Skip to content

Commit

Permalink
Add e2e agency test
Browse files Browse the repository at this point in the history
  • Loading branch information
pratishta committed May 22, 2024
1 parent 5c6338f commit 5b29e0d
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/agency/agency.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as request from "supertest";
import { INestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import { DataRetrievalException } from "src/exception";
import { HttpName } from "src/filter";
import { AgencyRepository } from "src/agency/agency.repository";
import { AgencyRepositoryMock } from "./agency.repository.mock";
import { AgencyModule } from "src/agency/agency.module";
import { findAgenciesQueryResponseSchema } from "src/gen";

describe("Agency e2e", () => {
let app: INestApplication;

const agencyRepositoryMock = new AgencyRepositoryMock();

beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AgencyModule],
})
.overrideProvider(AgencyRepository)
.useValue(agencyRepositoryMock)
.compile();
app = moduleRef.createNestApplication();
await app.init();
});

describe("findAgencies", () => {
it("should 200 and return all agencies", async () => {
const response = await request(app.getHttpServer())
.get(`/agencies`)
.expect(200);
expect(() =>
findAgenciesQueryResponseSchema.parse(response.body),
).not.toThrow();
});

it("should 500 and return all agencies", async () => {
const dataRetrievalException = new DataRetrievalException();
jest
.spyOn(agencyRepositoryMock, "findMany")
.mockImplementationOnce(() => {
throw dataRetrievalException;
});

const response = await request(app.getHttpServer())
.get(`/agencies`)
.expect(500);
expect(response.body.message).toBe(dataRetrievalException.message);
expect(response.body.error).toBe(HttpName.INTERNAL_SEVER_ERROR);
});
});

afterAll(async () => {
await app.close();
});
});

0 comments on commit 5b29e0d

Please sign in to comment.