Skip to content

Commit fc9f5e4

Browse files
authored
chore: update tests for replaceItems with actOnDispatch (feathersjs-ecosystem#752)
1 parent aeb5c56 commit fc9f5e4

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

test/hooks/get-replace-items.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from 'vitest';
2-
import { getItems, replaceItems } from '../../src';
2+
import { actOnDispatch, getItems, replaceItems } from '../../src';
33

44
// Tests when context.params._actOn === 'dispatch' are in act-on.test.ts
55

@@ -183,4 +183,59 @@ describe('services getItems & replaceItems', () => {
183183
assert.deepEqual(hookFindPaginate.result.data, [{ a: 1 }, { b: 2 }]);
184184
});
185185
});
186+
187+
describe('replaceItems actOnDispatch', () => {
188+
beforeEach(() => {
189+
hookBefore = { type: 'before', method: 'create', params: { provider: 'rest' } };
190+
hookAfter = { type: 'after', method: 'create', params: { provider: 'rest' } };
191+
hookFindPaginate = {
192+
type: 'after',
193+
method: 'find',
194+
params: { provider: 'rest' },
195+
dispatch: {
196+
total: 200,
197+
data: [],
198+
},
199+
};
200+
hookFind = {
201+
type: 'after',
202+
method: 'find',
203+
params: { provider: 'rest' },
204+
};
205+
});
206+
207+
it('updates hook after::create item', async () => {
208+
await actOnDispatch(() => replaceItems(hookAfter, { a: 1 }))(hookAfter);
209+
assert.deepEqual(hookAfter.dispatch, { a: 1 });
210+
});
211+
212+
it('updates hook after::create items', async () => {
213+
await actOnDispatch(() => replaceItems(hookAfter, [{ a: 1 }, { b: 2 }]))(hookAfter);
214+
assert.deepEqual(hookAfter.dispatch, [{ a: 1 }, { b: 2 }]);
215+
});
216+
217+
it('updates hook after::find item', async () => {
218+
await actOnDispatch(() => replaceItems(hookFind, { a: 1 }))(hookFind);
219+
assert.deepEqual(hookFind.dispatch, { a: 1 });
220+
});
221+
222+
it('updates hook after::find items', async () => {
223+
await actOnDispatch(() => replaceItems(hookFind, [{ a: 1 }, { b: 2 }]))(hookFind);
224+
assert.deepEqual(hookFind.dispatch, [{ a: 1 }, { b: 2 }]);
225+
});
226+
227+
it('updates hook after::find item paginated NOTE THIS TEST NOTE THIS TEST', async () => {
228+
await actOnDispatch(() => replaceItems(hookFindPaginate, { a: 1 }))(hookFindPaginate);
229+
assert.equal(hookFindPaginate.dispatch.total, 200);
230+
assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }]);
231+
});
232+
233+
it('updates hook after::find items paginated', async () => {
234+
await actOnDispatch(() => replaceItems(hookFindPaginate, [{ a: 1 }, { b: 2 }]))(
235+
hookFindPaginate,
236+
);
237+
assert.equal(hookFindPaginate.dispatch.total, 200);
238+
assert.deepEqual(hookFindPaginate.dispatch.data, [{ a: 1 }, { b: 2 }]);
239+
});
240+
});
186241
});

0 commit comments

Comments
 (0)