Skip to content

Commit 162fa86

Browse files
committed
fix notfound error handling for getMI
1 parent 07440f4 commit 162fa86

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

internal/datastore/src/mi-repository.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { Logger } from "pino";
77
import { randomUUID } from "node:crypto";
88
import { MI, MISchema } from "./types";
9+
import MiNotFoundError from "./errors/mi-not-found-error";
910

1011
export type MIRepositoryConfig = {
1112
miTableName: string;
@@ -53,9 +54,7 @@ export class MIRepository {
5354
);
5455

5556
if (!result.Item) {
56-
throw new Error(
57-
`Management Information with id ${miId} not found for supplier ${supplierId}`,
58-
);
57+
throw new MiNotFoundError(supplierId, miId);
5958
}
6059

6160
return MISchema.parse(result.Item);

lambdas/api-handler/src/services/__tests__/mi-operations.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ describe("postMI function", () => {
3838
},
3939
});
4040
});
41+
});
4142

43+
describe("getMI function", () => {
4244
it("retrieves the MI from the repository", async () => {
45+
const incomingMi: IncomingMI = {
46+
lineItem: "envelope-business-standard",
47+
timestamp: "2023-11-17T14:27:51.413Z",
48+
quantity: 22,
49+
specificationId: "spec1",
50+
groupId: "group1",
51+
stockRemaining: 20_000,
52+
supplierId: "supplier1",
53+
};
4354
const persistedMi = { id: "id1", ...incomingMi };
4455

4556
const mockRepo = {
@@ -68,7 +79,7 @@ describe("postMI function", () => {
6879
const mockRepo = {
6980
getMI: jest
7081
.fn()
71-
.mockRejectedValue(new MiNotFoundError("miId1", "supplier1")),
82+
.mockRejectedValue(new MiNotFoundError("supplier1", "miId1")),
7283
};
7384

7485
await expect(

lambdas/api-handler/src/services/mi-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GetMIResponse, IncomingMI, PostMIResponse } from "../contracts/mi";
33
import { mapToGetMIResponse, mapToPostMIResponse } from "../mappers/mi-mapper";
44
import { ApiErrorDetail } from "../contracts/errors";
55
import NotFoundError from "../errors/not-found-error";
6-
import MiNotFoundError from "@internal/datastore/src/errors/letter-not-found-error";
6+
import MiNotFoundError from "@internal/datastore/src/errors/mi-not-found-error";
77

88
export const postMI = async (
99
incomingMi: IncomingMI,

0 commit comments

Comments
 (0)