Skip to content

Commit

Permalink
replace 404 with 200 response when empty banner is retrieved (#11467)
Browse files Browse the repository at this point in the history
  • Loading branch information
britt-mo authored Sep 20, 2023
1 parent 04d82ef commit ce27594
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
8 changes: 4 additions & 4 deletions services/app-api/handlers/banners/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const testEvent: APIGatewayProxyEvent = {
};

describe("Test fetchBanner API method", () => {
test("Test Report not found Fetch", async () => {
test("Test Successful empty Banner Fetch", async () => {
mockDocumentClient.get.promise.mockReturnValueOnce({ Item: undefined });
const res = await fetchBanner(testEvent, null);
expect(res.statusCode).toBe(StatusCodes.NOT_FOUND);
expect(res.statusCode).toBe(StatusCodes.SUCCESS);
});

test("Test Successful Banner Fetch", async () => {
Expand All @@ -51,7 +51,7 @@ describe("Test fetchBanner API method", () => {
};
const res = await fetchBanner(noKeyEvent, null);

expect(res.statusCode).toBe(500);
expect(res.statusCode).toBe(StatusCodes.SERVER_ERROR);
expect(res.body).toContain(error.NO_KEY);
});

Expand All @@ -62,7 +62,7 @@ describe("Test fetchBanner API method", () => {
};
const res = await fetchBanner(noKeyEvent, null);

expect(res.statusCode).toBe(500);
expect(res.statusCode).toBe(StatusCodes.SERVER_ERROR);
expect(res.body).toContain(error.NO_KEY);
});
});
5 changes: 1 addition & 4 deletions services/app-api/handlers/banners/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export const fetchBanner = handler(async (event, _context) => {
};
const response = await dynamoDb.get(params);

let status = StatusCodes.SUCCESS;
if (!response?.Item) {
status = StatusCodes.NOT_FOUND;
}
const status = StatusCodes.SUCCESS;
return { status: status, body: response };
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export const AdminBannerProvider = ({ children }: Props) => {
setBannerData(newBannerData);
} catch (e: any) {
setIsLoading(false);
// 404 expected when no current banner exists
if (!e.toString().includes("404")) {
setError(bannerErrors.GET_BANNER_FAILED);
}
setError(bannerErrors.GET_BANNER_FAILED);
}
setIsLoading(false);
};
Expand Down

0 comments on commit ce27594

Please sign in to comment.