diff --git a/backend/src/jest/helpers.js b/backend/src/jest/helpers.js index e50f30c64..380aedd16 100644 --- a/backend/src/jest/helpers.js +++ b/backend/src/jest/helpers.js @@ -15,3 +15,9 @@ export async function login(variables) { authorization: `Bearer ${response.login}`, } } + +//* This is a fake ES2015 template string, just to benefit of syntax +// highlighting of `gql` template strings in certain editors. +export function gql(strings) { + return strings.join('') +} diff --git a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js index e4292bb8f..f2e3c2303 100644 --- a/backend/src/middleware/handleHtmlContent/handleContentData.spec.js +++ b/backend/src/middleware/handleHtmlContent/handleContentData.spec.js @@ -1,5 +1,5 @@ import { GraphQLClient } from 'graphql-request' -import { host, login } from '../../jest/helpers' +import { host, login, gql } from '../../jest/helpers' import Factory from '../../seed/factories' const factory = Factory() @@ -20,7 +20,7 @@ afterEach(async () => { }) describe('currentUser { notifications }', () => { - const query = ` + const query = gql` query($read: Boolean) { currentUser { notifications(read: $read, orderBy: createdAt_desc) { @@ -67,7 +67,7 @@ describe('currentUser { notifications }', () => { 'Hey @al-capone how do you do?' beforeEach(async () => { - const createPostMutation = ` + const createPostMutation = gql` mutation($title: String!, $content: String!) { CreatePost(title: $title, content: $content) { id @@ -116,7 +116,7 @@ describe('currentUser { notifications }', () => { // during development and thought: A feature not a bug! This way we // can encode a re-mentioning of users when you edit your post or // comment. - const updatePostMutation = ` + const updatePostMutation = gql` mutation($id: ID!, $title: String!, $content: String!) { UpdatePost(id: $id, content: $content, title: $title) { title @@ -172,7 +172,7 @@ describe('Hashtags', () => { const postTitle = 'Two Hashtags' const postContent = '

Hey Dude, #Democracy should work equal for everybody!? That seems to be the only way to have equal #Liberty for everyone.

' - const postWithHastagsQuery = ` + const postWithHastagsQuery = gql` query($id: ID) { Post(id: $id) { tags { @@ -185,7 +185,7 @@ describe('Hashtags', () => { const postWithHastagsVariables = { id: postId, } - const createPostMutation = ` + const createPostMutation = gql` mutation($postId: ID, $postTitle: String!, $postContent: String!) { CreatePost(id: $postId, title: $postTitle, content: $postContent) { id @@ -242,7 +242,7 @@ describe('Hashtags', () => { // The already existing Hashtag has no class at this point. const updatedPostContent = '

Hey Dude, #Elections should work equal for everybody!? That seems to be the only way to have equal #Liberty for everyone.

