Skip to content

Commit 45aef78

Browse files
committed
test: setIdPending & unsetIdPending mutations
1 parent 3b599cf commit 45aef78

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

test/service-module/service-module.mutations.test.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ eslint
66
import { assert } from 'chai'
77
import { assertGetter } from '../test-utils'
88
import makeServiceMutations, {
9-
PendingServiceMethodName
9+
PendingServiceMethodName, PendingIdServiceMethodName
1010
} from '../../src/service-module/service-module.mutations'
1111
import makeServiceState from '../../src/service-module/service-module.state'
1212
import errors from '@feathersjs/errors'
@@ -55,7 +55,9 @@ const {
5555
setPending,
5656
unsetPending,
5757
setError,
58-
clearError
58+
clearError,
59+
setIdPending,
60+
unsetIdPending
5961
} = makeServiceMutations()
6062

6163
describe('Service Module - Mutations', function() {
@@ -1169,6 +1171,31 @@ describe('Service Module - Mutations', function() {
11691171
})
11701172
})
11711173

1174+
describe('Per-instance Pending', function() {
1175+
it('setIdPending && unsetIdPending', function() {
1176+
const state = this.state
1177+
const methods: PendingIdServiceMethodName[] = [
1178+
'create',
1179+
'update',
1180+
'patch',
1181+
'remove'
1182+
]
1183+
1184+
methods.forEach(method => {
1185+
const uppercaseMethod = method.charAt(0).toUpperCase() + method.slice(1)
1186+
assert(state[`isId${uppercaseMethod}Pending`].length === 0)
1187+
1188+
// Set pending & check
1189+
setIdPending(state, { method, id: 42 })
1190+
assert(state[`isId${uppercaseMethod}Pending`].includes(42))
1191+
1192+
// Unset pending & check
1193+
unsetIdPending(state, { method, id: 42 })
1194+
assert(state[`isId${uppercaseMethod}Pending`].length === 0)
1195+
})
1196+
})
1197+
})
1198+
11721199
describe('Errors', function() {
11731200
it('setError', function() {
11741201
const state = this.state

0 commit comments

Comments
 (0)