From c60d6e4dd9c65d2e8fff7737659ddf65a3f8428e Mon Sep 17 00:00:00 2001 From: Tiffany Chang Date: Sun, 8 Mar 2026 23:20:41 -0700 Subject: [PATCH 1/5] login integration test --- .gitignore | 2 + cypress.config.js | 9 ++++ cypress/e2e/login.cy.js | 80 +++++++++++++++++++++++++++++++++++ cypress/fixtures/example.json | 5 +++ cypress/support/commands.js | 25 +++++++++++ cypress/support/e2e.js | 17 ++++++++ 6 files changed, 138 insertions(+) create mode 100644 cypress.config.js create mode 100644 cypress/e2e/login.cy.js create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/e2e.js diff --git a/.gitignore b/.gitignore index df460d7..3500ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ server/node_modules *.pem client/coverage server/coverage +cypress/e2e/1-getting-started +cypress/e2e/2-advanced-examples \ No newline at end of file diff --git a/cypress.config.js b/cypress.config.js new file mode 100644 index 0000000..5e6fbd5 --- /dev/null +++ b/cypress.config.js @@ -0,0 +1,9 @@ +module.exports = { + allowCypressEnv: false, + + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}; diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js new file mode 100644 index 0000000..f5f108b --- /dev/null +++ b/cypress/e2e/login.cy.js @@ -0,0 +1,80 @@ +describe('login spec', () => { + beforeEach(() => { + cy.visit('http://localhost:5173/') + Cypress.Cookies.debug(true) + cy.clearCookies() + }) + it('shows sign in on load', () => { + cy.get('.App div').first().should('have.class', 'landing-page') + cy.get('h2').should('have.text', 'Sign In') + }) + + it('toggles to signup', () => { + cy.get('.link-button').click() + cy.get('h2').should('have.text', 'Sign Up') + + cy.get('.link-button').click() + cy.get('h2').should('have.text', 'Sign In') + + }) + + it('render home page when signed in', () => { + cy.intercept('POST', '**/auth/v1/token*').as('loginRequest') + + cy.get('input[placeholder="Enter email"]').type('test@email.mail') + cy.get('input[placeholder="Enter password"]').type('pass10') + cy.get('button[type="submit"]').click().then + + cy.wait('@loginRequest').then((interception) => { + expect(interception.response?.statusCode).to.equal(200) + }) + + cy.getCookies().should('have.length', 1) + cy.get('.App div').contains('Create a Music Moment').should('be.visible'); + }) + + it('does not render home with incorrect credentials', () => { + cy.intercept('POST', '**/auth/v1/token*').as('loginRequest') + + cy.get('input[placeholder="Enter email"]').type('test@email.mail') + cy.get('input[placeholder="Enter password"]').type('pass101') + cy.get('button[type="submit"]').click() + + cy.wait('@loginRequest').then((interception) => { + expect(interception.response?.statusCode).to.equal(400) + }) + cy.get('.App div').contains('Invalid email or password. Please try again.').should('be.visible'); + + cy.getCookies().should('have.length', 0) + }) + + it('creates new account with sign up', () => { + cy.get('.link-button').click() + cy.intercept('POST', '**/auth/v1/signup*', { + statusCode: 200, + body: { + user: { + id: 'mock-user-id-123', + email: 'test@example.com' + }, + session: null + } + }).as('signupRequest') + + cy.get('input[placeholder="Enter email"]').type('test123@example.com') + cy.get('input[placeholder="Enter username"]').type('test') + cy.get('input[placeholder="Enter password"]').type('pass101') + cy.get('button[type="submit"]').click() + + cy.wait('@signupRequest') + + cy.on('window:alert', (alertText) => { + expect(alertText).to.contains('Sign up successful! Please check your email to verify your account.') + }) + cy.get('h2').should('have.text', 'Sign In') + + }) + + + +}) diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 0000000..66ea16e --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js new file mode 100644 index 0000000..3eaffff --- /dev/null +++ b/cypress/support/e2e.js @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/e2e.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' \ No newline at end of file From c89e0392f82c9d33436f8b717bae7021adef47a8 Mon Sep 17 00:00:00 2001 From: Tiffany Chang Date: Mon, 9 Mar 2026 00:51:24 -0700 Subject: [PATCH 2/5] make post cypress test --- .github/workflows/jest.yml | 4 ++++ .gitignore | 4 +--- cypress/e2e/login.cy.js | 7 ++++++- cypress/e2e/make_post.cy.js | 37 +++++++++++++++++++++++++++++++++++++ dev-docs.md | 8 ++++++++ 5 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 cypress/e2e/make_post.cy.js diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 632feb5..641dc48 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -74,3 +74,7 @@ jobs: run: | cd client npm run test + + -name: Run integration tests + run: | + npx cypress run diff --git a/.gitignore b/.gitignore index 3500ebb..c5d072a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,4 @@ server/node_modules .env *.pem client/coverage -server/coverage -cypress/e2e/1-getting-started -cypress/e2e/2-advanced-examples \ No newline at end of file +server/coverage \ No newline at end of file diff --git a/cypress/e2e/login.cy.js b/cypress/e2e/login.cy.js index f5f108b..472a405 100644 --- a/cypress/e2e/login.cy.js +++ b/cypress/e2e/login.cy.js @@ -23,7 +23,7 @@ describe('login spec', () => { cy.get('input[placeholder="Enter email"]').type('test@email.mail') cy.get('input[placeholder="Enter password"]').type('pass10') - cy.get('button[type="submit"]').click().then + cy.get('button[type="submit"]').click() cy.wait('@loginRequest').then((interception) => { expect(interception.response?.statusCode).to.equal(200) @@ -49,7 +49,12 @@ describe('login spec', () => { }) it('creates new account with sign up', () => { + const testUser = { + email: `test-${Date.now()}@example.com`, + password: 'TestPassword123!' + } cy.get('.link-button').click() + // stubbing the signup to prevent new accounts being made every time test is run cy.intercept('POST', '**/auth/v1/signup*', { statusCode: 200, body: { diff --git a/cypress/e2e/make_post.cy.js b/cypress/e2e/make_post.cy.js new file mode 100644 index 0000000..773776f --- /dev/null +++ b/cypress/e2e/make_post.cy.js @@ -0,0 +1,37 @@ +describe('make post spec', () => { + beforeEach(() => { + cy.visit('http://localhost:5173/', { + onBeforeLoad(win) { + cy.stub(win.navigator.geolocation, 'getCurrentPosition').callsArgWith(0, { + coords: { + latitude: 43, + longitude: -125, + }, + }) + }, + }) + cy.intercept('POST', '**/auth/v1/token*').as('loginRequest') + cy.get('input[placeholder="Enter email"]').type('test@email.mail') + cy.get('input[placeholder="Enter password"]').type('pass10') + cy.get('button[type="submit"]').click() + cy.wait('@loginRequest') + + }) + it('adds post to map', () => { + cy.intercept('POST', '/api/posts', { + statusCode: 201 + }).as('postRequest') + cy.get('.leaflet-marker-icon').its('length').then((initialCount) => { + cy.get('.post-button').click() + cy.get('.form-input').eq(0).type('Last Christmas') + cy.get('.form-input').eq(1).type('Wham') + cy.get('.form-input').eq(2).type('integration test song') + cy.get('.btn-add').click() + + cy.wait('@postRequest') + + // Marker count increased + cy.get('.leaflet-marker-icon').should('have.length', initialCount + 1) + }) + }) +}) \ No newline at end of file diff --git a/dev-docs.md b/dev-docs.md index c128ecd..0288c3e 100644 --- a/dev-docs.md +++ b/dev-docs.md @@ -46,7 +46,13 @@ soundscape/ │ ├── package.json │ ├── package-lock.json │ └── tsconfig.json +├── cypress/ +| ├── e2e/ +| ├── fixtures/ +| ├── screenshots/ +| └── support/ ├── .gitignore +├── cypress.config.js ├── package.json ├── package-lock.json ├── tsconfig.json @@ -117,6 +123,8 @@ Tests can be run individually in the `client` and `server` directories with environment file may not be setup properly, and `npm install` may be needed in order to install packages needed. +Integrations test can be run in the root directory. Make sure the application is running locally and run `npx cypress run` to run all cypress tests. An individual test file can be run with `npx cypress run --spec "cypress/e2e/path/to/file"` and run tests with a specfic browser by running `npx cypress run --browser chrome`. To use the cypress GUI to interactively run and create tests run `npx cypress open`. + ## How to Add New Tests ### Client From d5dded6b7042b63edb60c9566f94922058ff3f6e Mon Sep 17 00:00:00 2001 From: Tiffany Chang Date: Mon, 9 Mar 2026 00:55:30 -0700 Subject: [PATCH 3/5] yaml fix --- .github/workflows/jest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 641dc48..7abf63e 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -75,6 +75,6 @@ jobs: cd client npm run test - -name: Run integration tests + - name: Run integration tests run: | npx cypress run From 5eec85ce5add2aec448db0c8d5631bac3375e4de Mon Sep 17 00:00:00 2001 From: Tiffany Chang Date: Mon, 9 Mar 2026 01:11:57 -0700 Subject: [PATCH 4/5] use start-server-and-test to automate integration tests --- .github/workflows/jest.yml | 2 +- package.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 7abf63e..56dbf68 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -77,4 +77,4 @@ jobs: - name: Run integration tests run: | - npx cypress run + npx start-server-and-test 'npm run dev' http://localhost:5173 'npx cypress run' diff --git a/package.json b/package.json index 9101e7f..1f30093 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "test": "./env-setup.sh && concurrently \"npm run test --prefix server\" \"npm run test --prefix client\"" }, "devDependencies": { - "concurrently": "^9.2.1" + "concurrently": "^9.2.1", + "start-server-and-test": "^2.1.5", + "cypress": "^15.10.0" } } From c287d1d970f0e0619b19f1c40c15fdc2d4076656 Mon Sep 17 00:00:00 2001 From: leoSallos Date: Mon, 9 Mar 2026 10:26:39 -0700 Subject: [PATCH 5/5] patch testing environment setup for workflow yml --- .github/workflows/jest.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jest.yml b/.github/workflows/jest.yml index 56dbf68..704426a 100644 --- a/.github/workflows/jest.yml +++ b/.github/workflows/jest.yml @@ -53,8 +53,9 @@ jobs: echo "HTTPS_KEY_PASSPHRASE=${{ secrets.HTTPS_KEY_PASSPHRASE }}" >> server/.env echo "NEXT_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}" >> server/.env echo "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY }}" >> server/.env + echo "COOKIE_HOST_URL=.localhost" >> server/.env - - name: Create server https keys + - name: Import server https keys run: | echo "${{ secrets.TEST_KEY }}" > server/key.pem echo "${{ secrets.TEST_CERT }}" > server/cert.pem @@ -63,7 +64,8 @@ jobs: run: | echo "VITE_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}" >> client/.env echo "VITE_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY }}" >> client/.env - echo "VITE_SERVER_URL=https://placeholder.url" >> client/.env + echo "VITE_SERVER_URL=https://localhost:8000" >> client/.env + echo "VITE_COOKIE_HOST_URL=.localhost" >> client/.env - name: Run server tests run: |