feat: add Cypress end-to-end tests for login functionality and CI configuration

This commit is contained in:
2025-10-18 19:34:39 +02:00
parent 736d327050
commit 94ed954dc1
6 changed files with 1544 additions and 3 deletions

23
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: CI
on:
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- uses: pnpm/action-setup@v4
with:
version: 8
- run: pnpm install
- run: npx prisma generate
- run: npx prisma db push
- run: node scripts/seed-test.js
- run: pnpm ci

10
cypress.config.ts Normal file
View File

@@ -0,0 +1,10 @@
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
})

10
cypress/e2e/login.cy.ts Normal file
View File

@@ -0,0 +1,10 @@
describe('Login', () => {
it('should login successfully', () => {
cy.visit('/login')
cy.get('input[name="email"]').type('test@example.com')
cy.get('input[name="password"]').type('password')
cy.get('button[type="submit"]').click()
cy.url().should('include', '/dashboard')
})
})

View File

@@ -6,7 +6,11 @@
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"format": "prettier --write ."
"format": "prettier --write .",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"test:e2e": "cypress run",
"ci": "pnpm build && start-server-and-test start http://localhost:3000 test:e2e"
},
"dependencies": {
"@hookform/resolvers": "^5.2.2",
@@ -42,6 +46,7 @@
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"cypress": "^15.5.0",
"prettier": "^3.6.2",
"tailwindcss": "^4",
"tw-animate-css": "^1.4.0",

1466
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

31
scripts/seed-test.js Normal file
View File

@@ -0,0 +1,31 @@
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
async function main() {
// Create test user
const hashedPassword = await bcrypt.hash('password', 10);
await prisma.user.upsert({
where: { email: 'test@example.com' },
update: {},
create: {
email: 'test@example.com',
password: hashedPassword,
role: 'MEMBER',
firstName: 'Test',
lastName: 'User',
},
});
console.log('Test user created');
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});