pdf.spec.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { PlatformTest } from '@tsed/platform-http/testing';
  2. import { JobStatus, JobStatusSharedWithGrowi } from 'src/service/pdf-convert';
  3. import SuperTest from 'supertest';
  4. import Server from '../server';
  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(
  32. 'jobId must be a valid MongoDB ObjectId',
  33. );
  34. });
  35. it('should return 202 and status for valid request', async () => {
  36. const request = SuperTest(PlatformTest.callback());
  37. const res = await request
  38. .post('/pdf/sync-job')
  39. .send({
  40. jobId: '64d2fa8b2f9c1e4a9b5e3d77',
  41. expirationDate: '2024-01-01T00:00:00Z',
  42. status: JobStatusSharedWithGrowi.HTML_EXPORT_IN_PROGRESS,
  43. appId: 1,
  44. })
  45. .expect(202);
  46. expect(res.body).toHaveProperty('status');
  47. expect(Object.values(JobStatus)).toContain(res.body.status);
  48. });
  49. });