|
6 | 6 | import { assert } from 'chai'
|
7 | 7 | import { assertGetter } from '../test-utils'
|
8 | 8 | import makeServiceMutations, {
|
9 |
| - PendingServiceMethodName |
| 9 | + PendingServiceMethodName, PendingIdServiceMethodName |
10 | 10 | } from '../../src/service-module/service-module.mutations'
|
11 | 11 | import makeServiceState from '../../src/service-module/service-module.state'
|
12 | 12 | import errors from '@feathersjs/errors'
|
@@ -55,7 +55,9 @@ const {
|
55 | 55 | setPending,
|
56 | 56 | unsetPending,
|
57 | 57 | setError,
|
58 |
| - clearError |
| 58 | + clearError, |
| 59 | + setIdPending, |
| 60 | + unsetIdPending |
59 | 61 | } = makeServiceMutations()
|
60 | 62 |
|
61 | 63 | describe('Service Module - Mutations', function() {
|
@@ -1169,6 +1171,31 @@ describe('Service Module - Mutations', function() {
|
1169 | 1171 | })
|
1170 | 1172 | })
|
1171 | 1173 |
|
| 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 | + |
1172 | 1199 | describe('Errors', function() {
|
1173 | 1200 | it('setError', function() {
|
1174 | 1201 | const state = this.state
|
|
0 commit comments