Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/e2etests #59

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
216c35c
Test e2e workflow
JBlixems Jun 23, 2024
24a95c8
Modify package.json
JBlixems Jun 23, 2024
c4d6510
Add env variables from github secrets
JBlixems Jun 23, 2024
82a24f2
Fix e2e workflow
JBlixems Jun 23, 2024
c8d5039
Test new docker compose command in e2e workflow
JBlixems Jun 23, 2024
de6c49f
Attempt another fix for e2e
JBlixems Jun 23, 2024
9bd4932
Fix path
JBlixems Jun 23, 2024
0db05c7
Test another fix for e2e
JBlixems Jun 23, 2024
579bafb
Another fix
JBlixems Jun 23, 2024
96fd8b1
Another fix
JBlixems Jun 23, 2024
378d7bc
Dont wait for nginx
JBlixems Jun 23, 2024
36f8b86
Don't wait for anything
JBlixems Jun 23, 2024
c7be453
Dont install cypress again
JBlixems Jun 23, 2024
0e00ac5
Fix cypress command for e2e
JBlixems Jun 23, 2024
8e51ec2
Install cypress dependancies
JBlixems Jun 23, 2024
cc20025
Fix permission issues
JBlixems Jun 23, 2024
48db01b
Fix permission issues and file path
JBlixems Jun 23, 2024
350e17c
Add login test
JBlixems Jun 23, 2024
63c390e
Merge branch 'develop' into feature/e2etest
JBlixems Jun 23, 2024
095f81d
Test new e2e
JBlixems Jun 23, 2024
6a3ae1f
Merge branch 'feature/e2etest' of https://github.com/COS301-SE-2024/C…
JBlixems Jun 23, 2024
62c132c
Fix broken dev code
JBlixems Jun 23, 2024
b4d4a06
Run docker in detached mode
JBlixems Jul 1, 2024
ab8cd3b
Fix merge conflict
JBlixems Jul 1, 2024
a46d33c
Add other sdk secrets
JBlixems Jul 1, 2024
0d14289
Fix the e2e testing to work
JBlixems Jul 1, 2024
cad0260
Cache npm install for workflows
JBlixems Jul 2, 2024
adbe0e6
Remove caching will fix another time
JBlixems Jul 2, 2024
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
23 changes: 1 addition & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Build Codebase
on:
push:
Expand All @@ -11,18 +10,8 @@ permissions:
contents: read

jobs:
start:
name: Initial Setup
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Starting Job
run: |
echo "Beginning to Build ${{ github.repository }}"

run_tests:
name: Build Codebase
needs: start
runs-on: ubuntu-latest
steps:
- name: Checkout "${{ github.repository }}"
Expand All @@ -39,14 +28,4 @@ jobs:

- name: Build Codebase
run: |
cd CoVAR-app && npm run build

end:
name: The end
runs-on: ubuntu-latest
needs: [start, run_tests]
steps:
- name: Ending
id: init
run: |
echo "${{ github.repository }} has been successfully built"
cd CoVAR-app && npm run build
65 changes: 65 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Cypress E2E Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Compose
uses: docker/setup-buildx-action@v2

- name: Create .env file
run: |
echo PG_USER=${{ secrets.PG_USER }} >> .env
echo PG_HOST=${{ secrets.PG_HOST }} >> .env
echo PG_DATABASE=${{ secrets.PG_DATABASE }} >> .env
echo PG_PASSWORD=${{ secrets.PG_PASSWORD }} >> .env
echo PG_PORT=${{ secrets.PG_PORT }} >> .env
echo JSON_SECRET=${{ secrets.JSON_SECRET }} >> .env
echo REFRESH_SECRET=${{ secrets.REFRESH_SECRET }} >> .env
echo REACT_APP_API_KEY=${{ secrets.REACT_APP_API_KEY }} >> .env
echo REACT_APP_AUTH_DOMAIN=${{ secrets.REACT_APP_AUTH_DOMAIN }} >> .env
echo REACT_APP_PROJECT_ID=${{ secrets.REACT_APP_PROJECT_ID }} >> .env
echo REACT_APP_STORAGE_BUCKET=${{ secrets.REACT_APP_STORAGE_BUCKET }} >> .env
echo REACT_APP_MESSAGING_SENDER_ID=${{ secrets.REACT_APP_MESSAGING_SENDER_ID }} >> .env
echo REACT_APP_APP_ID=${{ secrets.REACT_APP_APP_ID }} >> .env
echo REACT_APP_MEASUREMENT_ID=${{ secrets.REACT_APP_MEASUREMENT_ID }} >> .env

