mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
packages
This commit is contained in:
42
packages/graphql/test/create/create.mock.ts
Normal file
42
packages/graphql/test/create/create.mock.ts
Normal 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",
|
||||
},
|
||||
);
|
||||
45
packages/graphql/test/create/create.spec.ts
Normal file
45
packages/graphql/test/create/create.spec.ts
Normal 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."));
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user