Skip to content

Commit b9e3879

Browse files
committed
internal: Add end to end test
1 parent 2bfa172 commit b9e3879

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

__tests__/new.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ export class FutureArticleResource extends CoolerArticleResource {
249249
return instanceFetch(this.url(), this.getFetchInit(body));
250250
},
251251
url: this.listUrl.bind(this),
252+
update: (newid: string) => ({
253+
[this.list().key({})]: (existing: string[]) => [newid, ...existing],
254+
}),
252255
});
253256
}
254257

packages/core/src/state/reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export default function reducer(
7171
results = applyUpdatersToResults(results, result, action.meta.updaters);
7272
if (action.meta.update) {
7373
const updaters = action.meta.update(result);
74-
Object.keys(updaters).forEach(
75-
key => { results[key] = updaters[key](results[key]); },
76-
);
74+
Object.keys(updaters).forEach(key => {
75+
results[key] = updaters[key](results[key]);
76+
});
7777
}
7878
return {
7979
entities: mergeDeepCopy(

packages/experimental/src/__tests__/useFetcher.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FutureArticleResource } from '__tests__/new';
22
import nock from 'nock';
3-
import { useCache } from '@rest-hooks/core';
3+
import { useCache, useResource } from '@rest-hooks/core';
44

55
// relative imports to avoid circular dependency in tsconfig references
66
import {
@@ -24,6 +24,29 @@ export const createPayload = {
2424
tags: ['a', 'best', 'react'],
2525
};
2626

27+
export const nested = [
28+
{
29+
id: 5,
30+
title: 'hi ho',
31+
content: 'whatever',
32+
tags: ['a', 'best', 'react'],
33+
author: {
34+
id: 23,
35+
username: 'bob',
36+
},
37+
},
38+
{
39+
id: 3,
40+
title: 'the next time',
41+
content: 'whatever',
42+
author: {
43+
id: 23,
44+
username: 'charles',
45+
46+
},
47+
},
48+
];
49+
2750
for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
2851
describe(`${makeProvider.name} => <Provider />`, () => {
2952
// TODO: add nested resource test case that has multiple partials to test merge functionality
@@ -50,6 +73,9 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
5073
.reply(403, {})
5174
.get(`/article-cooler/666`)
5275
.reply(200, '')
76+
.get(`/article-cooler/`)
77+
.reply(200, nested)
78+
5379
.post(`/article-cooler/`)
5480
.reply(200, createPayload);
5581

@@ -105,7 +131,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
105131
};
106132
});
107133

108-
/*it('should update on create', async () => {
134+
it('should update on create', async () => {
109135
const { result, waitForNextUpdate } = renderRestHook(() => {
110136
const articles = useResource(FutureArticleResource.list(), {});
111137
const fetch = useFetcher();
@@ -115,7 +141,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
115141
await result.current.fetch(FutureArticleResource.create(), {
116142
id: 1,
117143
});
118-
expect(result.current.articles.map(({ id }) => id)).toEqual([5, 3, 1]);
119-
});*/
144+
expect(result.current.articles.map(({ id }) => id)).toEqual([1, 5, 3]);
145+
});
120146
});
121147
}

0 commit comments

Comments
 (0)