- name: create-json
id: create-json
uses: jsdaniell/[email protected]
with:
name: "server/covar-7c8b5-firebase-adminsdk-85918-b6654147c1.json"
json: ${{ secrets.FIREBASE_SDK }}

- name: Create DB Schema
run: |
echo ${{ secrets.SCHEMA }} > schema.sql

- name: Clean up any existing Docker containers and networks
run: |
docker-compose down || true
docker container prune -f
docker network prune -f

- name: Build and run Docker Compose services
run: docker-compose up --build -d

- name: Wait for services to be ready
run: |
echo "Waiting for services to be ready..."
sleep 20

- name: Run Cypress tests
run: docker run --network host -v $PWD/CoVAR-app:/CoVAR-app -w /CoVAR-app cypress/included:13.11.0 --config-file cypress.config.js

- name: Shut down Docker Compose services
run: docker-compose down
25 changes: 3 additions & 22 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@ name: Lint Codebase
on:
push:
branches: [ main, develop ]

pull_request:
branches: [ main, develop ]
#types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read

jobs:
start:
name: Initial Setup
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Starting Job
run: |
echo "Beginning to lint ${{ github.repository }}"

lint_frontend:
name: Lint Frontend
runs-on: ubuntu-latest
needs: start
steps:
- name: Checkout "${{ github.repository }}"
uses: actions/checkout@v3
Expand All @@ -37,13 +27,4 @@ jobs:

- name: Lint Codebase
run: |
cd CoVAR-app && npm run lint
end:
name: The end
runs-on: ubuntu-latest
needs: [lint_frontend]
steps:
- name: Ending
id: init
run: |
echo "${{ github.repository }} has been successfully linted"
cd CoVAR-app && npm run lint
23 changes: 1 addition & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Test Codebase
on:
push:
Expand All @@ -11,18 +10,8 @@ permissions:
contents: read

jobs:
start:
name: Initial Setup
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Starting Job
run: |
echo "Beginning to test ${{ github.repository }}"

run_tests:
name: Test Codebase
needs: start
runs-on: ubuntu-latest
steps:
- name: Checkout "${{ github.repository }}"
Expand Down Expand Up @@ -53,14 +42,4 @@ jobs:
run: |
echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"

end:
name: The end
runs-on: ubuntu-latest
needs: [start, run_tests]
steps:
- name: Ending
id: init
run: |
echo "${{ github.repository }} has passed all tests"
echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}"
15 changes: 15 additions & 0 deletions CoVAR-app/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
baseUrl: "http://localhost:3050",
setupNodeEvents(on, config) {
on('task', {
logDOM(domString) {
console.log(domString);
return null;
}
});
},
},
});
30 changes: 30 additions & 0 deletions CoVAR-app/cypress/e2e/login.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('Login E2E Tests', () => {
beforeEach(() => {
cy.visit('/login')
})

it('displays the entire DOM for debugging', () => {
cy.document().then((doc) => {
const domString = doc.documentElement.outerHTML;
cy.task('logDOM', domString);
});
});

it('displays an error message with incorrect credentials', () => {
cy.get('input[name="email"]', { timeout: 4000 }).type('[email protected]')
cy.get('input[name="password"]').type('wrongpassword')
cy.get('button[type="submit"]').click()

cy.wait(1000)
cy.get('#error').should("have.text", 'Failed to sign in. Please check your credentials.')
})

it('successfully logs in with correct credentials', () => {
cy.get('input[name="email"]', { timeout: 4000 }).type('[email protected]')
cy.get('input[name="password"]').type('Password')
cy.get('button[type="submit"]').click()

cy.url().should('include', '/')
})

})
5 changes: 5 additions & 0 deletions CoVAR-app/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": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions CoVAR-app/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts 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) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions CoVAR-app/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts 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'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading
Loading