Skip to content

Commit e3d5483

Browse files
committed
test: add verification for isSavePending sugar
1 parent 8026d90 commit e3d5483

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

test/service-module/model-base.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ describe('makeModel / BaseModel', function () {
119119
'isUpdatePending',
120120
'isPatchPending',
121121
'isRemovePending',
122+
'isSavePending',
122123
'isPending'
123124
]
124125
const m = new BaseModel()

test/service-module/model-methods.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ describe('Models - Methods', function () {
387387
context.result = { _id: 42, ...context.data }
388388
// Check pending status
389389
assert(thing.isCreatePending === true, 'isCreatePending set')
390+
assert(thing.isSavePending === true, 'isSavePending set')
390391
assert(thing.isPending === true, 'isPending set')
391392
// Check clone's pending status
392393
assert(clone.isCreatePending === true, 'isCreatePending set on clone')
394+
assert(clone.isSavePending === true, 'isSavePending set on clone')
393395
assert(clone.isPending === true, 'isPending set on clone')
394396
return context
395397
}
@@ -399,9 +401,11 @@ describe('Models - Methods', function () {
399401
context.result = { ...context.data }
400402
// Check pending status
401403
assert(thing.isUpdatePending === true, 'isUpdatePending set')
404+
assert(thing.isSavePending === true, 'isSavePending set')
402405
assert(thing.isPending === true, 'isPending set')
403406
// Check clone's pending status
404407
assert(clone.isUpdatePending === true, 'isUpdatePending set on clone')
408+
assert(clone.isSavePending === true, 'isSavePending set on clone')
405409
assert(clone.isPending === true, 'isPending set on clone')
406410
return context
407411
}
@@ -411,9 +415,11 @@ describe('Models - Methods', function () {
411415
context.result = { ...context.data }
412416
// Check pending status
413417
assert(thing.isPatchPending === true, 'isPatchPending set')
418+
assert(thing.isSavePending === true, 'isSavePending set')
414419
assert(thing.isPending === true, 'isPending set')
415420
// Check clone's pending status
416421
assert(clone.isPatchPending === true, 'isPatchPending set on clone')
422+
assert(clone.isSavePending === true, 'isSavePending set on clone')
417423
assert(clone.isPending === true, 'isPending set on clone')
418424
return context
419425
}
@@ -423,9 +429,11 @@ describe('Models - Methods', function () {
423429
context.result = { ...context.data }
424430
// Check pending status
425431
assert(thing.isRemovePending === true, 'isRemovePending set')
432+
assert(thing.isSavePending === false, 'isSavePending clear on remove')
426433
assert(thing.isPending === true, 'isPending set')
427434
// Check clone's pending status
428435
assert(clone.isRemovePending === true, 'isRemovePending set on clone')
436+
assert(clone.isSavePending === false, 'isSavePending clear on remove on clone')
429437
assert(clone.isPending === true, 'isPending set on clone')
430438
return context
431439
}
@@ -436,29 +444,37 @@ describe('Models - Methods', function () {
436444
// Create and verify status
437445
await thing.create()
438446
assert(thing.isCreatePending === false, 'isCreatePending cleared')
447+
assert(thing.isSavePending === false, 'isSavePending cleared')
439448
assert(thing.isPending === false, 'isPending cleared')
440449
assert(clone.isCreatePending === false, 'isCreatePending cleared on clone')
450+
assert(clone.isSavePending === false, 'isSavePending cleared on clone')
441451
assert(clone.isPending === false, 'isPending cleared on clone')
442452

443453
// Update and verify status
444454
await thing.update()
445455
assert(thing.isUpdatePending === false, 'isUpdatePending cleared')
456+
assert(thing.isSavePending === false, 'isSavePending cleared')
446457
assert(thing.isPending === false, 'isPending cleared')
447458
assert(clone.isUpdatePending === false, 'isUpdatePending cleared on clone')
459+
assert(clone.isSavePending === false, 'isSavePending cleared on clone')
448460
assert(clone.isPending === false, 'isPending cleared on clone')
449461

450462
// Patch and verify status
451463
await thing.patch()
452464
assert(thing.isPatchPending === false, 'isPatchPending cleared')
465+
assert(thing.isSavePending === false, 'isSavePending cleared')
453466
assert(thing.isPending === false, 'isPending cleared')
454467
assert(clone.isPatchPending === false, 'isPatchPending cleared on clone')
468+
assert(clone.isSavePending === false, 'isSavePending cleared on clone')
455469
assert(clone.isPending === false, 'isPending cleared on clone')
456470

457471
// Remove and verify status
458472
await thing.remove()
459473
assert(thing.isRemovePending === false, 'isRemovePending cleared')
474+
assert(thing.isSavePending === false, 'isSavePending cleared')
460475
assert(thing.isPending === false, 'isPending cleared')
461476
assert(clone.isRemovePending === false, 'isRemovePending cleared on clone')
477+
assert(clone.isSavePending === false, 'isSavePending cleared on clone')
462478
assert(clone.isPending === false, 'isPending cleared on clone')
463479
})
464480
})

test/service-module/model-temp-ids.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ describe('Models - Temp Ids', function() {
612612
context.result = { _id: 42, ...context.data }
613613
// Check pending status
614614
assert(thing.isCreatePending === true, 'isCreatePending set')
615+
assert(thing.isSavePending === true, 'isSavePending set')
615616
assert(thing.isPending === true, 'isPending set')
616617
// Check clone's pending status
617618
assert(clone.isCreatePending === true, 'isCreatePending set')
619+
assert(clone.isSavePending === true, 'isSavePending set on clone')
618620
assert(clone.isPending === true, 'isPending set')
619621
return context
620622
}
@@ -625,8 +627,10 @@ describe('Models - Temp Ids', function() {
625627
// Save and verify status
626628
await thing.save()
627629
assert(thing.isCreatePending === false, 'isCreatePending cleared')
630+
assert(thing.isSavePending === false, 'isSavePending cleared')
628631
assert(thing.isPending === false, 'isPending cleared')
629632
assert(clone.isCreatePending === false, 'isCreatePending cleared')
633+
assert(clone.isSavePending === false, 'isSavePending cleared on clone')
630634
assert(clone.isPending === false, 'isPending cleared')
631635
})
632636
})

test/service-module/module.getters.test.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const options = {
2121
service: null
2222
}
2323

24-
const { find, count, list, get, getCopyById, isCreatePendingById, isUpdatePendingById, isPatchPendingById, isRemovePendingById, isPendingById } = makeServiceGetters()
24+
const { find, count, list, get, getCopyById, isCreatePendingById, isUpdatePendingById, isPatchPendingById, isRemovePendingById, isSavePendingById, isPendingById } = makeServiceGetters()
2525
const { addItems, setIdPending, unsetIdPending } = makeServiceMutations()
2626

2727
describe('Service Module - Getters', function () {
@@ -406,60 +406,80 @@ describe('Service Module - Getters', function () {
406406

407407
it('is*PendingById', function() {
408408
const { state } = this
409-
const getters = { isCreatePendingById, isUpdatePendingById, isPatchPendingById, isRemovePendingById }
409+
410+
// Set up getters
411+
const getters: any = {
412+
isCreatePendingById: isCreatePendingById(state),
413+
isUpdatePendingById: isUpdatePendingById(state),
414+
isPatchPendingById: isPatchPendingById(state),
415+
isRemovePendingById: isRemovePendingById(state),
416+
isSavePendingById,
417+
isPendingById
418+
}
419+
getters.isSavePendingById = isSavePendingById(state, getters)
420+
getters.isPendingById = isPendingById(state, getters)
410421

411422
assert(isCreatePendingById(state)(42) === false, 'creating status is clear')
412423
assert(isUpdatePendingById(state)(42) === false, 'updating status is clear')
413424
assert(isPatchPendingById(state)(42) === false, 'patching status is clear')
414425
assert(isRemovePendingById(state)(42) === false, 'removing status is clear')
415-
assert(isPendingById(state, getters)(42), 'any method pending status is clear')
426+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear')
427+
assert(isPendingById(state, getters)(42) === false, 'any method pending status is clear')
416428

417429
// Create
418430
setIdPending(state, { method: 'create', id: 42})
419431
assert(isCreatePendingById(state)(42) === true, 'creating status is set')
420-
assert(isPendingById(state, getters)(42), 'any method pending status is set')
432+
assert(isSavePendingById(state, getters)(42) === true, 'saving status is set')
433+
assert(isPendingById(state, getters)(42) === true, 'any method pending status is set')
421434

422435
unsetIdPending(state, { method: 'create', id: 42 })
423436
assert(isCreatePendingById(state)(42) === false, 'creating status is clear')
424437
assert(isUpdatePendingById(state)(42) === false, 'updating status is clear')
425438
assert(isPatchPendingById(state)(42) === false, 'patching status is clear')
426439
assert(isRemovePendingById(state)(42) === false, 'removing status is clear')
427-
assert(isPendingById(state, getters)(42), 'any method pending status is clear')
440+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear')
441+
assert(isPendingById(state, getters)(42) === false, 'any method pending status is clear')
428442

429443
// Update
430444
setIdPending(state, { method: 'update', id: 42})
431445
assert(isUpdatePendingById(state)(42) === true, 'updating status is set')
432-
assert(isPendingById(state, getters)(42), 'any method pending status is set')
446+
assert(isSavePendingById(state, getters)(42) === true, 'saving status is set')
447+
assert(isPendingById(state, getters)(42) === true, 'any method pending status is set')
433448

434449
unsetIdPending(state, { method: 'update', id: 42 })
435450
assert(isCreatePendingById(state)(42) === false, 'creating status is clear')
436451
assert(isUpdatePendingById(state)(42) === false, 'updating status is clear')
437452
assert(isPatchPendingById(state)(42) === false, 'patching status is clear')
438453
assert(isRemovePendingById(state)(42) === false, 'removing status is clear')
439-
assert(isPendingById(state, getters)(42), 'any method pending status is clear')
454+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear')
455+
assert(isPendingById(state, getters)(42) === false, 'any method pending status is clear')
440456

441457
// Patch
442458
setIdPending(state, { method: 'patch', id: 42})
443459
assert(isPatchPendingById(state)(42) === true, 'patching status is set')
444-
assert(isPendingById(state, getters)(42), 'any method pending status is set')
460+
assert(isSavePendingById(state, getters)(42) === true, 'saving status is set')
461+
assert(isPendingById(state, getters)(42) === true, 'any method pending status is set')
445462

446463
unsetIdPending(state, { method: 'patch', id: 42 })
447464
assert(isCreatePendingById(state)(42) === false, 'creating status is clear')
448465
assert(isUpdatePendingById(state)(42) === false, 'updating status is clear')
449466
assert(isPatchPendingById(state)(42) === false, 'patching status is clear')
450467
assert(isRemovePendingById(state)(42) === false, 'removing status is clear')
451-
assert(isPendingById(state, getters)(42), 'any method pending status is clear')
468+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear')
469+
assert(isPendingById(state, getters)(42) === false, 'any method pending status is clear')
452470

453471
// Remove
454472
setIdPending(state, { method: 'remove', id: 42})
455473
assert(isRemovePendingById(state)(42) === true, 'removing status is set')
456-
assert(isPendingById(state, getters)(42), 'any method pending status is set')
474+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear for remove')
475+
assert(isPendingById(state, getters)(42) === true, 'any method pending status is set')
457476

458477
unsetIdPending(state, { method: 'remove', id: 42 })
459478
assert(isCreatePendingById(state)(42) === false, 'creating status is clear')
460479
assert(isUpdatePendingById(state)(42) === false, 'updating status is clear')
461480
assert(isPatchPendingById(state)(42) === false, 'patching status is clear')
462481
assert(isRemovePendingById(state)(42) === false, 'removing status is clear')
463-
assert(isPendingById(state, getters)(42), 'any method pending status is clear')
482+
assert(isSavePendingById(state, getters)(42) === false, 'saving status is clear')
483+
assert(isPendingById(state, getters)(42) === false, 'any method pending status is clear')
464484
})
465485
})

test/service-module/service-module.actions.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ describe('Service Module - Actions', () => {
929929
assert(todoState.errorOnUpdate === null)
930930
assert(todoState.isUpdatePending === false)
931931
assert(store.getters['my-todos/isUpdatePendingById'](0) === false, 'ID pending update clear')
932+
assert(store.getters['my-todos/isSavePendingById'](0) === false, 'ID pending save clear')
932933
assert(store.getters['my-todos/isPendingById'](0) === false, 'ID pending clear')
933934
assert.deepEqual(
934935
todoState.keyedById[responseFromUpdate.id],
@@ -942,6 +943,7 @@ describe('Service Module - Actions', () => {
942943
assert(todoState.errorOnUpdate === null)
943944
assert(todoState.isUpdatePending === true)
944945
assert(store.getters['my-todos/isUpdatePendingById'](0) === true, 'ID pending update set')
946+
assert(store.getters['my-todos/isSavePendingById'](0) === true, 'ID pending save set')
945947
assert(store.getters['my-todos/isPendingById'](0) === true, 'ID pending set')
946948
assert(todoState.idField === 'id')
947949
})
@@ -1027,6 +1029,7 @@ describe('Service Module - Actions', () => {
10271029
assert(todoState.errorOnPatch === null)
10281030
assert(todoState.isPatchPending === false)
10291031
assert(store.getters['my-todos/isPatchPendingById'](0) === false, 'ID pending patch clear')
1032+
assert(store.getters['my-todos/isSavePendingById'](0) === false, 'ID pending save clear')
10301033
assert(store.getters['my-todos/isPendingById'](0) === false, 'ID pending clear')
10311034
assert.deepEqual(
10321035
todoState.keyedById[responseFromPatch.id],
@@ -1040,6 +1043,7 @@ describe('Service Module - Actions', () => {
10401043
assert(todoState.errorOnPatch === null)
10411044
assert(todoState.isPatchPending === true)
10421045
assert(store.getters['my-todos/isPatchPendingById'](0) === true, 'ID pending patch set')
1046+
assert(store.getters['my-todos/isSavePendingById'](0) === true, 'ID pending save set')
10431047
assert(store.getters['my-todos/isPendingById'](0) === true, 'ID pending set')
10441048
assert(todoState.idField === 'id')
10451049
})
@@ -1107,6 +1111,7 @@ describe('Service Module - Actions', () => {
11071111
assert(todoState.errorOnPatch === null)
11081112
assert(todoState.isPatchPending === false)
11091113
assert(store.getters['my-todos/isPatchPendingById'](0) === false, 'ID pending patch clear')
1114+
assert(store.getters['my-todos/isSavePendingById'](0) === false, 'ID pending save clear')
11101115
assert(store.getters['my-todos/isPendingById'](0) === false, 'ID pending clear')
11111116
assert.deepEqual(
11121117
todoState.keyedById[responseFromPatch.id],
@@ -1120,6 +1125,7 @@ describe('Service Module - Actions', () => {
11201125
assert(todoState.errorOnPatch === null)
11211126
assert(todoState.isPatchPending === true)
11221127
assert(store.getters['my-todos/isPatchPendingById'](0) === true, 'ID pending patch set')
1128+
assert(store.getters['my-todos/isSavePendingById'](0) === true, 'ID pending save set')
11231129
assert(store.getters['my-todos/isPendingById'](0) === true, 'ID pending set')
11241130
assert(todoState.idField === 'id')
11251131
})
@@ -1187,6 +1193,7 @@ describe('Service Module - Actions', () => {
11871193
assert(todoState.errorOnRemove === null)
11881194
assert(todoState.isRemovePending === false)
11891195
assert(store.getters['my-todos/isRemovePendingById'](0) === false, 'ID pending remove clear')
1196+
assert(store.getters['my-todos/isSavePendingById'](0) === false, 'ID pending save clear')
11901197
assert(store.getters['my-todos/isPendingById'](0) === false, 'ID pending clear')
11911198
assert.deepEqual(todoState.keyedById, {})
11921199
done()
@@ -1201,6 +1208,7 @@ describe('Service Module - Actions', () => {
12011208
assert(todoState.errorOnRemove === null)
12021209
assert(todoState.isRemovePending === true)
12031210
assert(store.getters['my-todos/isRemovePendingById'](0) === true, 'ID pending remove set')
1211+
assert(store.getters['my-todos/isSavePendingById'](0) === false, 'ID pending save clear')
12041212
assert(store.getters['my-todos/isPendingById'](0) === true, 'ID pending set')
12051213
assert(todoState.idField === 'id')
12061214
})

0 commit comments

Comments
 (0)