dashboard.test.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import client from './client';
  2. import * as setup from './setup';
  3. describe('/api/dashboards', () => {
  4. let state: any = {};
  5. beforeAll(async () => {
  6. state = await setup.ensureState({
  7. orgName: 'api-test-org',
  8. users: [
  9. { user: setup.admin, role: 'Admin' },
  10. { user: setup.editor, role: 'Editor' },
  11. { user: setup.viewer, role: 'Viewer' },
  12. ],
  13. admin: setup.admin,
  14. dashboards: [
  15. {
  16. title: 'aaa',
  17. uid: 'aaa',
  18. },
  19. {
  20. title: 'bbb',
  21. uid: 'bbb',
  22. },
  23. ],
  24. });
  25. });
  26. describe('With admin user', () => {
  27. it('can delete dashboard', async () => {
  28. let rsp = await client.callAs(setup.admin).delete(`/api/dashboards/uid/aaa`);
  29. expect(rsp.data.title).toBe('aaa');
  30. });
  31. });
  32. describe('With viewer user', () => {
  33. it('Cannot delete dashboard', async () => {
  34. let rsp = await setup.expectError(() => {
  35. return client.callAs(setup.viewer).delete(`/api/dashboards/uid/bbb`);
  36. });
  37. expect(rsp.response.status).toBe(403);
  38. });
  39. });
  40. });