forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.controller.spec.ts
More file actions
95 lines (84 loc) · 3.12 KB
/
Copy pathitems.controller.spec.ts
File metadata and controls
95 lines (84 loc) · 3.12 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Test, TestingModule } from '@nestjs/testing';
import { ItemsController } from './items.controller';
import { ItemsService } from './items.service';
import { CreateItemDto } from './dto/create-item.dto';
import { UpdateItemDto } from './dto/update-item.dto';
describe('ItemsController', () => {
let controller: ItemsController;
let service: ItemsService;
const mockItem = {
id: 'item-uuid',
splitId: 'split-uuid',
name: 'Burger',
quantity: 1,
unitPrice: 10,
totalPrice: 10,
assignedToIds: ['user-uuid'],
};
const mockItemsService = {
create: jest.fn().mockResolvedValue(mockItem),
findAllBySplitId: jest.fn().mockResolvedValue([mockItem]),
findOne: jest.fn().mockResolvedValue(mockItem),
update: jest.fn().mockResolvedValue(mockItem),
remove: jest.fn().mockResolvedValue(undefined),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ItemsController],
providers: [
{
provide: ItemsService,
useValue: mockItemsService,
},
],
}).compile();
controller = module.get<ItemsController>(ItemsController);
service = module.get<ItemsService>(ItemsService);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('create', () => {
it('should create an item', async () => {
const dto: CreateItemDto = {
splitId: 'split-uuid',
name: 'Burger',
quantity: 1,
unitPrice: 10,
totalPrice: 10,
assignedToIds: ['user-uuid'],
};
const result = await controller.create(dto);
expect(result).toEqual(mockItem);
expect(service.create).toHaveBeenCalledWith(dto);
});
});
describe('findAll', () => {
it('should return all items for a split', async () => {
const result = await controller.findAll('split-uuid');
expect(result).toEqual([mockItem]);
expect(service.findAllBySplitId).toHaveBeenCalledWith('split-uuid');
});
});
describe('findOne', () => {
it('should return a single item', async () => {
const result = await controller.findOne('item-uuid');
expect(result).toEqual(mockItem);
expect(service.findOne).toHaveBeenCalledWith('item-uuid');
});
});
describe('update', () => {
it('should update an item', async () => {
const dto: UpdateItemDto = { name: 'Cheese Burger' };
const result = await controller.update('item-uuid', dto);
expect(result).toEqual(mockItem);
expect(service.update).toHaveBeenCalledWith('item-uuid', dto);
});
});
describe('remove', () => {
it('should remove an item', async () => {
await controller.remove('item-uuid');
expect(service.remove).toHaveBeenCalledWith('item-uuid');
});
});
});