Skip to content

Commit bcedd93

Browse files
committed
add tests
1 parent cfa02ad commit bcedd93

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/ra-data-simple-rest/src/index.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ describe('Data Simple REST Client', () => {
6767

6868
expect(result.total).toEqual(42);
6969
});
70+
it('should support embeds via meta', async () => {
71+
const httpClient = jest.fn(() =>
72+
Promise.resolve({
73+
headers: new Headers({
74+
'content-range': '0/4-8',
75+
}),
76+
})
77+
);
78+
const client = simpleClient('http://localhost:3000', httpClient);
79+
80+
await client.getList('posts', {
81+
filter: {},
82+
pagination: { page: 1, perPage: 10 },
83+
sort: { field: 'title', order: 'DESC' },
84+
meta: { embed: ['author'] },
85+
});
86+
87+
expect(httpClient).toHaveBeenCalledWith(
88+
'http://localhost:3000/posts?embed=%5B%22author%22%5D&filter=%7B%7D&range=%5B0%2C9%5D&sort=%5B%22title%22%2C%22DESC%22%5D',
89+
{ headers: { map: { range: 'posts=0-9' } } }
90+
);
91+
});
7092
});
7193
describe('getOne', () => {
7294
it('should allow numeric id in path', async () => {
@@ -91,6 +113,20 @@ describe('Data Simple REST Client', () => {
91113
expect.any(Object)
92114
);
93115
});
116+
it('should support embeds via meta', async () => {
117+
const httpClient = jest.fn().mockResolvedValue({ id: 'Post#123' });
118+
const client = simpleClient('http://localhost:3000', httpClient);
119+
120+
await client.getOne('posts', {
121+
id: 'Post#123',
122+
meta: { embed: ['author'] },
123+
});
124+
125+
expect(httpClient).toHaveBeenCalledWith(
126+
'http://localhost:3000/posts/Post%23123?embed=%5B%22author%22%5D',
127+
expect.any(Object)
128+
);
129+
});
94130
});
95131
describe('update', () => {
96132
it('should escape id in path', async () => {

0 commit comments

Comments
 (0)