pdf.spec.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { PlatformTest } from '@tsed/platform-http/testing';
  2. import SuperTest from 'supertest';
  3. import Server from '../server';
  4. import { JobStatus, JobStatusSharedWithGrowi } from 'src/service/pdf-convert';
  5. describe('PdfCtrl', () => {
  6. beforeAll(PlatformTest.bootstrap(Server));
  7. afterAll(PlatformTest.reset);
  8. it('should return 500 for invalid appId', async() => {
  9. const request = SuperTest(PlatformTest.callback());
  10. await request
  11. .post('/pdf/sync-job')
  12. .send({
  13. jobId: '64d2fa8b2f9c1e4a9b5e3d77',
  14. expirationDate: '2024-01-01T00:00:00Z',
  15. status: JobStatusSharedWithGrowi.HTML_EXPORT_IN_PROGRESS,
  16. appId: '../../../admin/secret-dir',
  17. })
  18. .expect(500);
  19. });
  20. it('should return 400 for invalid jobId', async() => {
  21. const request = SuperTest(PlatformTest.callback());
  22. const res = await request
  23. .post('/pdf/sync-job')
  24. .send({
  25. jobId: '../../../admin/secret-dir',
  26. expirationDate: '2024-01-01T00:00:00Z',
  27. status: JobStatusSharedWithGrowi.HTML_EXPORT_IN_PROGRESS,
  28. appId: 1,
  29. })
  30. .expect(400);
  31. expect(res.body.message).toContain('jobId must be a valid MongoDB ObjectId');
  32. });
  33. it('should return 202 and status for valid request', async() => {
  34. const request = SuperTest(PlatformTest.callback());
  35. const res = await request
  36. .post('/pdf/sync-job')
  37. .send({
  38. jobId: '64d2fa8b2f9c1e4a9b5e3d77',
  39. expirationDate: '2024-01-01T00:00:00Z',
  40. status: JobStatusSharedWithGrowi.HTML_EXPORT_IN_PROGRESS,
  41. appId: 1,
  42. })
  43. .expect(202);
  44. expect(res.body).toHaveProperty('status');
  45. expect(Object.values(JobStatus)).toContain(res.body.status);
  46. });
  47. });