Skip to content

Commit

Permalink
311 Update tests and schemas for findCommunityDistrictsByBoroughId en…
Browse files Browse the repository at this point in the history
…dpoint

 - borough.service.spec updated test for resource error with missing id test to reflect an ID not in the db instead of an empty string
 - borough.service.e2e-spec updated to include a test for 404
 - community-district schema updated to reflect updated OpenAPI pattern to include 0

Closes #311
  • Loading branch information
horatiorosa committed Jun 7, 2024
1 parent e2af46a commit a545bd7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/borough/borough.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("Borough service unit", () => {
});

it("service should throw a resource error when requesting with a missing id", async () => {
const missingId = "";
const missingId = "9";
const zoningDistrict =
boroughService.findCommunityDistrictsByBoroughId(missingId);
expect(zoningDistrict).rejects.toThrow(ResourceNotFoundException);
Expand Down
2 changes: 1 addition & 1 deletion src/schema/community-district.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const communityDistrict = pgTable(
);

export const communityDistrictEntitySchema = z.object({
boroughId: z.string().length(1).regex(new RegExp("[1-9]")),
boroughId: z.string().length(1).regex(new RegExp("[0-9]")),
id: z.string().length(2).regex(new RegExp("^([0-9]{2})$")),
});
8 changes: 8 additions & 0 deletions test/borough/borough.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe("Borough e2e", () => {
expect(response.body.error).toBe(HttpName.BAD_REQUEST);
});

it("should 404 and when finding by a missing id", async () => {
const missingId = "9";
const response = await request(app.getHttpServer())
.get(`/boroughs/${missingId}/community-districts`)
.expect(404);
expect(response.body.message).toBe(HttpName.NOT_FOUND);
});

it("should 500 when the database errors", async () => {
const dataRetrievalException = new DataRetrievalException();
jest
Expand Down

0 comments on commit a545bd7

Please sign in to comment.