mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
71 lines
1.6 KiB
TypeScript
71 lines
1.6 KiB
TypeScript
import gql from "graphql-tag";
|
|
import dataProvider from "../../src/index";
|
|
import client from "../gqlClient";
|
|
import "./update.mock";
|
|
|
|
const gqlMutation = gql`
|
|
mutation UpdateOneBlogPost($input: UpdateOneBlogPostInput!) {
|
|
updateOneBlogPost(input: $input) {
|
|
id
|
|
title
|
|
content
|
|
status
|
|
category {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
describe("update", () => {
|
|
describe("with correct params", () => {
|
|
describe("with gqlMutation", () => {
|
|
it("works as expected", async () => {
|
|
const { data } = await dataProvider(client).update({
|
|
resource: "blogPosts",
|
|
id: "113",
|
|
variables: {
|
|
title: "Updated Title",
|
|
},
|
|
meta: {
|
|
gqlMutation,
|
|
},
|
|
});
|
|
|
|
expect(data.id).toEqual("113");
|
|
expect(data.title).toEqual("Updated Title");
|
|
});
|
|
});
|
|
|
|
describe("with gqlQuery", () => {
|
|
it("works as expected", async () => {
|
|
const { data } = await dataProvider(client).update({
|
|
resource: "blogPosts",
|
|
id: "113",
|
|
variables: {
|
|
title: "Updated Title 3",
|
|
},
|
|
meta: {
|
|
gqlQuery: gqlMutation,
|
|
},
|
|
});
|
|
|
|
expect(data.id).toEqual("113");
|
|
expect(data.title).toEqual("Updated Title 3");
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("without operation", () => {
|
|
it("throws error", async () => {
|
|
expect(
|
|
dataProvider(client).update({
|
|
resource: "blogPosts",
|
|
id: 113,
|
|
variables: {},
|
|
}),
|
|
).rejects.toEqual(new Error("Operation is required."));
|
|
});
|
|
});
|
|
});
|