@@ -6,6 +6,7 @@ import { InventoryService } from '../inventory/inventory.service';
6
6
import { OrganizationsService } from '../organizations/organizations.service' ;
7
7
import { WarehousesController } from './warehouses.controller' ;
8
8
import { WarehousesService } from './warehouses.service' ;
9
+ import { OrganizationsStatsService } from '../organizations/organizations-stats.service' ;
9
10
10
11
const MOCK_TAKEN_ORG_ID = new Types . ObjectId ( '62a23958e5a9e9b88f853a67' ) ;
11
12
const MOCK_FREE_ORG_ID = new Types . ObjectId ( '657047c4e0cecd73abbad627' ) ;
@@ -50,14 +51,28 @@ describe('WarehousesController', () => {
50
51
} ;
51
52
52
53
const mockOrganizationsService = {
53
- addWarehouseReference : jest . fn ( ) ,
54
- deleteWarehouseReference : jest . fn ( ) ,
55
- updateWarehouseReference : jest . fn ( ) ,
54
+ addWarehouseReference : jest . fn ( ( ) => ( {
55
+ _id : MOCK_TAKEN_ORG_ID ,
56
+ } ) ) ,
57
+ deleteWarehouseReference : jest . fn ( ( ) => ( {
58
+ _id : MOCK_TAKEN_ORG_ID ,
59
+ } ) ) ,
60
+ updateWarehouseReference : jest . fn ( ( ) => ( {
61
+ _id : MOCK_TAKEN_ORG_ID ,
62
+ } ) ) ,
56
63
exist : jest . fn ( ( id : Types . ObjectId ) => {
57
64
return id . toString ( ) == MOCK_TAKEN_ORG_ID . toString ( ) ;
58
65
} ) ,
59
66
} ;
60
67
68
+ const mockOrganizationsStatsService = {
69
+ recalculateTotalValue : jest . fn ( ) ,
70
+ } ;
71
+
72
+ const mockInventoryService = {
73
+ deleteManyByWarehouse : jest . fn ( ) ,
74
+ } ;
75
+
61
76
const addWarehouseReferenceSpy = jest . spyOn ( mockOrganizationsService , 'addWarehouseReference' ) ;
62
77
const deleteWarehouseReferenceSpy = jest . spyOn (
63
78
mockOrganizationsService ,
@@ -67,22 +82,29 @@ describe('WarehousesController', () => {
67
82
mockOrganizationsService ,
68
83
'updateWarehouseReference' ,
69
84
) ;
70
-
71
- const mockInventoryService = {
72
- deleteManyByWarehouse : jest . fn ( ) ,
73
- } ;
85
+ const recalculateTotalValueSpy = jest . spyOn (
86
+ mockOrganizationsStatsService ,
87
+ 'recalculateTotalValue' ,
88
+ ) ;
74
89
75
90
beforeEach ( async ( ) => {
76
91
const module : TestingModule = await Test . createTestingModule ( {
77
92
controllers : [ WarehousesController ] ,
78
- providers : [ WarehousesService , OrganizationsService , InventoryService ] ,
93
+ providers : [
94
+ WarehousesService ,
95
+ OrganizationsService ,
96
+ OrganizationsStatsService ,
97
+ InventoryService ,
98
+ ] ,
79
99
} )
80
100
. overrideProvider ( WarehousesService )
81
101
. useValue ( mockWarehouseService )
82
102
. overrideProvider ( OrganizationsService )
83
103
. useValue ( mockOrganizationsService )
84
104
. overrideProvider ( InventoryService )
85
105
. useValue ( mockInventoryService )
106
+ . overrideProvider ( OrganizationsStatsService )
107
+ . useValue ( mockOrganizationsStatsService )
86
108
. compile ( ) ;
87
109
88
110
controller = module . get < WarehousesController > ( WarehousesController ) ;
@@ -191,6 +213,7 @@ describe('WarehousesController', () => {
191
213
} ) ,
192
214
) ;
193
215
expect ( deleteWarehouseReferenceSpy ) . toHaveBeenCalledWith ( MOCK_TAKEN_WAREHOUSE_ID ) ;
216
+ expect ( recalculateTotalValueSpy ) . toHaveBeenCalledWith ( MOCK_TAKEN_ORG_ID ) ;
194
217
} ) ;
195
218
196
219
it ( 'should not delete warehouse that does not exist' , ( ) => {
0 commit comments