Small Nest.js-based project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

2 years ago
import { setTimeout as wait } from 'timers/promises';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
afterEach(async () => {
await app.close();
2 years ago
});
it('stores a job for suricrasia.online and completes it', async () => {
2 years ago
const supertest = request(app.getHttpServer());
const jobCreateResponse = await supertest
.post('/screenshots')
2 years ago
.send({ pageUrl: 'https://suricrasia.online', imageType: 'png' });
expect(jobCreateResponse.status).toEqual(201);
expect(jobCreateResponse.body.jobId).toBeDefined();
const jobId = jobCreateResponse.body.jobId;
await wait(5000);
const jobStatusResponse = await supertest.get(`/screenshots/${jobId}`);
expect(jobStatusResponse.status).toEqual(200);
expect(jobStatusResponse.body.status).toBeDefined();
expect(jobStatusResponse.body.status).toEqual('completed');
const jobResultResponse = await supertest.get(
`/screenshots/${jobId}/result`,
);
expect(jobResultResponse.status).toEqual(200);
expect(jobResultResponse.body).toMatchImageSnapshot();
}, 10000);
});