Skip to content

Commit 705e4e6

Browse files
committed
lint fix and improve test coverage
1 parent 41dbe10 commit 705e4e6

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

internal/datastore/src/__test__/mi-repository.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ describe("MiRepository", () => {
6666
});
6767

6868
describe("getMi", () => {
69-
it("throws an error when fetching MI information that does not exist", async() => {
70-
await expect(
71-
miRepository.getMI("XXX", "supplier1"),
69+
it("throws an error when fetching MI information that does not exist", async () => {
70+
await expect(miRepository.getMI("XXX", "supplier1")
7271
).rejects.toThrow(
7372
"Management Information with id XXX not found for supplier supplier1",
7473
);

lambdas/api-handler/src/mappers/__tests__/mi-mapper.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MIBase } from "@internal/datastore/src";
22
import { IncomingMI, PostMIRequest } from "../../contracts/mi";
3-
import { mapToMI, mapToPostMIResponse } from "../mi-mapper";
3+
import { mapToGetMIResponse, mapToMI, mapToPostMIResponse } from "../mi-mapper";
44

55
describe("mi-mapper", () => {
66
it("maps a PostMIRequest to an IncomingMI object", async () => {
@@ -59,4 +59,33 @@ describe("mi-mapper", () => {
5959
},
6060
});
6161
});
62+
63+
it("maps an internal MIBase object to a GetMIResponse", async () => {
64+
const mi: MIBase = {
65+
id: "id1",
66+
lineItem: "envelope-business-standard",
67+
timestamp: "2023-11-17T14:27:51.413Z",
68+
quantity: 22,
69+
specificationId: "spec1",
70+
groupId: "group1",
71+
stockRemaining: 20_000,
72+
};
73+
74+
const result = mapToGetMIResponse(mi);
75+
76+
expect(result).toEqual({
77+
data: {
78+
id: "id1",
79+
type: "ManagementInformation",
80+
attributes: {
81+
lineItem: "envelope-business-standard",
82+
timestamp: "2023-11-17T14:27:51.413Z",
83+
quantity: 22,
84+
specificationId: "spec1",
85+
groupId: "group1",
86+
stockRemaining: 20_000,
87+
},
88+
},
89+
});
90+
});
6291
});

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,29 @@ describe("postMI function", () => {
3636
},
3737
});
3838
});
39+
40+
it("retrieves the MI from the repository", async () => {
41+
const persistedMi = { id: "id1", ...incomingMi };
42+
43+
const mockRepo = {
44+
getMI: jest.fn().mockResolvedValue(persistedMi),
45+
};
46+
47+
const result = await getMI("id1", "supplier1" , mockRepo as any);
48+
49+
expect(result).toEqual({
50+
data: {
51+
id: "id1",
52+
type: "ManagementInformation",
53+
attributes: {
54+
lineItem: "envelope-business-standard",
55+
timestamp: "2023-11-17T14:27:51.413Z",
56+
quantity: 22,
57+
specificationId: "spec1",
58+
groupId: "group1",
59+
stockRemaining: 20_000,
60+
},
61+
},
62+
});
63+
});
3964
});

0 commit comments

Comments
 (0)