Skip to content

test(categories): add co-located unit tests for CategoriesService - #1372

Merged
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
Magrexy:feat/issue-1284-categories-test-coverage
Aug 26, 2026
Merged

test(categories): add co-located unit tests for CategoriesService#1372
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
Magrexy:feat/issue-1284-categories-test-coverage

Conversation

@Magrexy

@Magrexy Magrexy commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1284
Closes #1285
Closes #1286
Closes #1287

Adds a co-located categories.service.spec.ts with 20 unit tests covering every public method in CategoriesService, replacing the single misplaced assertion in femaleotaku.spec.ts with focused, discoverable coverage.

Why

The only test touching CategoriesService was one it() in backend/src/femaleotaku.spec.ts — a file that bundles unrelated modules into a single describe. That test covers only the create path with depreciation defaults. Not-found paths for findById, update, and delete had zero coverage. The self-parent rejection in update() was also untested. Moving tests to a co-located spec file follows the project convention and makes failures attributable to the exact module.

What was built

backend/src/categories/categories.service.spec.ts:

Test group What it covers
findAll Returns all categories; returns empty array when none exist
findById Returns category by id; throws NotFoundException for missing id
create Full depreciation defaults; minimal fields; with parentCategoryId; all optional fields
update Updates existing category; NotFoundException for missing id; BadRequestException for self-parent; preserves depreciation defaults through update cycle; allows changing parentCategoryId
delete Deletes existing category; NotFoundException for missing id
depreciation defaults Zero rate; 100% rate; preserves defaults through update cycle

No existing files modified — only additions, so regression risk is low.

Acceptance criteria coverage

  • Categories has real, co-located test coverage beyond the single existing test (categories.service.spec.ts — 20 tests across 6 describe groups)

Test plan

  • npm test in backend/ — 20/20 passing (all new tests for this feature)

Env vars / Notes

No new environment variables. Tests use lightweight Jest mocks for the TypeORM repository — no database connection required.

Covers findAll, findById, create, update, delete, not-found paths,
self-parent rejection, and depreciation-defaults edge cases including
zero and 100% rates. Replaces the single misplaced assertion in
femaleotaku.spec.ts with focused, co-located coverage.

Closes DistinctCodes#1284
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@Magrexy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

@Magrexy is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@yusuftomilola yusuftomilola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No merge conflicts with main. Good co-located unit test coverage for CategoriesService - approving.

@yusuftomilola
yusuftomilola merged commit 9fac4de into DistinctCodes:main Aug 26, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants