Skip to content

Commit

Permalink
fix(test): test before sonarqube analysis
Browse files Browse the repository at this point in the history
- make sure test results are available for coverage measurement
  • Loading branch information
cgawron committed Oct 2, 2024
1 parent ba49fe4 commit eb7b3bc
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ jobs:
with:
files: |
**/TEST-*.xml
- name: Analyze with SonarQube
if: always()
# You can pin the exact commit or the version.
# uses: SonarSource/[email protected]
uses: sonarsource/sonarqube-scan-action@master
Expand Down
6 changes: 3 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
"@types/bcrypt": "^5.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/express": "^4.17.11",
"@types/jest": "^29.5.8",
"@types/jest": "^29.5.13",
"@types/jsonwebtoken": "^9.0.3",
"@types/node": "^22.6.0",
"@types/nodemailer": "^6.4.0",
"@vitest/coverage-v8": "^2.1.1",
"@vitest/coverage-v8": "^2.1.2",
"eslint": "^8.48.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -74,7 +74,7 @@
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
"vitest": "^2.1.2"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Server", () => {
});

it("should start the server", async () => {
const res = await request(app).get("/meeting/api/v1/ping");
const res = await request(app).get("/api/v1/ping");
expect(res.status).toEqual(200);
});
});
14 changes: 7 additions & 7 deletions client/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig } from 'cypress'

const PORT = process.env.PORT || 3000;
const PORT = process.env.PORT || 5173;

export default defineConfig({
e2e: {
baseUrl: `http://localhost:${PORT}/meeting`,
video: true,
projectId: "pjkkoc"
},
})
e2e: {
baseUrl: `http://localhost:${PORT}/meeting`,
video: true,
projectId: "pjkkoc"
},
})
102 changes: 51 additions & 51 deletions client/cypress/e2e/scheduling.cy.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
/// <reference types="cypress" />

