first graphql collection tests

This commit is contained in:
Dan Ribbens
2020-07-12 13:11:28 -04:00
parent b12538b6ff
commit 573304ea3e
3 changed files with 74 additions and 0 deletions

View File

@@ -120,6 +120,7 @@
"eslint-plugin-react-hooks": "^2.3.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"faker": "^4.1.0",
"graphql-request": "^2.0.0",
"node-sass": "^4.13.1",
"node-sass-chokidar": "^1.4.0",
"nodemon": "^1.19.4",

View File

@@ -0,0 +1,68 @@
/**
* @jest-environment node
*/
const fetch = require('isomorphic-fetch');
const { request, GraphQLClient } = require('graphql-request');
const faker = require('faker');
const config = require('../../../../demo/payload.config');
const { email, password } = require('../../../tests/credentials');
const url = `${config.serverURL}${config.routes.api}${config.routes.graphQL}`;
let client = null;
let token = null;
let localizedPostID;
// const englishPostDesc = faker.lorem.lines(2);
// const spanishPostDesc = faker.lorem.lines(2);
describe('GrahpQL Resolvers', () => {
beforeAll(async (done) => {
// language=GraphQL
const query = `
mutation {
loginAdmin(
email: "${email}",
password: "${password}"
)
}`;
const response = await request(url, query);
token = response.loginAdmin;
client = new GraphQLClient(url, { headers: { Authorization: `JWT ${token}` } });
done();
});
describe('Create', () => {
it('should allow a localized post to be created', async () => {
const title = faker.lorem.words(1);
const description = faker.lorem.words(1);
const query = `mutation {
createLocalizedPost(data: {title: "${title}", description: "${description}", priority: 10}) {
title
description
priority
createdAt
updatedAt
}
}`;
const response = await client.request(query);
const data = response.createLocalizedPost;
expect(data.title).toBe(title);
expect(data.id).not.toBeNull();
const timestampRegex = /^(\d{4})(?:-?W(\d+)(?:-?(\d+)D?)?|(?:-(\d+))?-(\d+))(?:[T ](\d+):(\d+)(?::(\d+)(?:\.(\d+))?)?)?(?:Z(-?\d*))?$/;
expect(data.doc.createdAt).toStrictEqual(expect.stringMatching(timestampRegex));
expect(data.doc.updatedAt).toStrictEqual(expect.stringMatching(timestampRegex));
localizedPostID = data.id;
});
});
});

View File

@@ -5183,6 +5183,11 @@ graphql-playground-middleware-express@^1.7.14:
dependencies:
graphql-playground-html "1.6.25"
graphql-request@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-2.0.0.tgz#8dd12cf1eb2ce0c80f4114fd851741e091134862"
integrity sha512-Ww3Ax+G3l2d+mPT8w7HC9LfrKjutnCKtnDq7ZZp2ghVk5IQDjwAk3/arRF1ix17Ky15rm0hrSKVKxRhIVlSuoQ==
graphql-type-json@^0.3.1:
version "0.3.2"
resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.2.tgz#f53a851dbfe07bd1c8157d24150064baab41e115"