|
|
|
@ -106,6 +106,73 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetLibraryPanelConnections(t *testing.T) { |
|
|
|
|
scenarioWithPanel(t, "When an admin tries to get connections of library panel, it should succeed and return correct result", |
|
|
|
|
func(t *testing.T, sc scenarioContext) { |
|
|
|
|
dashJSON := map[string]interface{}{ |
|
|
|
|
"panels": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"id": int64(1), |
|
|
|
|
"gridPos": map[string]interface{}{ |
|
|
|
|
"h": 6, |
|
|
|
|
"w": 6, |
|
|
|
|
"x": 0, |
|
|
|
|
"y": 0, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"id": int64(2), |
|
|
|
|
"gridPos": map[string]interface{}{ |
|
|
|
|
"h": 6, |
|
|
|
|
"w": 6, |
|
|
|
|
"x": 6, |
|
|
|
|
"y": 0, |
|
|
|
|
}, |
|
|
|
|
"libraryPanel": map[string]interface{}{ |
|
|
|
|
"uid": sc.initialResult.Result.UID, |
|
|
|
|
"name": sc.initialResult.Result.Name, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
dash := models.Dashboard{ |
|
|
|
|
Title: "Testing GetLibraryPanelConnections", |
|
|
|
|
Data: simplejson.NewFromAny(dashJSON), |
|
|
|
|
} |
|
|
|
|
dashInDB := createDashboard(t, sc.sqlStore, sc.user, &dash, sc.folder.Id) |
|
|
|
|
err := sc.service.ConnectElementsToDashboard(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, []string{sc.initialResult.Result.UID}, dashInDB.Id) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
var expected = func(res LibraryElementConnectionsResponse) LibraryElementConnectionsResponse { |
|
|
|
|
return LibraryElementConnectionsResponse{ |
|
|
|
|
Result: []LibraryElementConnectionDTO{ |
|
|
|
|
{ |
|
|
|
|
ID: sc.initialResult.Result.ID, |
|
|
|
|
Kind: sc.initialResult.Result.Kind, |
|
|
|
|
ElementID: 1, |
|
|
|
|
ConnectionID: dashInDB.Id, |
|
|
|
|
ConnectionUID: dashInDB.Uid, |
|
|
|
|
Created: res.Result[0].Created, |
|
|
|
|
CreatedBy: LibraryElementDTOMetaUser{ |
|
|
|
|
ID: 1, |
|
|
|
|
Name: userInDbName, |
|
|
|
|
AvatarURL: userInDbAvatar, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sc.ctx.Req = web.SetURLParams(sc.ctx.Req, map[string]string{":uid": sc.initialResult.Result.UID}) |
|
|
|
|
resp := sc.service.getConnectionsHandler(sc.reqContext) |
|
|
|
|
var result = validateAndUnMarshalConnectionResponse(t, resp) |
|
|
|
|
|
|
|
|
|
if diff := cmp.Diff(expected(result), result, getCompareOptions()...); diff != "" { |
|
|
|
|
t.Fatalf("Result mismatch (-want +got):\n%s", diff) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type libraryElement struct { |
|
|
|
|
ID int64 `json:"id"` |
|
|
|
|
OrgID int64 `json:"orgId"` |
|
|
|
@ -285,6 +352,15 @@ func validateAndUnMarshalResponse(t *testing.T, resp response.Response) libraryE |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func validateAndUnMarshalConnectionResponse(t *testing.T, resp response.Response) LibraryElementConnectionsResponse { |
|
|
|
|
t.Helper() |
|
|
|
|
require.Equal(t, 200, resp.Status()) |
|
|
|
|
var result = LibraryElementConnectionsResponse{} |
|
|
|
|
err := json.Unmarshal(resp.Body(), &result) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func validateAndUnMarshalArrayResponse(t *testing.T, resp response.Response) libraryElementArrayResult { |
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
|
|