-
Notifications
You must be signed in to change notification settings - Fork 34
tests: Tests suites #141
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
tests: Tests suites #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||
| name: Test Suite | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| on: | ||||||||||||||||||||||
| push: | ||||||||||||||||||||||
| branches: [main, develop] | ||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||
| branches: [main, develop] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||
| test: | ||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| strategy: | ||||||||||||||||||||||
| matrix: | ||||||||||||||||||||||
| node-version: [18.x, 20.x] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| steps: | ||||||||||||||||||||||
| - uses: actions/checkout@v3 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Setup pnpm | ||||||||||||||||||||||
| uses: pnpm/action-setup@v2 | ||||||||||||||||||||||
| with: | ||||||||||||||||||||||
| version: 8 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Use Node.js ${{ matrix.node-version }} | ||||||||||||||||||||||
| uses: actions/setup-node@v3 | ||||||||||||||||||||||
| with: | ||||||||||||||||||||||
| node-version: ${{ matrix.node-version }} | ||||||||||||||||||||||
| cache: 'pnpm' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Install dependencies | ||||||||||||||||||||||
| run: pnpm install --frozen-lockfile | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Run linter | ||||||||||||||||||||||
| run: pnpm lint | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Run type check | ||||||||||||||||||||||
| run: pnpm type-check | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Run unit tests | ||||||||||||||||||||||
| run: pnpm test:ci | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Run integration tests | ||||||||||||||||||||||
| run: pnpm test:integration | ||||||||||||||||||||||
| env: | ||||||||||||||||||||||
| NODE_ENV: test | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Upload coverage to Codecov | ||||||||||||||||||||||
| uses: codecov/codecov-action@v3 | ||||||||||||||||||||||
| with: | ||||||||||||||||||||||
| files: ./coverage/lcov.info | ||||||||||||||||||||||
| flags: unittests | ||||||||||||||||||||||
| name: codecov-umbrella | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Generate coverage badge | ||||||||||||||||||||||
| if: matrix.node-version == '20.x' | ||||||||||||||||||||||
| run: | | ||||||||||||||||||||||
| COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct') | ||||||||||||||||||||||
| echo "Coverage: $COVERAGE%" | ||||||||||||||||||||||
|
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverage badge step doesn't generate a badge. This step only reads and echoes the coverage percentage but doesn't actually create or update a badge. If badge generation is intended, consider using a badge generation action or service. If this is just for logging, consider renaming the step to "Log coverage percentage". ♻️ Options to fixOption 1: Rename for clarity - - name: Generate coverage badge
+ - name: Log coverage percentageOption 2: Actually generate a badge using a service - name: Generate coverage badge
if: matrix.node-version == '20.x'
run: |
COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
echo "Coverage: $COVERAGE%"
+ # Use a badge service or action here to generate actual badge📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| blockchain-test: | ||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| steps: | ||||||||||||||||||||||
| - uses: actions/checkout@v3 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Setup Rust | ||||||||||||||||||||||
| uses: actions-rs/toolchain@v1 | ||||||||||||||||||||||
| with: | ||||||||||||||||||||||
| toolchain: stable | ||||||||||||||||||||||
| override: true | ||||||||||||||||||||||
|
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace deprecated The 🔧 Proposed fix - name: Setup Rust
- uses: actions-rs/toolchain@v1
- with:
- toolchain: stable
- override: true
+ uses: dtolnay/rust-toolchain@stable📝 Committable suggestion
Suggested change
🧰 Tools🪛 actionlint (1.7.11)[error] 68-68: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue (action) 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - name: Run Rust tests | ||||||||||||||||||||||
| run: pnpm blockchain:test | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/usr/bin/env sh | ||
| . "$(dirname -- "$0")/_/husky.sh" | ||
|
|
||
| # Run linting | ||
| pnpm lint | ||
|
|
||
| # Run tests | ||
| pnpm test:ci | ||
|
|
||
| # Check TypeScript types | ||
| pnpm type-check |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/usr/bin/env sh | ||
| . "$(dirname -- "$0")/_/husky.sh" | ||
|
|
||
| # Run full test suite before push | ||
| pnpm test:ci | ||
|
|
||
| # Run integration tests | ||
| pnpm test:integration |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "*.{ts,tsx}": [ | ||
| "eslint --fix", | ||
| "prettier --write" | ||
| ], | ||
| "*.{js,jsx}": [ | ||
| "eslint --fix", | ||
| "prettier --write" | ||
| ], | ||
| "*.{json,md}": [ | ||
| "prettier --write" | ||
| ] | ||
| } | ||
|
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configuration is correct but not invoked in pre-commit hook. The lint-staged configuration is well-structured. However, the 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,159 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Request, Response } from 'express'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { AuthController } from '../authController'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Mock dependencies | ||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mock('../../utils/jwt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mock('../../utils/password'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mock('../../prisma/client', () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| prisma: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| user: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| findFirst: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| create: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| refreshToken: { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| create: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| findUnique: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| update: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| deleteMany: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| import { prisma } from '../../prisma/client'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { hashPassword, comparePassword } from '../../utils/password'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { generateAccessToken } from '../../utils/jwt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('AuthController', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let authController: AuthController; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let mockReq: Partial<Request>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let mockRes: Partial<Response>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.clearAllMocks(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| authController = new AuthController(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| mockReq = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| body: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| mockRes = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| status: jest.fn().mockReturnThis(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| json: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "authController.test.ts" | head -5Repository: nexoraorg/chenaikit Length of output: 121 🌐 Web query:
💡 Result:
Related config:
Sources: Citations: 🏁 Script executed: cat -n ./backend/src/controllers/__tests__/authController.test.tsRepository: nexoraorg/chenaikit Length of output: 5641 Use
Safer isolation in
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(() => { | |
| jest.clearAllMocks(); | |
| authController = new AuthController(); | |
| mockReq = { | |
| body: {}, | |
| headers: {}, | |
| }; | |
| mockRes = { | |
| status: jest.fn().mockReturnThis(), | |
| json: jest.fn(), | |
| }; | |
| }); | |
| beforeEach(() => { | |
| jest.resetAllMocks(); | |
| authController = new AuthController(); | |
| mockReq = { | |
| body: {}, | |
| headers: {}, | |
| }; | |
| mockRes = { | |
| status: jest.fn().mockReturnThis(), | |
| json: jest.fn(), | |
| }; | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@backend/src/controllers/__tests__/authController.test.ts` around lines 31 -
42, The tests use jest.clearAllMocks() in the beforeEach which only clears call
history but preserves mock implementations, causing stubs (e.g.,
prisma.user.findFirst) to leak between tests; replace jest.clearAllMocks() with
jest.resetAllMocks() in the beforeEach where authController (new
AuthController()), mockReq and mockRes are initialized so each test starts with
fresh mock implementations and no retained mockResolvedValue/mockReturnValue
behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update outdated GitHub Actions to latest versions.
Static analysis indicates these actions are outdated and may not work correctly on newer runners:
actions/checkout@v3→actions/checkout@v4actions/setup-node@v3→actions/setup-node@v4codecov/codecov-action@v3→codecov/codecov-action@v5🔧 Proposed version updates
Apply similar update to checkout on line 65.
Also applies to: 26-26, 49-49, 65-65
🧰 Tools
🪛 actionlint (1.7.11)
[error] 18-18: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🤖 Prompt for AI Agents