diff --git a/api-tests/plugins/graphql/crud.test.api.js b/api-tests/plugins/graphql/crud.test.api.js index 13c85de3c1..483506097d 100644 --- a/api-tests/plugins/graphql/crud.test.api.js +++ b/api-tests/plugins/graphql/crud.test.api.js @@ -137,6 +137,48 @@ describe('Test Graphql API End to End', () => { data.posts = res.body.data.posts.data.map(({ id, attributes }) => ({ id, ...attributes })); }); + 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), + })), + }, + }, + }); + }); + test('List posts with limit', async () => { const res = await graphqlQuery({ query: /* GraphQL */ ` diff --git a/api-tests/plugins/graphql/utils.test.api.js b/api-tests/plugins/graphql/utils.test.api.js new file mode 100644 index 0000000000..f7e805a9d0 --- /dev/null +++ b/api-tests/plugins/graphql/utils.test.api.js @@ -0,0 +1,25 @@ +'use strict'; + +// Helpers. +const { createStrapiInstance } = require('api-tests/strapi'); +const request = require('supertest'); + +let strapi; + +describe('Test Graphql Utils', () => { + beforeAll(async () => { + strapi = await createStrapiInstance(); + }); + + afterAll(async () => { + await strapi.destroy(); + }); + + test('Load Graphql playground', async () => { + const supertestAgent = request.agent(strapi.server.httpServer); + const res = await supertestAgent.get('/graphql').set('accept', 'text/html'); + + expect(res.statusCode).toBe(200); + expect(res.text).toContain('