/
item.go
555 lines (527 loc) · 18.2 KB
/
item.go
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package moqs
import (
"cloud.google.com/go/firestore"
"context"
"github.com/wheatandcat/memoir-backend/graph/model"
"github.com/wheatandcat/memoir-backend/repository"
"sync"
"time"
)
// Ensure, that ItemRepositoryInterfaceMock does implement repository.ItemRepositoryInterface.
// If this is not the case, regenerate this file with moq.
var _ repository.ItemRepositoryInterface = &ItemRepositoryInterfaceMock{}
// ItemRepositoryInterfaceMock is a mock implementation of repository.ItemRepositoryInterface.
//
// func TestSomethingThatUsesItemRepositoryInterface(t *testing.T) {
//
// // make and configure a mocked repository.ItemRepositoryInterface
// mockedItemRepositoryInterface := &ItemRepositoryInterfaceMock{
// CreateFunc: func(ctx context.Context, f *firestore.Client, userID string, i *model.Item) error {
// panic("mock out the Create method")
// },
// DeleteFunc: func(ctx context.Context, f *firestore.Client, userID string, i *model.DeleteItem) error {
// panic("mock out the Delete method")
// },
// GetCountUserMultipleInPeriodFunc: func(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam) (int, error) {
// panic("mock out the GetCountUserMultipleInPeriod method")
// },
// GetItemFunc: func(ctx context.Context, f *firestore.Client, userID string, id string) (*model.Item, error) {
// panic("mock out the GetItem method")
// },
// GetItemUserMultipleInPeriodFunc: func(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error) {
// panic("mock out the GetItemUserMultipleInPeriod method")
// },
// GetItemsInDateFunc: func(ctx context.Context, f *firestore.Client, userID string, date time.Time) ([]*model.Item, error) {
// panic("mock out the GetItemsInDate method")
// },
// GetItemsInPeriodFunc: func(ctx context.Context, f *firestore.Client, userID string, stertDate time.Time, endDate time.Time, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error) {
// panic("mock out the GetItemsInPeriod method")
// },
// UpdateFunc: func(ctx context.Context, f *firestore.Client, userID string, i *model.UpdateItem, updatedAt time.Time) error {
// panic("mock out the Update method")
// },
// }
//
// // use mockedItemRepositoryInterface in code that requires repository.ItemRepositoryInterface
// // and then make assertions.
//
// }
type ItemRepositoryInterfaceMock struct {
// CreateFunc mocks the Create method.
CreateFunc func(ctx context.Context, f *firestore.Client, userID string, i *model.Item) error
// DeleteFunc mocks the Delete method.
DeleteFunc func(ctx context.Context, f *firestore.Client, userID string, i *model.DeleteItem) error
// GetCountUserMultipleInPeriodFunc mocks the GetCountUserMultipleInPeriod method.
GetCountUserMultipleInPeriodFunc func(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam) (int, error)
// GetItemFunc mocks the GetItem method.
GetItemFunc func(ctx context.Context, f *firestore.Client, userID string, id string) (*model.Item, error)
// GetItemUserMultipleInPeriodFunc mocks the GetItemUserMultipleInPeriod method.
GetItemUserMultipleInPeriodFunc func(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error)
// GetItemsInDateFunc mocks the GetItemsInDate method.
GetItemsInDateFunc func(ctx context.Context, f *firestore.Client, userID string, date time.Time) ([]*model.Item, error)
// GetItemsInPeriodFunc mocks the GetItemsInPeriod method.
GetItemsInPeriodFunc func(ctx context.Context, f *firestore.Client, userID string, stertDate time.Time, endDate time.Time, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error)
// UpdateFunc mocks the Update method.
UpdateFunc func(ctx context.Context, f *firestore.Client, userID string, i *model.UpdateItem, updatedAt time.Time) error
// calls tracks calls to the methods.
calls struct {
// Create holds details about calls to the Create method.
Create []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// I is the i argument value.
I *model.Item
}
// Delete holds details about calls to the Delete method.
Delete []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// I is the i argument value.
I *model.DeleteItem
}
// GetCountUserMultipleInPeriod holds details about calls to the GetCountUserMultipleInPeriod method.
GetCountUserMultipleInPeriod []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// Sip is the sip argument value.
Sip repository.SearchItemParam
}
// GetItem holds details about calls to the GetItem method.
GetItem []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// ID is the id argument value.
ID string
}
// GetItemUserMultipleInPeriod holds details about calls to the GetItemUserMultipleInPeriod method.
GetItemUserMultipleInPeriod []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// Sip is the sip argument value.
Sip repository.SearchItemParam
// First is the first argument value.
First int
// Cursor is the cursor argument value.
Cursor repository.ItemsInPeriodCursor
}
// GetItemsInDate holds details about calls to the GetItemsInDate method.
GetItemsInDate []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// Date is the date argument value.
Date time.Time
}
// GetItemsInPeriod holds details about calls to the GetItemsInPeriod method.
GetItemsInPeriod []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// StertDate is the stertDate argument value.
StertDate time.Time
// EndDate is the endDate argument value.
EndDate time.Time
// First is the first argument value.
First int
// Cursor is the cursor argument value.
Cursor repository.ItemsInPeriodCursor
}
// Update holds details about calls to the Update method.
Update []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// F is the f argument value.
F *firestore.Client
// UserID is the userID argument value.
UserID string
// I is the i argument value.
I *model.UpdateItem
// UpdatedAt is the updatedAt argument value.
UpdatedAt time.Time
}
}
lockCreate sync.RWMutex
lockDelete sync.RWMutex
lockGetCountUserMultipleInPeriod sync.RWMutex
lockGetItem sync.RWMutex
lockGetItemUserMultipleInPeriod sync.RWMutex
lockGetItemsInDate sync.RWMutex
lockGetItemsInPeriod sync.RWMutex
lockUpdate sync.RWMutex
}
// Create calls CreateFunc.
func (mock *ItemRepositoryInterfaceMock) Create(ctx context.Context, f *firestore.Client, userID string, i *model.Item) error {
if mock.CreateFunc == nil {
panic("ItemRepositoryInterfaceMock.CreateFunc: method is nil but ItemRepositoryInterface.Create was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.Item
}{
Ctx: ctx,
F: f,
UserID: userID,
I: i,
}
mock.lockCreate.Lock()
mock.calls.Create = append(mock.calls.Create, callInfo)
mock.lockCreate.Unlock()
return mock.CreateFunc(ctx, f, userID, i)
}
// CreateCalls gets all the calls that were made to Create.
// Check the length with:
//
// len(mockedItemRepositoryInterface.CreateCalls())
func (mock *ItemRepositoryInterfaceMock) CreateCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.Item
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.Item
}
mock.lockCreate.RLock()
calls = mock.calls.Create
mock.lockCreate.RUnlock()
return calls
}
// Delete calls DeleteFunc.
func (mock *ItemRepositoryInterfaceMock) Delete(ctx context.Context, f *firestore.Client, userID string, i *model.DeleteItem) error {
if mock.DeleteFunc == nil {
panic("ItemRepositoryInterfaceMock.DeleteFunc: method is nil but ItemRepositoryInterface.Delete was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.DeleteItem
}{
Ctx: ctx,
F: f,
UserID: userID,
I: i,
}
mock.lockDelete.Lock()
mock.calls.Delete = append(mock.calls.Delete, callInfo)
mock.lockDelete.Unlock()
return mock.DeleteFunc(ctx, f, userID, i)
}
// DeleteCalls gets all the calls that were made to Delete.
// Check the length with:
//
// len(mockedItemRepositoryInterface.DeleteCalls())
func (mock *ItemRepositoryInterfaceMock) DeleteCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.DeleteItem
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.DeleteItem
}
mock.lockDelete.RLock()
calls = mock.calls.Delete
mock.lockDelete.RUnlock()
return calls
}
// GetCountUserMultipleInPeriod calls GetCountUserMultipleInPeriodFunc.
func (mock *ItemRepositoryInterfaceMock) GetCountUserMultipleInPeriod(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam) (int, error) {
if mock.GetCountUserMultipleInPeriodFunc == nil {
panic("ItemRepositoryInterfaceMock.GetCountUserMultipleInPeriodFunc: method is nil but ItemRepositoryInterface.GetCountUserMultipleInPeriod was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
}{
Ctx: ctx,
F: f,
Sip: sip,
}
mock.lockGetCountUserMultipleInPeriod.Lock()
mock.calls.GetCountUserMultipleInPeriod = append(mock.calls.GetCountUserMultipleInPeriod, callInfo)
mock.lockGetCountUserMultipleInPeriod.Unlock()
return mock.GetCountUserMultipleInPeriodFunc(ctx, f, sip)
}
// GetCountUserMultipleInPeriodCalls gets all the calls that were made to GetCountUserMultipleInPeriod.
// Check the length with:
//
// len(mockedItemRepositoryInterface.GetCountUserMultipleInPeriodCalls())
func (mock *ItemRepositoryInterfaceMock) GetCountUserMultipleInPeriodCalls() []struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
}
mock.lockGetCountUserMultipleInPeriod.RLock()
calls = mock.calls.GetCountUserMultipleInPeriod
mock.lockGetCountUserMultipleInPeriod.RUnlock()
return calls
}
// GetItem calls GetItemFunc.
func (mock *ItemRepositoryInterfaceMock) GetItem(ctx context.Context, f *firestore.Client, userID string, id string) (*model.Item, error) {
if mock.GetItemFunc == nil {
panic("ItemRepositoryInterfaceMock.GetItemFunc: method is nil but ItemRepositoryInterface.GetItem was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
ID string
}{
Ctx: ctx,
F: f,
UserID: userID,
ID: id,
}
mock.lockGetItem.Lock()
mock.calls.GetItem = append(mock.calls.GetItem, callInfo)
mock.lockGetItem.Unlock()
return mock.GetItemFunc(ctx, f, userID, id)
}
// GetItemCalls gets all the calls that were made to GetItem.
// Check the length with:
//
// len(mockedItemRepositoryInterface.GetItemCalls())
func (mock *ItemRepositoryInterfaceMock) GetItemCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
ID string
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
ID string
}
mock.lockGetItem.RLock()
calls = mock.calls.GetItem
mock.lockGetItem.RUnlock()
return calls
}
// GetItemUserMultipleInPeriod calls GetItemUserMultipleInPeriodFunc.
func (mock *ItemRepositoryInterfaceMock) GetItemUserMultipleInPeriod(ctx context.Context, f *firestore.Client, sip repository.SearchItemParam, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error) {
if mock.GetItemUserMultipleInPeriodFunc == nil {
panic("ItemRepositoryInterfaceMock.GetItemUserMultipleInPeriodFunc: method is nil but ItemRepositoryInterface.GetItemUserMultipleInPeriod was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
First int
Cursor repository.ItemsInPeriodCursor
}{
Ctx: ctx,
F: f,
Sip: sip,
First: first,
Cursor: cursor,
}
mock.lockGetItemUserMultipleInPeriod.Lock()
mock.calls.GetItemUserMultipleInPeriod = append(mock.calls.GetItemUserMultipleInPeriod, callInfo)
mock.lockGetItemUserMultipleInPeriod.Unlock()
return mock.GetItemUserMultipleInPeriodFunc(ctx, f, sip, first, cursor)
}
// GetItemUserMultipleInPeriodCalls gets all the calls that were made to GetItemUserMultipleInPeriod.
// Check the length with:
//
// len(mockedItemRepositoryInterface.GetItemUserMultipleInPeriodCalls())
func (mock *ItemRepositoryInterfaceMock) GetItemUserMultipleInPeriodCalls() []struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
First int
Cursor repository.ItemsInPeriodCursor
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
Sip repository.SearchItemParam
First int
Cursor repository.ItemsInPeriodCursor
}
mock.lockGetItemUserMultipleInPeriod.RLock()
calls = mock.calls.GetItemUserMultipleInPeriod
mock.lockGetItemUserMultipleInPeriod.RUnlock()
return calls
}
// GetItemsInDate calls GetItemsInDateFunc.
func (mock *ItemRepositoryInterfaceMock) GetItemsInDate(ctx context.Context, f *firestore.Client, userID string, date time.Time) ([]*model.Item, error) {
if mock.GetItemsInDateFunc == nil {
panic("ItemRepositoryInterfaceMock.GetItemsInDateFunc: method is nil but ItemRepositoryInterface.GetItemsInDate was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
Date time.Time
}{
Ctx: ctx,
F: f,
UserID: userID,
Date: date,
}
mock.lockGetItemsInDate.Lock()
mock.calls.GetItemsInDate = append(mock.calls.GetItemsInDate, callInfo)
mock.lockGetItemsInDate.Unlock()
return mock.GetItemsInDateFunc(ctx, f, userID, date)
}
// GetItemsInDateCalls gets all the calls that were made to GetItemsInDate.
// Check the length with:
//
// len(mockedItemRepositoryInterface.GetItemsInDateCalls())
func (mock *ItemRepositoryInterfaceMock) GetItemsInDateCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
Date time.Time
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
Date time.Time
}
mock.lockGetItemsInDate.RLock()
calls = mock.calls.GetItemsInDate
mock.lockGetItemsInDate.RUnlock()
return calls
}
// GetItemsInPeriod calls GetItemsInPeriodFunc.
func (mock *ItemRepositoryInterfaceMock) GetItemsInPeriod(ctx context.Context, f *firestore.Client, userID string, stertDate time.Time, endDate time.Time, first int, cursor repository.ItemsInPeriodCursor) ([]*model.Item, error) {
if mock.GetItemsInPeriodFunc == nil {
panic("ItemRepositoryInterfaceMock.GetItemsInPeriodFunc: method is nil but ItemRepositoryInterface.GetItemsInPeriod was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
StertDate time.Time
EndDate time.Time
First int
Cursor repository.ItemsInPeriodCursor
}{
Ctx: ctx,
F: f,
UserID: userID,
StertDate: stertDate,
EndDate: endDate,
First: first,
Cursor: cursor,
}
mock.lockGetItemsInPeriod.Lock()
mock.calls.GetItemsInPeriod = append(mock.calls.GetItemsInPeriod, callInfo)
mock.lockGetItemsInPeriod.Unlock()
return mock.GetItemsInPeriodFunc(ctx, f, userID, stertDate, endDate, first, cursor)
}
// GetItemsInPeriodCalls gets all the calls that were made to GetItemsInPeriod.
// Check the length with:
//
// len(mockedItemRepositoryInterface.GetItemsInPeriodCalls())
func (mock *ItemRepositoryInterfaceMock) GetItemsInPeriodCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
StertDate time.Time
EndDate time.Time
First int
Cursor repository.ItemsInPeriodCursor
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
StertDate time.Time
EndDate time.Time
First int
Cursor repository.ItemsInPeriodCursor
}
mock.lockGetItemsInPeriod.RLock()
calls = mock.calls.GetItemsInPeriod
mock.lockGetItemsInPeriod.RUnlock()
return calls
}
// Update calls UpdateFunc.
func (mock *ItemRepositoryInterfaceMock) Update(ctx context.Context, f *firestore.Client, userID string, i *model.UpdateItem, updatedAt time.Time) error {
if mock.UpdateFunc == nil {
panic("ItemRepositoryInterfaceMock.UpdateFunc: method is nil but ItemRepositoryInterface.Update was just called")
}
callInfo := struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.UpdateItem
UpdatedAt time.Time
}{
Ctx: ctx,
F: f,
UserID: userID,
I: i,
UpdatedAt: updatedAt,
}
mock.lockUpdate.Lock()
mock.calls.Update = append(mock.calls.Update, callInfo)
mock.lockUpdate.Unlock()
return mock.UpdateFunc(ctx, f, userID, i, updatedAt)
}
// UpdateCalls gets all the calls that were made to Update.
// Check the length with:
//
// len(mockedItemRepositoryInterface.UpdateCalls())
func (mock *ItemRepositoryInterfaceMock) UpdateCalls() []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.UpdateItem
UpdatedAt time.Time
} {
var calls []struct {
Ctx context.Context
F *firestore.Client
UserID string
I *model.UpdateItem
UpdatedAt time.Time
}
mock.lockUpdate.RLock()
calls = mock.calls.Update
mock.lockUpdate.RUnlock()
return calls
}