mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
folders: basic integration tests for folders
This commit is contained in:
parent
ea7998ca8e
commit
b56e2a61f9
78
tests/api/folder.test.ts
Normal file
78
tests/api/folder.test.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import client from './client';
|
||||
import * as setup from './setup';
|
||||
|
||||
describe('/api/folders', () => {
|
||||
let state: any = {};
|
||||
|
||||
beforeAll(async () => {
|
||||
state = await setup.ensureState({
|
||||
orgName: 'api-test-org',
|
||||
users: [
|
||||
{ user: setup.admin, role: 'Admin' },
|
||||
{ user: setup.editor, role: 'Editor' },
|
||||
{ user: setup.viewer, role: 'Viewer' },
|
||||
],
|
||||
admin: setup.admin,
|
||||
folders: [
|
||||
{
|
||||
title: 'Folder 1',
|
||||
uid: 'f-01',
|
||||
},
|
||||
{
|
||||
title: 'Folder 2',
|
||||
uid: 'f-02',
|
||||
},
|
||||
{
|
||||
title: 'Folder 3',
|
||||
uid: 'f-03',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('With admin user', () => {
|
||||
it('can delete folder', async () => {
|
||||
let rsp = await client.callAs(setup.admin).delete(`/api/folders/f-01`);
|
||||
expect(rsp.data.title).toBe('Folder 1');
|
||||
});
|
||||
|
||||
it('can update folder', async () => {
|
||||
let rsp = await client.callAs(setup.admin).put(`/api/folders/f-02`, {
|
||||
uid: 'f-02',
|
||||
title: 'Folder 2 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
expect(rsp.data.title).toBe('Folder 2 upd');
|
||||
});
|
||||
|
||||
it('can update folder uid', async () => {
|
||||
let rsp = await client.callAs(setup.admin).put(`/api/folders/f-03`, {
|
||||
uid: 'f-03-upd',
|
||||
title: 'Folder 3 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
expect(rsp.data.uid).toBe('f-03-upd');
|
||||
expect(rsp.data.title).toBe('Folder 3 upd');
|
||||
});
|
||||
});
|
||||
|
||||
describe('With viewer user', () => {
|
||||
it('Cannot delete folder', async () => {
|
||||
let rsp = await setup.expectError(() => {
|
||||
return client.callAs(setup.viewer).delete(`/api/folders/f-02`);
|
||||
});
|
||||
expect(rsp.response.status).toBe(403);
|
||||
});
|
||||
|
||||
it('Cannot update folder', async () => {
|
||||
let rsp = await setup.expectError(() => {
|
||||
return client.callAs(setup.viewer).put(`/api/folders/f-02`, {
|
||||
uid: 'f-02',
|
||||
title: 'Folder 2 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
});
|
||||
expect(rsp.response.status).toBe(403);
|
||||
});
|
||||
});
|
||||
});
|
@ -90,6 +90,18 @@ export async function createDashboard(user, dashboard) {
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
export async function createFolder(user, folder) {
|
||||
const rsp = await client.callAs(user).post(`/api/folders`, {
|
||||
uid: folder.uid,
|
||||
title: folder.title,
|
||||
overwrite: true,
|
||||
});
|
||||
folder.id = rsp.id;
|
||||
folder.url = rsp.url;
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
export async function ensureState(state) {
|
||||
const org = await getOrg(state.orgName);
|
||||
|
||||
@ -99,9 +111,13 @@ export async function ensureState(state) {
|
||||
await setUsingOrg(user, org);
|
||||
}
|
||||
|
||||
for (let dashboard of state.dashboards) {
|
||||
for (let dashboard of state.dashboards || []) {
|
||||
await createDashboard(state.admin, dashboard);
|
||||
}
|
||||
|
||||
for (let folder of state.folders || []) {
|
||||
await createFolder(state.admin, folder);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user