Commit b56e2a61 by Marcus Efraimsson

folders: basic integration tests for folders

parent ea7998ca
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment