Add FolderUID for library elements (#79572)
* Add FolderUID in missing places for libraryelements * Add migration for FolderUID in library elements table * Add Folder UIDs tolibrary panels * Adjust dashboard import with folder uid * Fix lint * Rename back FolderUID to UID * Remove default * Check if folderUID is nil * Add unique indes on org_id,folder_uid,name and kind * Update pkg/services/libraryelements/database.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Fix folder integration test, with unique index on library elements * Make folder uids nullable and rewrite migration query * Use dashboard uid instead of folder_uid * Adjust test --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to create a library panel that already exists, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Text - Library Panel")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Text - Library Panel")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
require.Equal(t, 400, resp.Status())
|
||||
@@ -28,6 +28,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: sc.initialResult.Result.UID,
|
||||
Name: "Text - Library Panel",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -68,7 +69,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
testScenario(t, "When an admin tries to create a library panel that does not exists using an nonexistent UID, it should succeed",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Nonexistent UID")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Nonexistent UID")
|
||||
command.UID = util.GenerateShortUID()
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
@@ -78,6 +79,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: command.UID,
|
||||
Name: "Nonexistent UID",
|
||||
Kind: int64(model.PanelElement),
|
||||
@@ -118,7 +120,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to create a library panel that does not exists using an existent UID, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Existing UID")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Existing UID")
|
||||
command.UID = sc.initialResult.Result.UID
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
@@ -128,7 +130,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to create a library panel that does not exists using an invalid UID, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Invalid UID")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Invalid UID")
|
||||
command.UID = "Testing an invalid UID"
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
@@ -138,7 +140,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
scenarioWithPanel(t, "When an admin tries to create a library panel that does not exists using an UID that is too long, it should fail",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
// nolint:staticcheck
|
||||
command := getCreatePanelCommand(sc.folder.ID, "Invalid UID")
|
||||
command := getCreatePanelCommand(sc.folder.ID, sc.folder.UID, "Invalid UID")
|
||||
command.UID = "j6T00KRZzj6T00KRZzj6T00KRZzj6T00KRZzj6T00K"
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
@@ -147,7 +149,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
|
||||
testScenario(t, "When an admin tries to create a library panel where name and panel title differ, it should not update panel title",
|
||||
func(t *testing.T, sc scenarioContext) {
|
||||
command := getCreatePanelCommand(1, "Library Panel Name")
|
||||
command := getCreatePanelCommand(1, sc.folder.UID, "Library Panel Name")
|
||||
sc.reqContext.Req.Body = mockRequestBody(command)
|
||||
resp := sc.service.createHandler(sc.reqContext)
|
||||
var result = validateAndUnMarshalResponse(t, resp)
|
||||
@@ -156,6 +158,7 @@ func TestCreateLibraryElement(t *testing.T) {
|
||||
ID: 1,
|
||||
OrgID: 1,
|
||||
FolderID: 1, // nolint:staticcheck
|
||||
FolderUID: sc.folder.UID,
|
||||
UID: result.Result.UID,
|
||||
Name: "Library Panel Name",
|
||||
Kind: int64(model.PanelElement),
|
||||
|
||||
Reference in New Issue
Block a user