context('Error handling', () => {
describe('Error getting user', () => {
before(() => {
cy.intercept('/meeting/api/v1/users/findUserByUrl?url=christian-gawron', { statusCode: 500, body: { error: "no data" } }).as('getUser')
cy.visit('/schedule/christian-gawron/sprechstunde')
})
describe('Error getting user', () => {
before(() => {
cy.intercept('/api/v1/users/findUserByUrl?url=christian-gawron', { statusCode: 500, body: { error: "no data" } }).as('getUser')
cy.visit('/schedule/christian-gawron/sprechstunde')
})

it('Should show error message', () => {
cy.wait(['@getUser'], { timeout: 10000 })
cy.get('.error')
})
it('Should show error message', () => {
cy.wait(['@getUser'], { timeout: 10000 })
cy.get('.error')
})
})
})

context('Scheduling page', () => {
beforeEach(() => {
//const now = new Date(2021, 4, 25).getTime()
cy.clock(Date.UTC(2021, 4, 25), ['Date'])
cy.intercept('/meeting/api/v1/users/findUserByUrl?url=christian-gawron', { fixture: 'userByURL' }).as('getUser')
cy.intercept('/meeting/api/v1/events/getEventBy?user=109150731150582581691&url=sprechstunde', { fixture: 'event' }).as('getEvent')
cy.intercept('/meeting/api/v1/events/getAvailable?*', { fixture: 'available' }).as('getAvailable')
})
beforeEach(() => {
//const now = new Date(2021, 4, 25).getTime()
cy.clock(Date.UTC(2021, 4, 25), ['Date'])
cy.intercept('/api/v1/users/findUserByUrl?url=christian-gawron', { fixture: 'userByURL' }).as('getUser')
cy.intercept('/api/v1/events/getEventBy?user=109150731150582581691&url=sprechstunde', { fixture: 'event' }).as('getEvent')
cy.intercept('/api/v1/events/getAvailable?*', { fixture: 'available' }).as('getAvailable')
})

describe('Visit scheduling page and schedule appointment', () => {
before(() => {
cy.intercept('POST', '/meeting/api/v1/**', { body: { error: 'not possible' } }).as('apiCheck')
cy.visit('/schedule/christian-gawron/sprechstunde')
})
describe('Visit scheduling page and schedule appointment', () => {
before(() => {
cy.intercept('POST', '/api/v1/**', { body: { error: 'not possible' } }).as('apiCheck')
cy.visit('/schedule/christian-gawron/sprechstunde')
})

it('Check simple schedule flow', () => {
cy.wait(['@getUser', '@getEvent', '@getAvailable'], { timeout: 10000 })
cy.get('h6').should('contain', 'Christian Gawron')
cy.get('.MuiPickersDay-today').should('contain', '25')
cy.contains('07:00').click()
cy.get('[name=name]').type('Max Mustermann')
cy.get('[name=email]').type('[email protected]')
cy.get('form').submit()
cy.wait('@apiCheck', { timeout: 10000 }).then((interception) => {
cy.log(interception.request.body)
assert.equal(interception.request.body.name, 'Max Mustermann')
})
})
it('Check simple schedule flow', () => {
cy.wait(['@getUser', '@getEvent', '@getAvailable'], { timeout: 10000 })
cy.get('h6').should('contain', 'Christian Gawron')
cy.get('.MuiPickersDay-today').should('contain', '25')
cy.contains('07:00').click()
cy.get('[name=name]').type('Max Mustermann')
cy.get('[name=email]').type('[email protected]')
cy.get('form').submit()
cy.wait('@apiCheck', { timeout: 10000 }).then((interception) => {
cy.log(interception.request.body)
assert.equal(interception.request.body.name, 'Max Mustermann')
})
})
})

describe('Error creating appointment', () => {
before(() => {
cy.intercept('POST', '/meeting/api/v1/**', { statusCode: 400, body: { error: 'not possible' } }).as('apiCheck')
cy.visit('/schedule/christian-gawron/sprechstunde')
})
describe('Error creating appointment', () => {
before(() => {
cy.intercept('POST', '/api/v1/**', { statusCode: 400, body: { error: 'not possible' } }).as('apiCheck')
cy.visit('/schedule/christian-gawron/sprechstunde')
})

it('should show an error message', () => {
cy.wait(['@getUser', '@getEvent', '@getAvailable'], { timeout: 10000 })
cy.get('h6').should('contain', 'Christian Gawron')
cy.get('.MuiPickersDay-today').should('contain', '25')
cy.contains('07:00').click()
cy.get('[name=name]').type('Max Mustermann')
cy.get('[name=email]').type('[email protected]')
cy.get('form').submit()
cy.wait('@apiCheck', { timeout: 10000 })
cy.get('.error')
})
it('should show an error message', () => {
cy.wait(['@getUser', '@getEvent', '@getAvailable'], { timeout: 10000 })
cy.get('h6').should('contain', 'Christian Gawron')
cy.get('.MuiPickersDay-today').should('contain', '25')
cy.contains('07:00').click()
cy.get('[name=name]').type('Max Mustermann')
cy.get('[name=email]').type('[email protected]')
cy.get('form').submit()
cy.wait('@apiCheck', { timeout: 10000 })
cy.get('.error')
})
})
})
})
8 changes: 4 additions & 4 deletions client/cypress_ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"baseUrl": "http://localhost:3000/meeting",
"projectId": "pjkkoc",
"defaultCommandTimeout": 10000
}
"baseUrl": "http://localhost:5173/meeting",
"projectId": "pjkkoc",
"defaultCommandTimeout": 10000
}
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"build": "vite build",
"test": "npx cypress run --spec cypress/integration/**/*.spec.js --record",
"cy:ci": "cypress run --headless --e2e",
"ci": "start-server-and-test start http://localhost:3000/meeting cy:ci"
"ci": "start-server-and-test start http://localhost:5173/meeting cy:ci"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -77,7 +77,7 @@
"@types/eslint": "^9.6.1",
"@types/react-router-dom": "^5.3.3",
"@vitejs/plugin-react": "^4.3.1",
"cypress": "^13.5.0",
"cypress": "^13.15.0",
"dotenv-cli": "^7.4.2",
"eslint": "^9.11.1",
"eslint-plugin-i18next": "^6.1.0",
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"types": "./lib/types.d.ts",
"scripts": {
"test": "jest src/**/*.spec.ts --coverage --forceExit --detectOpenHandles",
"ci": "jest src/**/*.spec.ts --ci --coverage --forceExit --reporters='default' --reporters='jest-junit'",
"ci": "jest src/**/*.spec.ts --ci --coverage --forceExit --detectOpenHandles --reporters='default' --reporters='jest-junit'",
"build": "tsc",
"doc": "jsdoc -c jsdoc.json"
},
Expand Down
Loading

0 comments on commit eb7b3bc

Please sign in to comment.