main
Inga 🏳‍🌈 2 years ago
parent d585e802a2
commit 4ba4648186
  1. 38
      test/app.e2e-spec.ts

@ -1,4 +1,4 @@
import { setTimeout as wait } from "timers/promises"; import { setTimeout as wait } from 'timers/promises';
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common'; import { INestApplication } from '@nestjs/common';
import * as request from 'supertest'; import * as request from 'supertest';
@ -18,27 +18,29 @@ describe('AppController (e2e)', () => {
afterEach(async () => { afterEach(async () => {
await app.close(); await app.close();
}) });
it('stores a job for suricrasia.online and completes it', async () => { it('stores a job for suricrasia.online and completes it', async () => {
const supertest = request(app.getHttpServer()) const supertest = request(app.getHttpServer());
const jobCreateResponse = await supertest const jobCreateResponse = await supertest
.post('/screenshots') .post('/screenshots')
.send({ pageUrl: 'https://suricrasia.online', imageType: 'png' }) .send({ pageUrl: 'https://suricrasia.online', imageType: 'png' });
expect(jobCreateResponse.status).toEqual(201) expect(jobCreateResponse.status).toEqual(201);
expect(jobCreateResponse.body.jobId).toBeDefined() expect(jobCreateResponse.body.jobId).toBeDefined();
const jobId = jobCreateResponse.body.jobId const jobId = jobCreateResponse.body.jobId;
await wait(5000) await wait(5000);
const jobStatusResponse = await supertest.get(`/screenshots/${jobId}`) const jobStatusResponse = await supertest.get(`/screenshots/${jobId}`);
expect(jobStatusResponse.status).toEqual(200) expect(jobStatusResponse.status).toEqual(200);
expect(jobStatusResponse.body.status).toBeDefined() expect(jobStatusResponse.body.status).toBeDefined();
expect(jobStatusResponse.body.status).toEqual('completed') expect(jobStatusResponse.body.status).toEqual('completed');
const jobResultResponse = await supertest.get(`/screenshots/${jobId}/result`) const jobResultResponse = await supertest.get(
expect(jobResultResponse.status).toEqual(200) `/screenshots/${jobId}/result`,
expect(jobResultResponse.body).toMatchImageSnapshot() );
expect(jobResultResponse.status).toEqual(200);
expect(jobResultResponse.body).toMatchImageSnapshot();
}, 10000); }, 10000);
}); });

Loading…
Cancel
Save