mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
fork refine
This commit is contained in:
76
packages/graphql/test/create/index.mock.ts
Normal file
76
packages/graphql/test/create/index.mock.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import nock from "nock";
|
||||
|
||||
nock("https://api.strapi.refine.dev:443", { encodedQueryParams: true })
|
||||
.post("/graphql", {
|
||||
query: "mutation ($input: createPostInput) {\n createPost (input: $input) {\n post { id, title, content, category { id } }\n }\n }",
|
||||
variables: {
|
||||
input: { data: { title: "foo", content: "bar", category: "2" } },
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{
|
||||
data: {
|
||||
createPost: {
|
||||
post: {
|
||||
id: "43",
|
||||
title: "foo",
|
||||
content: "bar",
|
||||
category: { id: "2" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
[
|
||||
"Server",
|
||||
"nginx/1.17.10",
|
||||
"Date",
|
||||
"Thu, 16 Sep 2021 13:28:08 GMT",
|
||||
"Content-Type",
|
||||
"application/json",
|
||||
"Content-Length",
|
||||
"97",
|
||||
"Connection",
|
||||
"close",
|
||||
"Vary",
|
||||
"Origin",
|
||||
"Strict-Transport-Security",
|
||||
"max-age=31536000; includeSubDomains",
|
||||
"X-Frame-Options",
|
||||
"SAMEORIGIN",
|
||||
"X-Powered-By",
|
||||
"Strapi <strapi.io>",
|
||||
"X-Response-Time",
|
||||
"39ms",
|
||||
],
|
||||
);
|
||||
|
||||
nock("https://api.strapi.refine.dev:443", { encodedQueryParams: true })
|
||||
.post("/graphql", {
|
||||
query: "mutation ($input: createPostInput) {\n createPost (input: $input) {\n post { id }\n }\n }",
|
||||
variables: {
|
||||
input: { data: { title: "foo", content: "bar", category: "2" } },
|
||||
},
|
||||
})
|
||||
.reply(200, { data: { createPost: { post: { id: "44" } } } }, [
|
||||
"Server",
|
||||
"nginx/1.17.10",
|
||||
"Date",
|
||||
"Thu, 16 Sep 2021 13:30:33 GMT",
|
||||
"Content-Type",
|
||||
"application/json",
|
||||
"Content-Length",
|
||||
"45",
|
||||
"Connection",
|
||||
"close",
|
||||
"Vary",
|
||||
"Origin",
|
||||
"Strict-Transport-Security",
|
||||
"max-age=31536000; includeSubDomains",
|
||||
"X-Frame-Options",
|
||||
"SAMEORIGIN",
|
||||
"X-Powered-By",
|
||||
"Strapi <strapi.io>",
|
||||
"X-Response-Time",
|
||||
"295ms",
|
||||
]);
|
||||
48
packages/graphql/test/create/index.spec.ts
Normal file
48
packages/graphql/test/create/index.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import dataProvider from "../../src/index";
|
||||
import client from "../gqlClient";
|
||||
import "./index.mock";
|
||||
|
||||
describe("create", () => {
|
||||
it("correct response with meta", async () => {
|
||||
const { data } = await dataProvider(client).create({
|
||||
resource: "posts",
|
||||
variables: {
|
||||
title: "foo",
|
||||
content: "bar",
|
||||
category: "2",
|
||||
},
|
||||
meta: {
|
||||
fields: [
|
||||
{
|
||||
operation: "post",
|
||||
fields: [
|
||||
"id",
|
||||
"title",
|
||||
"content",
|
||||
{ category: ["id"] },
|
||||
],
|
||||
variables: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(data["id"]).toEqual("43");
|
||||
expect(data["title"]).toEqual("foo");
|
||||
expect(data["content"]).toEqual("bar");
|
||||
expect(data["category"].id).toEqual("2");
|
||||
});
|
||||
|
||||
it("correct response without meta", async () => {
|
||||
const { data } = await dataProvider(client).create({
|
||||
resource: "posts",
|
||||
variables: {
|
||||
title: "foo",
|
||||
content: "bar",
|
||||
category: "2",
|
||||
},
|
||||
});
|
||||
|
||||
expect(data["id"]).toEqual("44");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user