Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -74,3 +76,7 @@ jobs:
run: |
cd client
npm run test

- name: Run integration tests
run: |
npx start-server-and-test 'npm run dev' http://localhost:5173 'npx cypress run'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ server/node_modules
.env
*.pem
client/coverage
server/coverage
server/coverage
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
allowCypressEnv: false,

e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
};
85 changes: 85 additions & 0 deletions cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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()

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', () => {
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: {
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')

})



})
37 changes: 37 additions & 0 deletions cypress/e2e/make_post.cy.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -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) => { ... })
17 changes: 17 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -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'
8 changes: 8 additions & 0 deletions dev-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}