From 2e19cf6592d546ffa1ce31ed40da80a5f554a9b4 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Mon, 17 Feb 2020 22:54:19 +0100 Subject: [PATCH 1/3] fix(nuxt-env): Configuration issue with websockets After some intensive debugging I found out that `req` (on the server) and `nuxtState` (on the client) have access to the configurations changed at runtime. How did I debug it: ``` yarn run build env WEBSOCKET_URI=whatever yarn run start ``` I also put a `console.log` into `plugins/apollo-client.js`. --- webapp/.env.template | 2 ++ webapp/nuxt.config.js | 8 +++++++- webapp/plugins/apollo-config.js | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/webapp/.env.template b/webapp/.env.template index fdabcf003..b00e6855a 100644 --- a/webapp/.env.template +++ b/webapp/.env.template @@ -2,3 +2,5 @@ MAPBOX_TOKEN="pk.eyJ1IjoiaHVtYW4tY29ubmVjdGlvbiIsImEiOiJjajl0cnBubGoweTVlM3VwZ2l SENTRY_DSN_WEBAPP= COMMIT= PUBLIC_REGISTRATION=false +WEBSOCKETS_URI=ws://localhost:3000/api/graphql +GRAPHQL_URI=http://localhost:4000/ diff --git a/webapp/nuxt.config.js b/webapp/nuxt.config.js index c1283a9be..2ef42f139 100644 --- a/webapp/nuxt.config.js +++ b/webapp/nuxt.config.js @@ -4,7 +4,13 @@ import dotenv from 'dotenv' dotenv.config() // we want to synchronize @nuxt-dotenv and nuxt-env const pkg = require('./package') -export const envWhitelist = ['NODE_ENV', 'MAPBOX_TOKEN', 'PUBLIC_REGISTRATION'] +export const envWhitelist = [ + 'NODE_ENV', + 'MAPBOX_TOKEN', + 'PUBLIC_REGISTRATION', + 'WEBSOCKETS_URI', + 'GRAPHQL_URI', +] const dev = process.env.NODE_ENV !== 'production' const styleguidePath = '../styleguide' diff --git a/webapp/plugins/apollo-config.js b/webapp/plugins/apollo-config.js index b89d9a188..63282a341 100644 --- a/webapp/plugins/apollo-config.js +++ b/webapp/plugins/apollo-config.js @@ -5,11 +5,12 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({ introspectionQueryResultData, }) -export default ({ app }) => { - const backendUrl = process.env.GRAPHQL_URI || 'http://localhost:4000' +export default ({ req, nuxtState }) => { + const { env } = req || nuxtState + const backendUrl = env.GRAPHQL_URI || 'http://localhost:4000' return { - wsEndpoint: process.env.WEBSOCKETS_URI || 'ws://localhost:4000/graphql', + wsEndpoint: env.WEBSOCKETS_URI || 'ws://localhost:4000/graphql', httpEndpoint: process.server ? backendUrl : '/api', httpLinkOptions: { credentials: 'same-origin', From 2ca4939ef045d8092beb43d40252a3415fae8996 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Mon, 17 Feb 2020 20:15:51 +0100 Subject: [PATCH 2/3] Refactor: Don't use async/await in cypress --- cypress/integration/common/report.js | 8 +++--- cypress/integration/common/steps.js | 40 +++++++++++++++++----------- cypress/support/commands.js | 31 ++++++++++++--------- cypress/support/factories.js | 15 +++++------ 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/cypress/integration/common/report.js b/cypress/integration/common/report.js index cc424ef3e..f209ceef7 100644 --- a/cypress/integration/common/report.js +++ b/cypress/integration/common/report.js @@ -42,10 +42,12 @@ Given('I am logged in with a {string} role', role => { .first("User", { name: `${role} is my name`, }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) }) When('I click on "Report Post" from the content menu of the post', () => { diff --git a/cypress/integration/common/steps.js b/cypress/integration/common/steps.js index 73de67480..a4bdb6475 100644 --- a/cypress/integration/common/steps.js +++ b/cypress/integration/common/steps.js @@ -39,10 +39,12 @@ Given("I am logged in", () => { .first("User", { name: narratorParams.name }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) }); Given("I log in as {string}", name => { @@ -50,10 +52,12 @@ Given("I log in as {string}", name => { .first("User", { name }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) }) Given("the {string} user searches for {string}", (_, postTitle) => { @@ -62,10 +66,12 @@ Given("the {string} user searches for {string}", (_, postTitle) => { .first("User", { id: "annoying-user" }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) cy.get(".searchable-input .ds-select-search") .focus() .type(postTitle); @@ -142,10 +148,12 @@ When("a blocked user visits the post page of one of my authored posts", () => { .first("User", { name: 'Harassing User' }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) cy.openPage('post/previously-created-post') }) @@ -349,10 +357,12 @@ Given("I am logged in with these credentials:", table => { .first("User", { name: loginCredentials.email, }) - .then(async user => { - const userJson = await user.toJson() - cy.login(userJson) + .then(user => { + return new Cypress.Promise((resolve, reject) => { + return user.toJson().then((user) => resolve(user)) + }) }) + .then(user => cy.login(user)) }); When("I fill the password form with:", table => { diff --git a/cypress/support/commands.js b/cypress/support/commands.js index f3035dcdd..75f27d0f7 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -25,14 +25,17 @@ const switchLang = name => { cy.contains(".locale-menu-popover a", name).click(); }; -const authenticatedHeaders = async (variables) => { +const authenticatedHeaders = (variables) => { const mutation = gql` mutation($email: String!, $password: String!) { login(email: $email, password: $password) } ` - const response = await request(config.GRAPHQL_URI, mutation, variables) - return { authorization: `Bearer ${response.login}` } + return new Cypress.Promise((resolve, reject) => { + request(config.GRAPHQL_URI, mutation, variables).then((response) => { + resolve({ authorization: `Bearer ${response.login}` }) + }) + }) } Cypress.Commands.add("switchLanguage", (name, force) => { @@ -81,20 +84,22 @@ Cypress.Commands.add("openPage", page => { Cypress.Commands.add( 'authenticateAs', - async ({email, password}) => { - const headers = await authenticatedHeaders({ email, password }) - return new GraphQLClient(config.GRAPHQL_URI, { headers }) - } -) + ({email, password}) => { + return new Cypress.Promise((resolve, reject) => { + authenticatedHeaders({ email, password }).then((headers) => { + resolve(new GraphQLClient(config.GRAPHQL_URI, { headers })) + }) + }) + }) Cypress.Commands.add( 'mutate', { prevSubject: true }, - async (graphQLClient, mutation, variables) => { - await graphQLClient.request(mutation, variables) - return graphQLClient - } -) + (graphQLClient, mutation, variables) => { + return new Cypress.Promise((resolve, reject) => { + graphQLClient.request(mutation, variables).then(() => resolve(graphQLClient)) + }) + }) // // diff --git a/cypress/support/factories.js b/cypress/support/factories.js index bee0d8542..d2a8d87ad 100644 --- a/cypress/support/factories.js +++ b/cypress/support/factories.js @@ -8,9 +8,7 @@ const neo4jConfigs = { } const neodeInstance = getNeode(neo4jConfigs) -beforeEach(async () => { - await cleanDatabase() -}) +beforeEach(() => cleanDatabase()) Cypress.Commands.add('neode', () => { return neodeInstance @@ -19,14 +17,14 @@ Cypress.Commands.add('neode', () => { Cypress.Commands.add( 'first', { prevSubject: true }, - async (neode, model, properties) => { + (neode, model, properties) => { return neode.first(model, properties) } ) Cypress.Commands.add( 'relateTo', { prevSubject: true }, - async (node, otherNode, relationship) => { + (node, otherNode, relationship) => { return node.relateTo(otherNode, relationship) } ) @@ -36,9 +34,10 @@ Cypress.Commands.add('factory', () => Factory) Cypress.Commands.add( 'build', { prevSubject: true }, - async (factory, name, atrributes, options) => { - await factory.build(name, atrributes, options) - return factory + (factory, name, atrributes, options) => { + return new Cypress.Promise((resolve, reject) => { + return factory.build(name, atrributes, options).then(() => resolve(factory)) + }) } ) From 6bba756856b82565336f0bf66a126f78867559e0 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Mon, 17 Feb 2020 21:09:53 +0100 Subject: [PATCH 3/3] Fix seeds, don't create additional categories --- backend/src/db/seed.js | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/db/seed.js b/backend/src/db/seed.js index f966f8b07..cf36f3039 100644 --- a/backend/src/db/seed.js +++ b/backend/src/db/seed.js @@ -967,7 +967,6 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] [...Array(4).keys()].map(() => Factory.build( 'comment', - 4, {}, { author: jennyRostock,