diff --git a/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 b/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 new file mode 100644 index 0000000..176e08e Binary files /dev/null and b/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 differ diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index b69ae6e..30760be 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.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); }); diff --git a/test/jest-e2e.json b/test/jest-e2e.json index e9d912f..4e31831 100644 --- a/test/jest-e2e.json +++ b/test/jest-e2e.json @@ -1,6 +1,9 @@ { "moduleFileExtensions": ["js", "json", "ts"], "rootDir": ".", + "setupFilesAfterEnv": [ + "/setup.jest.ts" + ], "testEnvironment": "node", "testRegex": ".e2e-spec.ts$", "transform": { diff --git a/test/setup.jest.ts b/test/setup.jest.ts new file mode 100644 index 0000000..579dbe1 --- /dev/null +++ b/test/setup.jest.ts @@ -0,0 +1,3 @@ +import { toMatchImageSnapshot } from 'jest-image-snapshot'; + +expect.extend({ toMatchImageSnapshot });