API Integration Tests via jest (#10899)

* tests: experiment with api tests

* api tests are getting nice

* api: api testing ready for feedback
This commit is contained in:
Torkel Ödegaard
2018-02-14 10:26:20 +01:00
committed by GitHub
parent bb681cd498
commit ead1c300d7
11 changed files with 373 additions and 3 deletions
+45
View File
@@ -0,0 +1,45 @@
import client from './client';
import * as setup from './setup';
describe('/api/dashboards', () => {
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,
dashboards: [
{
title: 'aaa',
uid: 'aaa',
},
{
title: 'bbb',
uid: 'bbb',
},
],
});
});
describe('With admin user', () => {
it('can delete dashboard', async () => {
let rsp = await client.callAs(setup.admin).delete(`/api/dashboards/uid/aaa`);
expect(rsp.data.title).toBe('aaa');
});
});
describe('With viewer user', () => {
it('Cannot delete dashboard', async () => {
let rsp = await setup.expectError(() => {
return client.callAs(setup.viewer).delete(`/api/dashboards/uid/bbb`);
});
expect(rsp.response.status).toBe(403);
});
});
});