5
5
addTestUser ,
6
6
clearDatabase ,
7
7
setAvailability ,
8
- setEvent ,
9
8
setRequest ,
10
9
setTour
11
10
} from '$lib/testHelpers' ;
@@ -49,8 +48,7 @@ describe('test accounting', () => {
49
48
const v1 = await addTaxi ( c1 , dummyCapacities ) ;
50
49
await setAvailability ( v1 , testDays [ 0 ] + HOUR * 5 , testDays [ 0 ] + HOUR * 6 ) ;
51
50
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 1000 ) ) ! . id ;
52
- const r1 = await setRequest ( t1 , u . id , '' ) ;
53
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
51
+ await setRequest ( t1 , u . id , '' ) ;
54
52
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
55
53
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
56
54
expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 1000 ) ;
@@ -66,10 +64,8 @@ describe('test accounting', () => {
66
64
const v1 = await addTaxi ( c1 , dummyCapacities ) ;
67
65
await setAvailability ( v1 , testDays [ 0 ] + HOUR * 5 , testDays [ 0 ] + HOUR * 6 ) ;
68
66
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 1000 ) ) ! . id ;
69
- const r1 = await setRequest ( t1 , u . id , '' ) ;
70
- const r2 = await setRequest ( t1 , u . id , '' ) ;
71
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
72
- await setEvent ( r2 . id , 1 , true , 1 , 1 ) ;
67
+ await setRequest ( t1 , u . id , '' ) ;
68
+ await setRequest ( t1 , u . id , '' ) ;
73
69
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
74
70
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
75
71
expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 1000 ) ;
@@ -85,8 +81,7 @@ describe('test accounting', () => {
85
81
const v1 = await addTaxi ( c1 , dummyCapacities ) ;
86
82
await setAvailability ( v1 , testDays [ 0 ] + HOUR * 5 , testDays [ 0 ] + HOUR * 6 ) ;
87
83
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5000 ) ) ! . id ;
88
- const r1 = await setRequest ( t1 , u . id , '' ) ;
89
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
84
+ await setRequest ( t1 , u . id , '' ) ;
90
85
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
91
86
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
92
87
expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5000 ) ;
@@ -103,10 +98,8 @@ describe('test accounting', () => {
103
98
await setAvailability ( v1 , testDays [ 0 ] + HOUR * 5 , testDays [ 0 ] + HOUR * 6 ) ;
104
99
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 2200 ) ) ! . id ;
105
100
const t2 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 3400 ) ) ! . id ;
106
- const r1 = await setRequest ( t1 , u . id , '' ) ;
107
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
108
- const r2 = await setRequest ( t2 , u . id , '' ) ;
109
- await setEvent ( r2 . id , 1 , true , 1 , 1 ) ;
101
+ await setRequest ( t1 , u . id , '' ) ;
102
+ await setRequest ( t2 , u . id , '' ) ;
110
103
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
111
104
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
112
105
expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5600 ) ;
@@ -127,10 +120,8 @@ describe('test accounting', () => {
127
120
await setAvailability ( v1 , testDays [ 0 ] + HOUR * 14 , testDays [ 0 ] + HOUR * 14 + 10 * MINUTE ) ;
128
121
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 2200 ) ) ! . id ;
129
122
const t2 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 3400 ) ) ! . id ;
130
- const r1 = await setRequest ( t1 , u . id , '' ) ;
131
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
132
- const r2 = await setRequest ( t2 , u . id , '' ) ;
133
- await setEvent ( r2 . id , 1 , true , 1 , 1 ) ;
123
+ await setRequest ( t1 , u . id , '' ) ;
124
+ await setRequest ( t2 , u . id , '' ) ;
134
125
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
135
126
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
136
127
expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5600 ) ;
@@ -140,37 +131,123 @@ describe('test accounting', () => {
140
131
expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 70 * MINUTE ) ;
141
132
} ) ;
142
133
143
- it ( 'availabilitiy crosses midnight ' , async ( ) => {
134
+ it ( 'availabilitiy on insignificant day ' , async ( ) => {
144
135
const u = await addTestUser ( ) ;
145
136
const c1 = await addCompany ( 1 , dummyCoordinates ) ;
146
137
const v1 = await addTaxi ( c1 , dummyCapacities ) ;
147
- await setAvailability ( v1 , testDays [ 0 ] - 30 * DAY - 30 * MINUTE , testDays [ 0 ] + 30 * MINUTE ) ;
148
- const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 2630 ) ) ! . id ;
149
- const r1 = await setRequest ( t1 , u . id , '' ) ;
150
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
138
+ await setAvailability ( v1 , midnight + 30 * MINUTE , midnight + 90 * MINUTE ) ;
139
+ const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 2600 ) ) ! . id ;
140
+ await setRequest ( t1 , u . id , '' ) ;
151
141
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
152
142
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
153
- expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 2630 ) ;
154
- expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 2030 ) ;
155
- expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 1820 ) ;
143
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 2600 ) ;
144
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 2000 ) ;
145
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 500 ) ;
146
+ expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 0 ) ;
156
147
expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 1 ) ;
157
- expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 30 * MINUTE ) ;
158
148
} ) ;
159
149
160
- it ( 'availabilitiy on insignificant day ' , async ( ) => {
150
+ it ( 'two tours same vehicle ' , async ( ) => {
161
151
const u = await addTestUser ( ) ;
162
152
const c1 = await addCompany ( 1 , dummyCoordinates ) ;
163
153
const v1 = await addTaxi ( c1 , dummyCapacities ) ;
164
- await setAvailability ( v1 , midnight + 30 * MINUTE , midnight + 90 * MINUTE ) ;
165
154
const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 2600 ) ) ! . id ;
166
- const r1 = await setRequest ( t1 , u . id , '' ) ;
167
- await setEvent ( r1 . id , 1 , true , 1 , 1 ) ;
155
+ const t2 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 3000 ) ) ! . id ;
156
+ await setRequest ( t1 , u . id , '' ) ;
157
+ await setRequest ( t2 , u . id , '' ) ;
168
158
const { companyCostsPerDay } = await getCompanyCosts ( ) ;
169
159
expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
170
- expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 2600 ) ;
171
- expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 2000 ) ;
172
- expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 500 ) ;
160
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5600 ) ;
161
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 4400 ) ;
162
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 1100 ) ;
173
163
expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 0 ) ;
164
+ expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 2 ) ;
165
+ } ) ;
166
+
167
+ it ( 'two tours different vehicles' , async ( ) => {
168
+ const u = await addTestUser ( ) ;
169
+ const c1 = await addCompany ( 1 , dummyCoordinates ) ;
170
+ const v1 = await addTaxi ( c1 , dummyCapacities ) ;
171
+ const v2 = await addTaxi ( c1 , dummyCapacities ) ;
172
+ await setAvailability ( v1 , testDays [ 0 ] + 3 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
173
+ await setAvailability ( v2 , testDays [ 0 ] + 3 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
174
+ const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5100 ) ) ! . id ;
175
+ const t2 = ( await setTour ( v2 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5100 ) ) ! . id ;
176
+ await setRequest ( t1 , u . id , '' ) ;
177
+ await setRequest ( t2 , u . id , '' ) ;
178
+ const { companyCostsPerDay } = await getCompanyCosts ( ) ;
179
+ expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
180
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 10200 ) ;
181
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 9000 ) ;
182
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 7500 ) ;
183
+ expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 2 * HOUR ) ;
184
+ expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 2 ) ;
185
+ } ) ;
186
+
187
+ it ( 'tours with 2 customers' , async ( ) => {
188
+ const u = await addTestUser ( ) ;
189
+ const c1 = await addCompany ( 1 , dummyCoordinates ) ;
190
+ const v1 = await addTaxi ( c1 , dummyCapacities ) ;
191
+ await setAvailability ( v1 , testDays [ 0 ] + 3 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
192
+ const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5700 ) ) ! . id ;
193
+ await setRequest ( t1 , u . id , '' , 2 ) ;
194
+ const { companyCostsPerDay } = await getCompanyCosts ( ) ;
195
+ expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
196
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5700 ) ;
197
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 4500 ) ;
198
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 3750 ) ;
199
+ expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( HOUR ) ;
200
+ expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 2 ) ;
201
+ } ) ;
202
+
203
+ it ( 'overlapping availabilities' , async ( ) => {
204
+ const u = await addTestUser ( ) ;
205
+ const c1 = await addCompany ( 1 , dummyCoordinates ) ;
206
+ const v1 = await addTaxi ( c1 , dummyCapacities ) ;
207
+ const v2 = await addTaxi ( c1 , dummyCapacities ) ;
208
+ await setAvailability ( v1 , testDays [ 0 ] + 3 * HOUR , testDays [ 0 ] + 6 * HOUR ) ;
209
+ await setAvailability ( v2 , testDays [ 0 ] + 2 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
210
+ await setAvailability ( v2 , testDays [ 0 ] + 5 * HOUR , testDays [ 0 ] + 7 * HOUR ) ;
211
+ const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5100 ) ) ! . id ;
212
+ const t2 = ( await setTour ( v2 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 35600 ) ) ! . id ;
213
+ await setRequest ( t1 , u . id , '' ) ;
214
+ await setRequest ( t2 , u . id , '' ) ;
215
+ const { companyCostsPerDay } = await getCompanyCosts ( ) ;
216
+ expect ( companyCostsPerDay ) . toHaveLength ( 1 ) ;
217
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 40700 ) ;
218
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 39500 ) ;
219
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 23750 ) ;
220
+ expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( 7 * HOUR ) ;
221
+ expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 2 ) ;
222
+ } ) ;
223
+
224
+ it ( '2 companies' , async ( ) => {
225
+ const u = await addTestUser ( ) ;
226
+ const c1 = await addCompany ( 1 , dummyCoordinates ) ;
227
+ const c2 = await addCompany ( 1 , dummyCoordinates ) ;
228
+ const v1 = await addTaxi ( c1 , dummyCapacities ) ;
229
+ const v2 = await addTaxi ( c2 , dummyCapacities ) ;
230
+ await setAvailability ( v1 , testDays [ 0 ] + 3 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
231
+ await setAvailability ( v2 , testDays [ 0 ] + 2 * HOUR , testDays [ 0 ] + 4 * HOUR ) ;
232
+ const t1 = ( await setTour ( v1 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 5100 ) ) ! . id ;
233
+ const t2 = ( await setTour ( v2 , testDays [ 0 ] + HOUR , testDays [ 0 ] + HOUR * 2 , 9200 ) ) ! . id ;
234
+ await setRequest ( t1 , u . id , '' ) ;
235
+ await setRequest ( t2 , u . id , '' , 2 ) ;
236
+ const { companyCostsPerDay } = await getCompanyCosts ( ) ;
237
+ expect ( companyCostsPerDay ) . toHaveLength ( 2 ) ;
238
+ expect ( companyCostsPerDay [ 0 ] . timestamp ) . toBe ( companyCostsPerDay [ 1 ] . timestamp ) ;
239
+ companyCostsPerDay . sort ( ( c1 , c2 ) => c1 . companyId - c2 . companyId ) ;
240
+
241
+ expect ( companyCostsPerDay [ 0 ] . taxameter ) . toBe ( 5100 ) ;
242
+ expect ( companyCostsPerDay [ 0 ] . uncapped ) . toBe ( 4500 ) ;
243
+ expect ( companyCostsPerDay [ 0 ] . capped ) . toBe ( 3750 ) ;
244
+ expect ( companyCostsPerDay [ 0 ] . availabilityDuration ) . toBe ( HOUR ) ;
174
245
expect ( companyCostsPerDay [ 0 ] . customerCount ) . toBe ( 1 ) ;
246
+
247
+ expect ( companyCostsPerDay [ 1 ] . taxameter ) . toBe ( 9200 ) ;
248
+ expect ( companyCostsPerDay [ 1 ] . uncapped ) . toBe ( 8000 ) ;
249
+ expect ( companyCostsPerDay [ 1 ] . capped ) . toBe ( 7250 ) ;
250
+ expect ( companyCostsPerDay [ 1 ] . availabilityDuration ) . toBe ( 2 * HOUR ) ;
251
+ expect ( companyCostsPerDay [ 1 ] . customerCount ) . toBe ( 2 ) ;
175
252
} ) ;
176
253
} ) ;
0 commit comments