2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-09-21 19:38:15 +02:00
|
|
|
const { omit, prop } = require('lodash/fp');
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
// Helpers.
|
2023-04-05 10:32:20 +02:00
|
|
|
const { createTestBuilder } = require('api-tests/builder');
|
|
|
|
const { createStrapiInstance } = require('api-tests/strapi');
|
|
|
|
const { createAuthRequest } = require('api-tests/request');
|
2019-03-25 16:37:46 +01:00
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
const builder = createTestBuilder();
|
|
|
|
let strapi;
|
2019-03-25 16:37:46 +01:00
|
|
|
let rq;
|
|
|
|
let graphqlQuery;
|
|
|
|
|
|
|
|
const postModel = {
|
2019-11-14 16:37:57 +01:00
|
|
|
attributes: {
|
|
|
|
name: {
|
|
|
|
type: 'richtext',
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
2019-11-14 16:37:57 +01:00
|
|
|
bigint: {
|
|
|
|
type: 'biginteger',
|
2019-04-05 07:45:56 -07:00
|
|
|
},
|
2019-11-14 16:37:57 +01:00
|
|
|
nullable: {
|
|
|
|
type: 'string',
|
2019-07-04 19:10:17 -03:00
|
|
|
},
|
2021-12-02 19:55:29 +09:00
|
|
|
category: {
|
|
|
|
type: 'enumeration',
|
|
|
|
enum: ['BLOG', 'PRODUCT', 'TUTORIALS'],
|
|
|
|
},
|
2019-11-14 16:37:57 +01:00
|
|
|
},
|
2021-10-22 11:59:03 +02:00
|
|
|
singularName: 'post',
|
|
|
|
pluralName: 'posts',
|
|
|
|
displayName: 'Post',
|
2019-03-25 16:37:46 +01:00
|
|
|
description: '',
|
|
|
|
collectionName: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Test Graphql API End to End', () => {
|
|
|
|
beforeAll(async () => {
|
2020-11-17 15:38:41 +01:00
|
|
|
await builder.addContentType(postModel).build();
|
|
|
|
|
2020-11-30 20:20:36 +01:00
|
|
|
strapi = await createStrapiInstance();
|
2020-11-17 15:38:41 +01:00
|
|
|
rq = await createAuthRequest({ strapi });
|
2019-03-25 16:37:46 +01:00
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
graphqlQuery = (body) => {
|
2019-03-25 16:37:46 +01:00
|
|
|
return rq({
|
|
|
|
url: '/graphql',
|
|
|
|
method: 'POST',
|
|
|
|
body,
|
|
|
|
});
|
|
|
|
};
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2019-03-25 16:37:46 +01:00
|
|
|
|
2020-11-17 15:38:41 +01:00
|
|
|
afterAll(async () => {
|
|
|
|
await strapi.destroy();
|
|
|
|
await builder.cleanup();
|
2021-03-26 20:15:38 +01:00
|
|
|
});
|
2019-03-25 16:37:46 +01:00
|
|
|
|
|
|
|
describe('Test CRUD', () => {
|
2019-05-06 15:33:25 +02:00
|
|
|
const postsPayload = [
|
2021-12-02 19:55:29 +09:00
|
|
|
{ name: 'post 1', bigint: 1316130638171, nullable: 'value', category: 'BLOG' },
|
|
|
|
{ name: 'post 2', bigint: 1416130639261, nullable: null, category: 'PRODUCT' },
|
2019-05-06 15:33:25 +02:00
|
|
|
];
|
2022-08-08 15:50:34 +02:00
|
|
|
const data = {
|
2019-03-25 16:37:46 +01:00
|
|
|
posts: [],
|
|
|
|
};
|
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
test.each(postsPayload)('Create Post %o', async (post) => {
|
2019-03-25 16:37:46 +01:00
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
2021-09-21 19:38:15 +02:00
|
|
|
mutation createPost($data: PostInput!) {
|
|
|
|
createPost(data: $data) {
|
|
|
|
data {
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
2021-09-21 19:38:15 +02:00
|
|
|
data: post,
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body } = res;
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(body).toEqual({
|
|
|
|
data: {
|
|
|
|
createPost: {
|
2021-09-21 19:38:15 +02:00
|
|
|
data: {
|
|
|
|
attributes: post,
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('List posts', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
|
|
|
posts {
|
2021-09-21 19:38:15 +02:00
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body } = res;
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(body).toMatchObject({
|
|
|
|
data: {
|
2021-09-21 19:38:15 +02:00
|
|
|
posts: {
|
2022-08-08 23:33:39 +02:00
|
|
|
data: postsPayload.map((entry) => ({
|
2021-09-21 19:38:15 +02:00
|
|
|
id: expect.any(String),
|
|
|
|
attributes: omit('id', entry),
|
|
|
|
})),
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// assign for later use
|
2021-09-21 19:38:15 +02:00
|
|
|
data.posts = res.body.data.posts.data.map(({ id, attributes }) => ({ id, ...attributes }));
|
2019-03-25 16:37:46 +01:00
|
|
|
});
|
|
|
|
|
2024-01-08 13:14:15 +00:00
|
|
|
test('List posts with GET', async () => {
|
|
|
|
const graphqlQueryGET = (body) => {
|
|
|
|
return rq({
|
|
|
|
url: '/graphql',
|
|
|
|
method: 'GET',
|
|
|
|
qs: body,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const res = await graphqlQueryGET({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
|
|
|
posts {
|
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
|
|
|
category
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { body } = res;
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(body).toMatchObject({
|
|
|
|
data: {
|
|
|
|
posts: {
|
|
|
|
data: postsPayload.map((entry) => ({
|
|
|
|
id: expect.any(String),
|
|
|
|
attributes: omit('id', entry),
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
test('List posts with limit', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
posts(pagination: { limit: 1 }) {
|
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
2021-09-21 19:38:15 +02:00
|
|
|
const expectedPost = data.posts[0];
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
2021-09-21 19:38:15 +02:00
|
|
|
posts: {
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
id: expectedPost.id,
|
|
|
|
attributes: omit('id', expectedPost),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('List posts with sort', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
2019-03-25 18:04:48 +01:00
|
|
|
posts(sort: "name:desc") {
|
2021-09-21 19:38:15 +02:00
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
2022-08-08 23:33:39 +02:00
|
|
|
const expectedPosts = [...data.posts].reverse().map((entry) => ({
|
2021-09-21 19:38:15 +02:00
|
|
|
id: expect.any(String),
|
|
|
|
attributes: omit('id', entry),
|
|
|
|
}));
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
2021-09-21 19:38:15 +02:00
|
|
|
posts: {
|
|
|
|
data: expectedPosts,
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('List posts with start', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
posts(pagination: { start: 1 }) {
|
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
2021-09-21 19:38:15 +02:00
|
|
|
const expectedPost = data.posts[1];
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
2021-09-21 19:38:15 +02:00
|
|
|
posts: {
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
id: expectedPost.id,
|
|
|
|
attributes: omit('id', expectedPost),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-06-29 15:59:45 +02:00
|
|
|
test('Pagination counts are correct', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
|
|
|
posts(filters: { name: { eq: "post 2" } }) {
|
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
|
|
|
category
|
|
|
|
}
|
|
|
|
}
|
|
|
|
meta {
|
|
|
|
pagination {
|
|
|
|
total
|
|
|
|
pageSize
|
|
|
|
page
|
|
|
|
pageCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectedPost = data.posts[1];
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
|
|
|
posts: {
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
id: expectedPost.id,
|
|
|
|
attributes: omit('id', expectedPost),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
page: 1,
|
|
|
|
pageCount: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-22 17:04:57 +02:00
|
|
|
test.skip('List posts with `createdBy` and `updatedBy`', async () => {
|
2020-08-07 15:50:07 +02:00
|
|
|
const res = await graphqlQuery({
|
2020-08-26 10:38:54 +02:00
|
|
|
query: /* GraphQL */ `
|
|
|
|
{
|
|
|
|
posts(start: 1) {
|
2021-09-21 19:38:15 +02:00
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
2020-08-26 10:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
2020-08-07 15:50:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
|
|
|
|
// no errors should be present in the response
|
|
|
|
expect(res.body.error).toBeUndefined();
|
|
|
|
|
|
|
|
// since the posts are created without AdminUser, it should return null
|
2021-09-22 17:04:57 +02:00
|
|
|
expect(res.body.data.posts[0].createdBy).toBeNull();
|
2020-08-07 15:50:07 +02:00
|
|
|
});
|
|
|
|
|
2019-03-25 16:37:46 +01:00
|
|
|
test.each([
|
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
name: { eq: 'post 1' },
|
|
|
|
bigint: { eq: 1316130638171 },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
[postsPayload[0]],
|
|
|
|
],
|
2021-12-02 19:55:29 +09:00
|
|
|
[
|
|
|
|
{
|
|
|
|
category: { eq: 'BLOG' },
|
|
|
|
},
|
|
|
|
[postsPayload[0]],
|
|
|
|
],
|
2019-03-25 16:37:46 +01:00
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
name: { not: { eq: 'post 1' } },
|
|
|
|
bigint: { not: { eq: 1316130638171 } },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
[postsPayload[1]],
|
|
|
|
],
|
2022-07-12 16:19:51 +04:00
|
|
|
[
|
|
|
|
{
|
|
|
|
category: { eqi: 'Blog' },
|
|
|
|
},
|
|
|
|
[postsPayload[0]],
|
|
|
|
],
|
2019-03-25 16:37:46 +01:00
|
|
|
[
|
|
|
|
{
|
2021-09-28 11:11:03 +02:00
|
|
|
name: { contains: 'post' },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
postsPayload,
|
|
|
|
],
|
2021-12-02 19:55:29 +09:00
|
|
|
[
|
|
|
|
{
|
|
|
|
category: { contains: 'PRO' },
|
|
|
|
},
|
|
|
|
[postsPayload[1]],
|
|
|
|
],
|
2019-03-25 16:37:46 +01:00
|
|
|
[
|
|
|
|
{
|
2021-09-28 11:11:03 +02:00
|
|
|
name: { contains: 'post 1' },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
[postsPayload[0]],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-28 11:11:03 +02:00
|
|
|
name: { containsi: 'Post' },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
postsPayload,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-28 11:11:03 +02:00
|
|
|
name: { not: { containsi: 'Post 1' } },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
[postsPayload[1]],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
name: { in: ['post 1', 'post 2', 'post 3'] },
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
postsPayload,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
name: { not: { in: ['post 2'] } },
|
2019-07-04 19:10:17 -03:00
|
|
|
},
|
|
|
|
[postsPayload[0]],
|
|
|
|
],
|
2020-10-15 13:22:40 +02:00
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
or: [{ name: { in: ['post 2'] } }, { bigint: { eq: 1316130638171 } }],
|
2020-10-15 13:22:40 +02:00
|
|
|
},
|
|
|
|
[postsPayload[0], postsPayload[1]],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
and: [{ or: [{ name: { in: ['post 2'] } }, { bigint: { eq: 1316130638171 } }] }],
|
2020-10-15 13:22:40 +02:00
|
|
|
},
|
|
|
|
[postsPayload[0], postsPayload[1]],
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
and: [
|
2020-10-15 13:22:40 +02:00
|
|
|
{
|
2021-09-21 19:38:15 +02:00
|
|
|
or: [
|
|
|
|
{ name: { in: ['post 2'] } },
|
|
|
|
{ or: [{ bigint: { eq: 1316130638171 } }, { nullable: { not: { null: true } } }] },
|
2020-10-15 13:22:40 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
[postsPayload[0], postsPayload[1]],
|
|
|
|
],
|
2021-09-21 19:38:15 +02:00
|
|
|
])('List posts with filters clause %o', async (filters, expected) => {
|
2019-03-25 16:37:46 +01:00
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
2021-09-21 19:38:15 +02:00
|
|
|
query findPosts($filters: PostFiltersInput) {
|
|
|
|
posts(filters: $filters) {
|
|
|
|
data {
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
2021-09-21 19:38:15 +02:00
|
|
|
filters,
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
2019-05-13 13:59:41 +02:00
|
|
|
|
2021-09-21 19:38:15 +02:00
|
|
|
const { data: posts } = res.body.data.posts;
|
|
|
|
|
2019-05-13 13:59:41 +02:00
|
|
|
// same length
|
2021-09-21 19:38:15 +02:00
|
|
|
expect(posts.length).toBe(expected.length);
|
2019-05-13 13:59:41 +02:00
|
|
|
|
|
|
|
// all the posts returned are in the expected array
|
2022-08-08 23:33:39 +02:00
|
|
|
posts.map(prop('attributes')).forEach((post) => {
|
2021-09-21 19:38:15 +02:00
|
|
|
expect(expected.map(omit('id'))).toEqual(expect.arrayContaining([post]));
|
2019-05-13 13:59:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// all expected values are in the result
|
2022-08-08 23:33:39 +02:00
|
|
|
expected.forEach((expectedPost) => {
|
2021-09-21 19:38:15 +02:00
|
|
|
expect(posts.map(prop('attributes'))).toEqual(
|
|
|
|
expect.arrayContaining([omit('id', expectedPost)])
|
|
|
|
);
|
2019-03-25 16:37:46 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Get One Post', async () => {
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
|
|
|
query getPost($id: ID!) {
|
|
|
|
post(id: $id) {
|
2021-09-21 19:38:15 +02:00
|
|
|
data {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
bigint
|
|
|
|
nullable
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
|
|
|
id: data.posts[0].id,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
2021-09-21 19:38:15 +02:00
|
|
|
post: {
|
|
|
|
data: {
|
|
|
|
id: data.posts[0].id,
|
|
|
|
attributes: omit('id', data.posts[0]),
|
|
|
|
},
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Update Post', async () => {
|
|
|
|
const newName = 'new post name';
|
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
2021-09-21 19:38:15 +02:00
|
|
|
mutation updatePost($id: ID!, $data: PostInput!) {
|
|
|
|
updatePost(id: $id, data: $data) {
|
|
|
|
data {
|
2019-03-25 16:37:46 +01:00
|
|
|
id
|
2021-09-21 19:38:15 +02:00
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
2021-09-21 19:38:15 +02:00
|
|
|
id: data.posts[0].id,
|
|
|
|
data: {
|
|
|
|
name: newName,
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
|
|
expect(res.body).toEqual({
|
|
|
|
data: {
|
|
|
|
updatePost: {
|
2021-09-21 19:38:15 +02:00
|
|
|
data: {
|
2019-03-25 16:37:46 +01:00
|
|
|
id: data.posts[0].id,
|
2021-09-21 19:38:15 +02:00
|
|
|
attributes: {
|
|
|
|
name: newName,
|
|
|
|
},
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-21 19:38:15 +02:00
|
|
|
const newPost = res.body.data.updatePost.data;
|
|
|
|
|
|
|
|
data.posts[0] = {
|
|
|
|
id: newPost.id,
|
|
|
|
...newPost.attributes,
|
|
|
|
};
|
2019-03-25 16:37:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Delete Posts', async () => {
|
2022-08-08 15:50:34 +02:00
|
|
|
for (const post of data.posts) {
|
2019-03-25 16:37:46 +01:00
|
|
|
const res = await graphqlQuery({
|
|
|
|
query: /* GraphQL */ `
|
2021-09-21 19:38:15 +02:00
|
|
|
mutation deletePost($id: ID!) {
|
|
|
|
deletePost(id: $id) {
|
|
|
|
data {
|
2019-08-23 14:15:24 +02:00
|
|
|
id
|
2021-09-21 19:38:15 +02:00
|
|
|
attributes {
|
|
|
|
name
|
|
|
|
nullable
|
|
|
|
bigint
|
2021-12-02 19:55:29 +09:00
|
|
|
category
|
2021-09-21 19:38:15 +02:00
|
|
|
}
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
variables: {
|
2021-09-21 19:38:15 +02:00
|
|
|
id: post.id,
|
2019-03-25 16:37:46 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(res.statusCode).toBe(200);
|
2019-08-23 14:15:24 +02:00
|
|
|
expect(res.body).toMatchObject({
|
|
|
|
data: {
|
|
|
|
deletePost: {
|
2021-09-21 19:38:15 +02:00
|
|
|
data: {
|
2019-08-23 14:15:24 +02:00
|
|
|
id: post.id,
|
2021-09-21 19:38:15 +02:00
|
|
|
attributes: omit('id', post),
|
2019-08-23 14:15:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2019-03-25 16:37:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|