implemented e2e test

main
Inga 🏳‍🌈 2 years ago
parent 7c918115c1
commit 3e968abe80
  1. BIN
      test/__image_snapshots__/app-e-2-e-spec-ts-app-controller-e-2-e-stores-a-job-for-suricrasia-online-and-completes-it-1-snap.png
  2. 32
      test/app.e2e-spec.ts
  3. 3
      test/jest-e2e.json
  4. 3
      test/setup.jest.ts

@ -1,3 +1,4 @@
import { setTimeout as wait } from "timers/promises";
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
@ -15,10 +16,29 @@ describe('AppController (e2e)', () => {
await app.init();
});
it('/hello-world (GET)', () => {
return request(app.getHttpServer())
.get('/hello-world')
.expect(200)
.expect('Hello World!');
});
afterEach(async () => {
await app.close();
})
it('stores a job for suricrasia.online and completes it', async () => {
const supertest = request(app.getHttpServer())
const jobCreateResponse = await supertest
.post('/screenshots')
.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);
});

@ -1,6 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"setupFilesAfterEnv": [
"<rootDir>/setup.jest.ts"
],
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {

@ -0,0 +1,3 @@
import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
Loading…
Cancel
Save