Skip to content

Rewrite rating-service.spec.ts to use TestDatabaseService#121

Merged
sezanzeb merged 1 commit into
voting-featurefrom
copilot/update-rating-service-tests
Apr 7, 2026
Merged

Rewrite rating-service.spec.ts to use TestDatabaseService#121
sezanzeb merged 1 commit into
voting-featurefrom
copilot/update-rating-service-tests

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 6, 2026

rating-service.spec.ts used hand-rolled mock repos, making tests brittle and disconnected from actual DB behavior. This rewrites it to use TestDatabaseService (in-memory SQLite) in the style of project-service.spec.ts.

Changes

  • Replace mock repos with TestDatabaseService: beforeAll bootstraps the DB once; beforeEach calls database.nuke() and re-seeds real entities via TypeORM.
  • Real entities in DB: User, Team, Project, Criterion, and Rating are persisted and resolved through actual queries — no more mockResolvedValue chains on fake repo objects.
  • ISettingsService remains mocked: it has no DB backing, so MockSettingsService is kept.
  • All test cases preserved: permission checks (global disable, missing project, project disallows rating, own-project guard, impersonation), successful upsert, and getRatingResults aggregation.
// Before: manual mock plumbing
mockProjectsRepo.findOneBy.mockResolvedValue(
  Object.assign(new Project(), { ...mockProject, allowRating: false }),
);

// After: real DB state
await projectRepo.update(mockProject.id, { allowRating: false });

@sezanzeb sezanzeb marked this pull request as ready for review April 6, 2026 23:29
@sezanzeb sezanzeb merged commit 656bb32 into voting-feature Apr 7, 2026
@sezanzeb sezanzeb deleted the copilot/update-rating-service-tests branch April 7, 2026 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants