-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.test.ts
57 lines (48 loc) · 1.36 KB
/
application.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { v4 as uuid } from "uuid";
import { IRepository, IUnitOfWork, Order } from "./domain";
import { IIntegrationEventService, buildCreateOrder } from "./application";
describe("buildCreateOrder", () => {
let unitOfWork: IUnitOfWork;
let orderRepository: IRepository<Order>;
let integrationEventService: IIntegrationEventService;
let createOrder: (event: {
customerId: string;
amount: number;
}) => Promise<Order>;
beforeEach(() => {
unitOfWork = {
transactionId: uuid(),
commit: jest.fn(),
};
orderRepository = {
add: jest.fn(),
};
integrationEventService = {
add: jest.fn(),
publish: jest.fn(),
};
createOrder = buildCreateOrder(
unitOfWork,
orderRepository,
integrationEventService
);
});
test("should create an order and add integration event", async () => {
const customerId = "customer123";
const amount = 100;
const order = await createOrder({ customerId, amount });
expect(order).toEqual(
expect.objectContaining({
customerId,
amount,
status: "PENDING",
})
);
expect(orderRepository.add).toHaveBeenCalledWith(order);
expect(integrationEventService.add).toHaveBeenCalledWith({
name: "OrderPlaced",
payload: { id: order.id },
});
expect(unitOfWork.commit).toHaveBeenCalled();
});
});