From e83ebb73a068ee6a2c259ef3ad27e32f7c8eb346 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Mon, 26 Sep 2022 16:20:50 +0200 Subject: [PATCH] Make intercept work with mocks --- client/cypress/support/commands.js | 72 ++++++++++-------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index e3381e7a..0563c647 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -27,7 +27,7 @@ // https://github.com/tgriesser/cypress-graphql-mock/issues/23 // todo: once above issue is fixed, go back to the original repo -> npm install cypress-graphql-mock // import 'cypress-graphql-mock'; -// import mocks from '../fixtures/mocks'; +import mocks from '../fixtures/mocks'; import {makeExecutableSchema} from '@graphql-tools/schema'; import {addMocksToSchema} from '@graphql-tools/mock'; @@ -144,54 +144,28 @@ Cypress.Commands.add('openSidebar', () => { Cypress.Commands.add('setup', () => { cy.fakeLogin('nino.teacher', 'test'); cy.viewport('macbook-15'); - // cy.task('getSchema').then(schemaString => { - const schemaString = ` - schema { - query: Query - } - - type Query { - me: PrivateUserNode - } - - - interface Node { - id: ID! - } + cy.task('getSchema').then(schemaString => { + const schema = makeExecutableSchema({typeDefs: schemaString}); + const schemaWithMocks = addMocksToSchema({schema, mocks}); - type PrivateUserNode implements Node { - firstName: String! - lastName: String! - avatarUrl: String! - } - `; - const schema = makeExecutableSchema({typeDefs: schemaString}); - const schemaWithMocks = addMocksToSchema({schema}); - - // cy.intercept('POST', '/api/graphql', (req) => { - const query = ` - query MeQuery { - me { - firstName - lastName - avatarUrl - } - } - `; - // const {query, variables} = req.body; - // console.log(query, variables); - graphql({ - schema: schemaWithMocks, - source: query, - }).then(result => { - console.log(result); - // req.reply({ - // data: {}, - // }); - }, e => { - console.log(e.message); - console.error(e); + cy.intercept('POST', '/api/graphql', (req) => { + const {query, variables} = req.body; + console.log(query, variables); + graphql({ + schema: schemaWithMocks, + source: query, + variableValues: variables, + }).then(result => { + console.log('result'); + console.log(result); + req.reply({ + ...result, + }); + }, e => { + console.log('error message'); + console.log(e.message); + console.error(e); + }); }); - // }); - // }); + }); });