Skip to content

Commit

Permalink
chore: enable back cypress (#1719)
Browse files Browse the repository at this point in the history
* chore(cypress): bump package

* chore(prettier): enable prettier on cypress tests files

* fix(e2e): enable back auth tests

* fix(e2e): enable back ressources tests

* fix(e2e): enable back remaining tests

* chore: enable back cypress workflow

* feat(cypress): upload failed files as artifacts

* fix(cypress): failing tests

* fix: import fs

* fix: code review
  • Loading branch information
keellyp authored Sep 11, 2024
1 parent 269b172 commit 1d7dbe0
Show file tree
Hide file tree
Showing 35 changed files with 811 additions and 775 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/cypress.old

This file was deleted.

77 changes: 77 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: TestE2E

on:
pull_request:
types: [opened, reopened, review_requested, ready_for_review, synchronize]

jobs:
cypress-run:
if: github.event.pull_request.draft == false
name: Run Test E2E
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Checkout API Git repository
uses: actions/checkout@v4
with:
repository: getlago/lago-api
ref: ${{ github.event.inputs.api_branch }}
path: api
token: ${{ secrets.GH_TOKEN }}

- name: Build Front local image
run: |
docker build -t getlago/front:ci ./
- name: Build API local image
run: |
docker build -t getlago/api:ci ./api
- name: Generate API RSA Key
run: |
echo "LAGO_RSA_PRIVATE_KEY=\"`openssl genrsa 2048 | base64`\"" >> .env
- name: Launch APP + API
env:
LAGO_LICENSE: ${{ secrets.LAGO_LICENSE }}
run: |
docker compose -f ./ci/docker-compose.ci.yml --env-file ./.env up -d db redis api front
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Cypress run
uses: cypress-io/github-action@v6
env:
CYPRESS_GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
browser: chrome
record: false
config-file: ./cypress/cypress.config.js
config: baseUrl=http://localhost,viewportHeight=800,viewportWidth=1280,video=true
spec: |
cypress/e2e/00-auth/*
cypress/e2e/10-resources/*
cypress/e2e/t10-*
cypress/e2e/t20-*
cypress/e2e/t30-*
- name: Upload screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore

- name: Upload videos
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
.env
yarn-error.log
coverage
cypress/downloads
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ dist
generated
globals.d.ts
ci
cypress/*
cypress/downloads
cypress/screenshots
2 changes: 1 addition & 1 deletion ci/docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: '3.8'

services:
db:
image: postgres:14.0-alpine
image: postgres:14-alpine
container_name: lago-db
restart: unless-stopped
environment:
Expand Down
11 changes: 0 additions & 11 deletions cypress.config.ts

This file was deleted.

16 changes: 16 additions & 0 deletions cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
const { defineConfig } = require('cypress')
const fs = require('fs')

require('dotenv').config({ path: '../.env' })

module.exports = defineConfig({
projectId: 'u863yi',
e2e: {
baseUrl: process.env.CYPRESS_APP_URL,
experimentalRunAllSpecs: true,
setupNodeEvents(on) {
on('after:spec', (_spec, results) => {
if (results && results.video) {
// Do we have failures for any retry attempts?
const failures = results.tests.some((test) =>
test.attempts.some((attempt) => attempt.state === 'failed'),
)
if (!failures) {
// delete the video if the spec passed and no tests retried
fs.unlinkSync(results.video)
}
}
})
},
},
})
28 changes: 10 additions & 18 deletions cypress/e2e/00-auth/t0-signup.cy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { userEmail, userPassword } from '../../support/reusableConstants'

describe('Sign up page test', () => {
it('should be able to visit app', () => {
describe('Sign up', () => {
it('should create a new user and redirect to the home after signup', () => {
cy.visit('sign-up')
})

it(
'should create a new user and redirect to the home after signup',
{ defaultCommandTimeout: 5000 },
() => {
cy.visit('sign-up')

cy.get('input[name="organizationName"]').type('Company name')
cy.get('input[name="email"]').type(userEmail)
cy.get('input[name="password"]').type(userPassword)
cy.get('[data-test="submit-button"]').click()
cy.get('input[name="organizationName"]').type('Company name')
cy.get('input[name="email"]').type(userEmail)
cy.get('input[name="password"]').type(userPassword)
cy.get('[data-test="submit-button"]').click()

cy.url().should('be.equal', Cypress.config().baseUrl + '/')
cy.get('[data-test="side-nav-name"]').contains('Company name')
}
)
cy.url().should('be.equal', Cypress.config().baseUrl + '/')
cy.get('[data-test="side-nav-name"]').contains('Company name')
})

it('should have a disabled button on visiting', () => {
cy.visit('sign-up')
Expand Down Expand Up @@ -52,7 +44,7 @@ describe('Sign up page test', () => {
cy.get('[data-test="error-alert"]').should('exist')
})

it('should display the right password error', () => {
it('should display the right password error message', () => {
cy.visit('sign-up')

cy.get('input[name="password"]').focus()
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/00-auth/t10-login.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { userEmail, userPassword } from '../../support/reusableConstants'

describe('Log in page test', () => {
it('should redirect to home page when right credentials ::preventLogin', () => {
describe('Log in', () => {
it('should redirect to home page if right credentials', () => {
cy.visit('login')
cy.get('input[name="email"]').type(userEmail)
cy.get('input[name="password"]').type(userPassword)
Expand All @@ -10,7 +10,7 @@ describe('Log in page test', () => {
cy.get('[data-test="error-alert"]').should('not.exist')
})

it('should display an error when wrong credentials ::preventLogin', () => {
it('should display an error if wrong credentials', () => {
cy.visit('/login')

cy.get('input[name="email"]').type(userEmail)
Expand All @@ -20,15 +20,15 @@ describe('Log in page test', () => {
cy.get('[data-test="error-alert"]').should('exist')
})

it('should display errors if inputs are not filled ::preventLogin', () => {
it('should display errors if inputs are not filled', () => {
cy.visit('/login')

cy.get('[data-test="submit"]').click()
cy.url().should('be.equal', Cypress.config().baseUrl + '/login')
cy.get('[data-test="text-field-error"]').should('have.length', 2)
})

it('should redirect on sign up on link click ::preventLogin', () => {
it('should redirect on sign up on link click', () => {
cy.visit('/login')

cy.get('[href="/sign-up"]').click()
Expand Down
95 changes: 46 additions & 49 deletions cypress/e2e/10-resources/t10-create-taxes.cy.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
import { TAX_TEN_CODE, TAX_TWENTY_CODE } from '../../support/reusableConstants'

describe('Create taxes', () => {
it('remove me when other tests are uncommented', () => {
expect(true).to.equal(true)
it('should create taxes', () => {
cy.visit('/settings/taxes')
cy.url().should('include', '/settings/taxes')

// Make sure no tax exists
cy.get('[data-test="empty-title"]').should('exist')

// Create tax 10%
cy.get('[data-test="create-tax-button"]').click()
cy.url().should('include', '/create/tax')
cy.get('input[name="name"]').type(TAX_TEN_CODE)
cy.get('input[name="code"]').type(TAX_TEN_CODE)
cy.get('input[name="rate"]').type('10')
cy.get('[data-test="submit"]').click()

// Create tax 20%
cy.get('[data-test="create-tax-button"]').click()
cy.url().should('include', '/create/tax')
cy.get('input[name="name"]').type(TAX_TWENTY_CODE)
cy.get('input[name="code"]').type(TAX_TWENTY_CODE)
cy.get('input[name="rate"]').type('20')
cy.get('[data-test="submit"]').click()

cy.get(`[data-test="${TAX_TEN_CODE}"]`).should('exist')
cy.get(`[data-test="${TAX_TWENTY_CODE}"]`).should('exist')
})

it('should assign tax to organization', () => {
cy.visit('/settings/invoice')
cy.url().should('include', '/settings/invoice')

// Make sure no tax are already assigned
cy.get('[data-test="empty-taxes"]')
.scrollIntoView({
offset: { top: -100, left: 0 },
duration: 0,
})
.should('exist')

// Assign tax 20%
cy.get('[data-test="add-tax-button"]').click()
cy.get('[data-test="add-organization-tax-dialog"]').should('exist')
cy.get('input[name="selectTax"]').click()
cy.get('[data-option-index="1"]').click()
cy.get('[data-test="submit-add-organization-tax-dialog-assign-button"]').click()
cy.get(`[data-test="applied-tax-${TAX_TWENTY_CODE}"]`).should('exist')
})
// TODO: uncomment when clickhouse migration is dones
// it('should create taxes', () => {
// cy.visit('/settings/taxes')
// cy.url().should('include', '/settings/taxes')
// // Make sure no tax exists
// cy.get('[data-test="empty-title"]').should('exist')

// // Create tax 10%
// cy.get('[data-test="create-tax-button"]').click()
// cy.url().should('include', '/create/tax')
// cy.get('input[name="name"]').type(TAX_TEN_CODE)
// cy.get('input[name="code"]').type(TAX_TEN_CODE)
// cy.get('input[name="rate"]').type('10')
// cy.get('[data-test="submit"]').click()
// // Create tax 20%
// cy.get('[data-test="create-tax-button"]').click()
// cy.url().should('include', '/create/tax')
// cy.get('input[name="name"]').type(TAX_TWENTY_CODE)
// cy.get('input[name="code"]').type(TAX_TWENTY_CODE)
// cy.get('input[name="rate"]').type('20')
// cy.get('[data-test="submit"]').click()

// cy.get(`[data-test="${TAX_TEN_CODE}"]`).should('exist')
// cy.get(`[data-test="${TAX_TWENTY_CODE}"]`).should('exist')
// })

// TODO: uncomment
// it('sould assign tax to organization', () => {
// cy.visit('/settings/invoice')
// cy.url().should('include', '/settings/invoice')

// // Make sure no tax are already assigned
// cy.get('[data-test="empty-taxes"]')
// .scrollIntoView({
// offset: { top: -100, left: 0 },
// duration: 0,
// })
// .should('exist')

// // Assign tax 20%
// cy.get('[data-test="add-tax-button"]').click()
// cy.get('[data-test="add-organization-tax-dialog"]').should('exist')
// cy.get('input[name="selectTax"]').click()
// cy.get('[data-option-index="1"]').click()
// cy.get('[data-test="submit-add-organization-tax-dialog-assign-button"]').click()
// cy.get(`[data-test="applied-tax-${TAX_TWENTY_CODE}"]`).should('exist')
// })
})
Loading

0 comments on commit 1d7dbe0

Please sign in to comment.