-
Notifications
You must be signed in to change notification settings - Fork 0
Order management backend #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f1a2587
5b88900
518c2f6
b78edc5
0690c6f
e9c58e5
06d3f47
69b82b2
3f81e79
c4489fd
d34d15b
3fb7724
27f626d
6632978
f664142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { Test, TestingModule } from '@nestjs/testing'; | ||
| import { OrdersController } from './order.controller'; | ||
| import { OrdersService } from './order.service'; | ||
| import { AllocationsService } from '../allocations/allocations.service'; | ||
| import { Order } from './order.entity'; | ||
| import { Allocation } from '../allocations/allocations.entity'; | ||
| import { mock } from 'jest-mock-extended'; | ||
|
|
||
| const mockOrdersService = mock<OrdersService>(); | ||
| const mockAllocationsService = mock<AllocationsService>(); | ||
|
|
||
| describe('OrdersController', () => { | ||
| let controller: OrdersController; | ||
|
|
||
| const mockOrders: Partial<Order>[] = [ | ||
| { orderId: 1, status: 'pending' }, | ||
| { orderId: 2, status: 'delivered' }, | ||
| ]; | ||
|
|
||
| const mockAllocations: Partial<Allocation>[] = [ | ||
| { allocationId: 1, orderId: 1 }, | ||
| { allocationId: 2, orderId: 1 }, | ||
| { allocationId: 3, orderId: 2 }, | ||
| ]; | ||
|
|
||
| beforeEach(async () => { | ||
| const module: TestingModule = await Test.createTestingModule({ | ||
| controllers: [OrdersController], | ||
| providers: [ | ||
| { provide: OrdersService, useValue: mockOrdersService }, | ||
| { provide: AllocationsService, useValue: mockAllocationsService }, | ||
| ], | ||
| }).compile(); | ||
|
|
||
| controller = module.get<OrdersController>(OrdersController); | ||
| }); | ||
|
|
||
| it('should be defined', () => { | ||
| expect(controller).toBeDefined(); | ||
| }); | ||
|
|
||
| describe('getAllOrders', () => { | ||
| it('should call ordersService.getAll and return orders', async () => { | ||
| const status = 'pending'; | ||
| const pantryNames = ['Test Pantry', 'Test Pantry 2']; | ||
| mockOrdersService.getAll.mockResolvedValueOnce([ | ||
| mockOrders[0], | ||
| ] as Order[]); | ||
|
|
||
| const result = await controller.getAllOrders(status, pantryNames); | ||
|
|
||
| expect(result).toEqual([mockOrders[0]] as Order[]); | ||
| expect(mockOrdersService.getAll).toHaveBeenCalledWith({ | ||
| status, | ||
| pantryNames, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getAllAllocationsByOrder', () => { | ||
| it('should call allocationsService.getAllAllocationsByOrder and return allocations', async () => { | ||
| const orderId = 1; | ||
| mockAllocationsService.getAllAllocationsByOrder.mockResolvedValueOnce( | ||
| mockAllocations.slice(0, 2) as Allocation[], | ||
| ); | ||
|
|
||
| const result = await controller.getAllAllocationsByOrder(orderId); | ||
|
|
||
| expect(result).toEqual(mockAllocations.slice(0, 2) as Allocation[]); | ||
| expect( | ||
| mockAllocationsService.getAllAllocationsByOrder, | ||
| ).toHaveBeenCalledWith(orderId); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.