From 4f2d879cd12df691d238bb88b98f7dbe5fe4b861 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Mon, 21 Oct 2024 10:52:19 +0200 Subject: [PATCH] fix(tests): remove hard-coding + wait for responses (#56728) Co-authored-by: Shaun Hamilton --- .gitpod.yml | 4 ++-- e2e/failed-updates.spec.ts | 19 +++++++++++++++---- e2e/projects.spec.ts | 13 +++++++++++-- e2e/third-party-donation.spec.ts | 2 +- e2e/utils/add-growthbook-cookie.ts | 4 +++- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 0a7bdbceae6..f7fa4286fda 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -30,7 +30,7 @@ ports: tasks: - before: | echo ' - export COOKIE_DOMAIN=gitpod.io + export COOKIE_DOMAIN=.gitpod.io export HOME_LOCATION=$(gp url 8000) export API_LOCATION=$(gp url 3000) export CHALLENGE_EDITOR_API_LOCATION=$(gp url 3200) @@ -45,7 +45,7 @@ tasks: docker compose up -d - name: server - before: export COOKIE_DOMAIN=gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000) + before: export COOKIE_DOMAIN=.gitpod.io && export HOME_LOCATION=$(gp url 8000) && export API_LOCATION=$(gp url 3000) # init is not executed for prebuilt workspaces and restarts, # so we should put all the heavy initialization here init: > diff --git a/e2e/failed-updates.spec.ts b/e2e/failed-updates.spec.ts index 94bd8e1bf64..ae189198734 100644 --- a/e2e/failed-updates.spec.ts +++ b/e2e/failed-updates.spec.ts @@ -36,7 +36,7 @@ test.describe('failed update flushing', () => { }) => { // Initially, the user has no completed challenges. const userRes = await request.get( - 'http://localhost:3000/user/get-session-user' + new URL('/user/get-session-user', process.env.API_LOCATION).toString() ); const completedChallenges = (await userRes.json()).user.developmentuser .completedChallenges; @@ -55,16 +55,27 @@ test.describe('failed update flushing', () => { // The update epic sends two requests and this lets us wait for both. const submitRes = page - .waitForResponse('http://localhost:3000/modern-challenge-completed') + .waitForResponse( + new URL( + '/modern-challenge-completed', + process.env.API_LOCATION + ).toString() + ) + .then(() => - page.waitForResponse('http://localhost:3000/modern-challenge-completed') + page.waitForResponse( + new URL( + '/modern-challenge-completed', + process.env.API_LOCATION + ).toString() + ) ); await page.reload(); await submitRes; const updatedUserRes = await request.get( - 'http://localhost:3000/user/get-session-user' + new URL('/user/get-session-user', process.env.API_LOCATION).toString() ); // Now the user should have both completed challenges. diff --git a/e2e/projects.spec.ts b/e2e/projects.spec.ts index f61b937b418..5c7173d994b 100644 --- a/e2e/projects.spec.ts +++ b/e2e/projects.spec.ts @@ -1,6 +1,7 @@ import { execSync } from 'child_process'; import { test, expect, Page } from '@playwright/test'; import { SuperBlocks } from '../shared/config/curriculum'; +import translations from '../client/i18n/locales/english/translations.json'; import tributePageHtml from './fixtures/tribute-page-html.json'; import tributePageCss from './fixtures/tribute-page-css.json'; import curriculum from './fixtures/js-ads-projects.json'; @@ -8,6 +9,7 @@ import { authedRequest } from './utils/request'; import { focusEditor, getEditors, clearEditor } from './utils/editor'; import { isMacOS } from './utils/user-agent'; +import { alertToBeVisible } from './utils/alerts'; interface Meta { challengeOrder: { id: string; title: string }[]; @@ -201,7 +203,7 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings }); await expect(solutionModal).toBeVisible(); await solutionModal - .getByRole('button', { name: 'Close' }) + .getByRole('button', { name: translations.buttons['close'] }) .first() .click(); // Wait for the modal to disappear before continue @@ -210,16 +212,23 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings await page .getByRole('button', { - name: "I agree to freeCodeCamp's Academic Honesty Policy." + name: translations.buttons['agree-honesty'] }) .click(); + await alertToBeVisible(page, translations.buttons['accepted-honesty']); + await page .getByRole('button', { name: 'Claim Certification Legacy JavaScript Algorithms and Data Structures' }) .click(); + await alertToBeVisible( + page, + '@developmentuser, you have successfully claimed the Legacy JavaScript Algorithms and Data Structures Certification! Congratulations on behalf of the freeCodeCamp.org team!' + ); + const showCertLink = page.getByRole('link', { name: 'Show Certification Legacy JavaScript Algorithms and Data Structures' }); diff --git a/e2e/third-party-donation.spec.ts b/e2e/third-party-donation.spec.ts index 37479813972..9e6cd1ad284 100644 --- a/e2e/third-party-donation.spec.ts +++ b/e2e/third-party-donation.spec.ts @@ -59,7 +59,7 @@ test.describe('third-party donation tests', () => { ); await page.route( - 'http://localhost:3000/donate/charge-stripe-card', + new URL('donate/charge-stripe-card', process.env.API_LOCATION).toString(), async route => { await route.fulfill({ json: { isDonating: true } }); } diff --git a/e2e/utils/add-growthbook-cookie.ts b/e2e/utils/add-growthbook-cookie.ts index 437c6b47d43..6209f64710f 100644 --- a/e2e/utils/add-growthbook-cookie.ts +++ b/e2e/utils/add-growthbook-cookie.ts @@ -11,7 +11,9 @@ export async function addGrowthbookCookie({ { name: 'gbuuid', value: variation, - domain: 'localhost', + // Weirdly, it seems necessary to prefix the domain with a dot. This seems + // to be a peculiarity of Playwright. + domain: process.env.COOKIE_DOMAIN || 'localhost', path: '/', expires: Math.floor(Date.now() / 1000) + 400 * 24 * 60 * 60 // 400 days from now }