This commit is contained in:
Stefan Pejcic
2024-11-07 19:03:37 +01:00
parent c6df945ed5
commit 09f9f9502d
2472 changed files with 620417 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import nock from "nock";
nock("https://api.nestjs-query.refine.dev:443", { encodedQueryParams: true })
.post("/graphql", {
operationName: "CreateBlogPost",
query:
"mutation CreateBlogPost($input: CreateOneBlogPostInput!) {\n createOneBlogPost(input: $input) {\n id\n title\n content\n status\n }\n}",
variables: {
input: {
blogPost: {
categoryId: 1,
content: "bar",
status: "DRAFT",
title: "foo",
},
},
},
})
.reply(
200,
{
data: {
createOneBlogPost: {
id: "507",
title: "foo",
content: "bar",
status: "DRAFT",
},
},
},
{
"access-control-allow-origin": "*",
"cache-control": "no-store",
connection: "keep-alive",
"content-length": "91",
"content-type": "application/graphql-response+json; charset=utf-8",
date: "Thu, 26 Sep 2024 11:54:40 GMT",
etag: 'W/"5b-jJ/FnAK4aEJwavpg5viT6Qcb+ZM"',
"strict-transport-security": "max-age=15724800; includeSubDomains",
"x-powered-by": "Express",
},
);

View File

@@ -0,0 +1,45 @@
import { gql } from "@urql/core";
import dataProvider from "../../src/index";
import client from "../gqlClient";
import "./create.mock";
const gqlMutation = gql`
mutation CreateBlogPost($input: CreateOneBlogPostInput!) {
createOneBlogPost(input: $input) {
id
title
content
status
}
}
`;
describe("create", () => {
describe("with correct params", () => {
it("works as expected", async () => {
const { data } = await dataProvider(client).create({
resource: "blogPosts",
variables: {
title: "foo",
content: "bar",
status: "DRAFT",
categoryId: 1,
},
meta: {
gqlMutation,
},
});
expect(data.title).toEqual("foo");
expect(data.content).toEqual("bar");
});
});
describe("without operation", () => {
it("throws error", async () => {
expect(
dataProvider(client).create({ resource: "blogPosts", variables: {} }),
).rejects.toEqual(new Error("Operation is required."));
});
});
});