How does a test response body get generated?

In /refine/packages/hasura/test/getList/index.mock.ts, it looks like the nock responses are a long string "1f8b08000000000004037d93516bdc300cc7bf8ac973058ee3c4f6bdf5c6b60eb651dabe8d326459be0b4d9312e70adbd1ef3eb5db989f663058c6fcf4f75fd2b949b861b33b374f4bd94ab3fb766ec6d4ec9a8864386b041f42063b040bde72861868c86c1399e89a8b661bb789e53996945f77c1949b970bf597d2060a3159483907b04c19903203321ab214986c5b512e0f3c6f6acfeb43398e2bab9b53d946aa789452b2c40986be4d60751700236b30182443244fde54bc0f0b9d8a3aaccbe9495d9d1e7156b713f3430df4865c4b3de8aca300ad911f62072906e7321b8fbeab80ef219eca3873290a275c1f456bcacb9adee45658a6e4104d0b6dc856dca300913a06635ca2a4bd7639fd075b915c9f62f6dac39048838d2e424c2d426e73e75b66cd962ad27e99c6e711e7457d794ecba4f666af6e711457af78e219d5f5729a53cd77beeb07f72a2d1bb0b9b7c24771817c6f2c7618a876f42b6ee332e3a43eae388f1babc7651b9fe5723e5450efd13a292e98304899248240bd0317add7127a3dd4cd73854f526675b71c16b5cc93f82bb92b9cf3c17b173be0dcf560c9690859eadf3b313979491243e5c11dc689d5a73949f7aca3687d77647a1085ea9248bebf05df56f4905c707a304011a5d3b175e05b43d0b7d60d98b3b5b676e09ad7f2e6c0e745fae90f51951ff376e432fe7c4d73c38571a5e36075f3727ff17bb4bee3e1b0f20137199773f32f503b199637598d1c4dff22eb17578a0b6196030000" How does this get transformed into the response that is used for assertions in the spec file?
K
kapa.ai379d ago
Hi @matt.ho. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
K
kapa.ai379d ago
---------------------- Hmm, I don't know enough to give you a confident answer yet. However, you can refer to the refine documentation for more information: https://refine.dev/docs ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Overview | refine
What is refine?
K
kapa.ai379d ago
<@692495582262067261> kapa.ai is still learning and improving, please let us how it did by reacting below
H
helpful-purple378d ago
Hey @matt.ho, First comment the import "./index.mock"; import in getList/index.spec.ts. Then, import nock from nock. Finally you can use the nock to record API responses like below:
it("correct response", async () => {
nock.recorder.rec();
const { data, total } = await dataProvider(client).getList({
resource: "posts",
meta: {
fields: ["id", "title"],
},
});

expect(data[0]["id"]).toBe("bac2ef0a-899f-4694-84ef-b9c6fe4dc2b7");
expect(data[0]["title"]).toBe("asdfasdfsadf");
expect(total).toBe(25);
});
it("correct response", async () => {
nock.recorder.rec();
const { data, total } = await dataProvider(client).getList({
resource: "posts",
meta: {
fields: ["id", "title"],
},
});

expect(data[0]["id"]).toBe("bac2ef0a-899f-4694-84ef-b9c6fe4dc2b7");
expect(data[0]["title"]).toBe("asdfasdfsadf");
expect(total).toBe(25);
});
When you run the test, it will write the mock response in your terminal, don't forget to save it in the index.mock file.
A
absent-sapphire371d ago
@salihozdemir How does the data object get defined?
expect(data[0]["id"]).toEqual("45");
expect(data[0]["title"]).toEqual("foo");
expect(data[0]["content"]).toEqual("bar");
expect(data[0]["category"].id).toEqual("2");
expect(data[0]["id"]).toEqual("45");
expect(data[0]["title"]).toEqual("foo");
expect(data[0]["content"]).toEqual("bar");
expect(data[0]["category"].id).toEqual("2");
H
helpful-purple371d ago
Do you mean something like this?
const data = [
{
id: "45",
title: "foo",
content: "bar",
category: {
id: "2",
}
}
]
const data = [
{
id: "45",
title: "foo",
content: "bar",
category: {
id: "2",
}
}
]
Btw, you can check out it: https://refine.dev/blog/mocking-api-calls-in-react/ for more details about nock.
A
absent-sapphire371d ago
Yes! Oh exactly what I'm looking for. Than kyou
More Posts
How to convert Form data before requestingI used antd. I have a multi choice field on the create page. ```tsx <Form.Item name={['user', 'id']}How to make, delete and edit repeatable componentsI am using Strapi V4 with refine and ant design and I am trying to figure out what the best way to aStuck at Error: No QueryClient set, use QueryClientProvider to set oneHey guys, Thanks first of all for this great open source project. Really appreciate it. I am playinI can't seem to run npm install to create refine appnpm create refine-app@latest client C:\Users\Admin\AppData\Local\npm-cache\_npx\98c66fac912b1cba\nodHow to change sider icon automatically with inferencer?How to change sider icon automatically without defining custom sider,Where to modify "refine project" header?Hi, i'm using MUI inferencer, and i want to modify dashboard title, where can i modify this? so i caHow to handle image upload on create page with Node JS API?How to handle image upload on create page with Node JS API?Route from login to forgot password pagehello i'm trying to create a forgot password page from the login but it's not routing from the logCan I set antd useForms's redirect property to a show page from another resource?Can I set antd useForms's redirect property to a show page from another resource?How to autosave?I'd like to create a form that autosaves the changed content to my data provider. How do I best achiHow can I get the resource id that I just created?As the picture, I want to update `receiptId` in `debit_notes` after I create a new receipt But I donuseDataGrid and crudFiltersI am using useDataGrid, and I want to implement the crudFilters in my app, the same way as the fineFGo to a specific step when using antd's useStepsFormWhen using antd's useStepsForm in the edit page of a resource, is it possible to go to a specific stTyping the `custom` method in DataProviderHello, I am trying to type the response data from my `custom` method in the DataProvider, which usesClearing up usage/purpose of `custom` method parameters.Hey. For the `custom` method in a data provider, what is the difference between query, payload, andHelp 2 find Medusa dashboard or UI Panel (Refine Store Example)Hi, I just installed the Store Example (https://github.com/refinedev/refine/tree/master/examples/stoHow to use List CRUD component after swizzle?I am attempting to customize the interface of a Refine-Material UI app. I used the swizzle command tDeployment to Vercel 404 not found when pasting URLMaybe one of you ran into the same issue i am clueless on this one. I deployed my refine project for