' - const updatePostMutation = ` + const updatePostMutation = gql` mutation($postId: ID!, $postTitle: String!, $updatedPostContent: String!) { UpdatePost(id: $postId, title: $postTitle, content: $updatedPostContent) { id diff --git a/backend/src/schema/resolvers/comments.spec.js b/backend/src/schema/resolvers/comments.spec.js index 5b2da7781..a12e2dfcc 100644 --- a/backend/src/schema/resolvers/comments.spec.js +++ b/backend/src/schema/resolvers/comments.spec.js @@ -1,6 +1,6 @@ import { GraphQLClient } from 'graphql-request' import Factory from '../../seed/factories' -import { host, login } from '../../jest/helpers' +import { host, login, gql } from '../../jest/helpers' const factory = Factory() let client @@ -25,7 +25,7 @@ afterEach(async () => { }) describe('CreateComment', () => { - const createCommentMutation = ` + const createCommentMutation = gql` mutation($postId: ID!, $content: String!) { CreateComment(postId: $postId, content: $content) { id @@ -33,7 +33,7 @@ describe('CreateComment', () => { } } ` - const createPostMutation = ` + const createPostMutation = gql` mutation($id: ID!, $title: String!, $content: String!) { CreatePost(id: $id, title: $title, content: $content) { id @@ -87,7 +87,7 @@ describe('CreateComment', () => { it('assigns the authenticated user as author', async () => { await client.request(createCommentMutation, createCommentVariables) - const { User } = await client.request(` + const { User } = await client.request(gql` { User(name: "TestUser") { comments { @@ -188,7 +188,7 @@ describe('CreateComment', () => { }) describe('DeleteComment', () => { - const deleteCommentMutation = ` + const deleteCommentMutation = gql` mutation($id: ID!) { DeleteComment(id: $id) { id diff --git a/backend/src/schema/resolvers/rewards.spec.js b/backend/src/schema/resolvers/rewards.spec.js index 7ea8d7e7b..3b94e93aa 100644 --- a/backend/src/schema/resolvers/rewards.spec.js +++ b/backend/src/schema/resolvers/rewards.spec.js @@ -1,6 +1,6 @@ import { GraphQLClient } from 'graphql-request' import Factory from '../../seed/factories' -import { host, login } from '../../jest/helpers' +import { host, login, gql } from '../../jest/helpers' const factory = Factory() let user @@ -42,7 +42,7 @@ describe('rewards', () => { }) describe('reward', () => { - const mutation = ` + const mutation = gql` mutation($from: ID!, $to: ID!) { reward(badgeKey: $from, userId: $to) { id @@ -141,7 +141,7 @@ describe('rewards', () => { await client.request(mutation, variables) await client.request(mutation, variables) - const query = ` + const query = gql` { User(id: "u1") { badgesCount @@ -178,7 +178,7 @@ describe('rewards', () => { }) const expected = { unreward: { id: 'u1', badges: [] } } - const mutation = ` + const mutation = gql` mutation($from: ID!, $to: ID!) { unreward(badgeKey: $from, userId: $to) { id @@ -191,7 +191,7 @@ describe('rewards', () => { describe('check test setup', () => { it('user has one badge', async () => { - const query = ` + const query = gql` { User(id: "u1") { badgesCount diff --git a/backend/src/schema/resolvers/socialMedia.spec.js b/backend/src/schema/resolvers/socialMedia.spec.js index f65552e5c..7ec35a08f 100644 --- a/backend/src/schema/resolvers/socialMedia.spec.js +++ b/backend/src/schema/resolvers/socialMedia.spec.js @@ -1,13 +1,13 @@ import { GraphQLClient } from 'graphql-request' import Factory from '../../seed/factories' -import { host, login } from '../../jest/helpers' +import { host, login, gql } from '../../jest/helpers' const factory = Factory() describe('SocialMedia', () => { let client let headers - const mutationC = ` + const mutationC = gql` mutation($url: String!) { CreateSocialMedia(url: $url) { id @@ -15,7 +15,7 @@ describe('SocialMedia', () => { } } ` - const mutationD = ` + const mutationD = gql` mutation($id: ID!) { DeleteSocialMedia(id: $id) { id diff --git a/backend/src/schema/resolvers/users.spec.js b/backend/src/schema/resolvers/users.spec.js index 022f836cd..fff6acadb 100644 --- a/backend/src/schema/resolvers/users.spec.js +++ b/backend/src/schema/resolvers/users.spec.js @@ -1,6 +1,6 @@ import { GraphQLClient } from 'graphql-request' -import { login, host } from '../../jest/helpers' import Factory from '../../seed/factories' +import { host, login, gql } from '../../jest/helpers' const factory = Factory() let client @@ -130,7 +130,7 @@ describe('users', () => { describe('DeleteUser', () => { let deleteUserVariables let asAuthor - const deleteUserMutation = ` + const deleteUserMutation = gql` mutation($id: ID!, $resource: [Deletable]) { DeleteUser(id: $id, resource: $resource) { id