test: add tests for NamespaceService #80

Open
Charon wants to merge 1 commit from feat/test-namespace-service into dev
Member

Closes #30

Summary

  • Add comprehensive test suite for Services/NamespaceService.php (40 test cases)
  • Cover all public methods: current(), setCurrent(), clearCurrent(), currentUuid(), findByUuid(), findBySlug(), defaultForUser(), defaultForCurrentUser(), canAccess(), accessibleByUser(), accessibleByCurrentUser(), ownedByUser(), ownedByWorkspace(), groupedForUser(), groupedForCurrentUser(), invalidateUserCache(), invalidateCache()

Test coverage areas

  • current() resolution: request attributes, session UUID, fallback to default, access rejection, unauthenticated
  • Session management: set from model/string, get UUID, clear, null when empty
  • Namespace lookup: findByUuid with caching, findBySlug per owner context, null for missing/wrong context
  • Default resolution: is_default priority, fallback to first active, fallback to workspace, null for lonely user, skip inactive
  • Access control: owner access, workspace member access, deny cross-user, deny cross-workspace, deny unauthenticated
  • Collections: ownedByUser, ownedByWorkspace, accessibleByUser, inactive exclusion, caching
  • groupedForUser: personal vs workspace separation, inactive workspace exclusion, multi-workspace
  • Cache invalidation: user cache, UUID cache

Uses Pest syntax following existing test patterns.

Closes #30 ## Summary - Add comprehensive test suite for `Services/NamespaceService.php` (40 test cases) - Cover all public methods: `current()`, `setCurrent()`, `clearCurrent()`, `currentUuid()`, `findByUuid()`, `findBySlug()`, `defaultForUser()`, `defaultForCurrentUser()`, `canAccess()`, `accessibleByUser()`, `accessibleByCurrentUser()`, `ownedByUser()`, `ownedByWorkspace()`, `groupedForUser()`, `groupedForCurrentUser()`, `invalidateUserCache()`, `invalidateCache()` ## Test coverage areas - **current() resolution**: request attributes, session UUID, fallback to default, access rejection, unauthenticated - **Session management**: set from model/string, get UUID, clear, null when empty - **Namespace lookup**: findByUuid with caching, findBySlug per owner context, null for missing/wrong context - **Default resolution**: is_default priority, fallback to first active, fallback to workspace, null for lonely user, skip inactive - **Access control**: owner access, workspace member access, deny cross-user, deny cross-workspace, deny unauthenticated - **Collections**: ownedByUser, ownedByWorkspace, accessibleByUser, inactive exclusion, caching - **groupedForUser**: personal vs workspace separation, inactive workspace exclusion, multi-workspace - **Cache invalidation**: user cache, UUID cache Uses Pest syntax following existing test patterns.
Charon added 1 commit 2026-03-24 13:52:25 +00:00
Cover current() resolution (request attributes, session, fallback),
session management (set/get/clear), findByUuid/findBySlug lookups,
defaultForUser priority chain, access control (owner/member/deny),
collection methods (ownedBy, accessibleBy), groupedForUser grouping,
and cache invalidation. 40 test cases using Pest syntax.

Fixes #30

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/test-namespace-service:feat/test-namespace-service
git checkout feat/test-namespace-service

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/test-namespace-service
git checkout feat/test-namespace-service
git rebase dev
git checkout dev
git merge --ff-only feat/test-namespace-service
git checkout feat/test-namespace-service
git rebase dev
git checkout dev
git merge --no-ff feat/test-namespace-service
git checkout dev
git merge --squash feat/test-namespace-service
git checkout dev
git merge --ff-only feat/test-namespace-service
git checkout dev
git merge feat/test-namespace-service
git push origin dev
Sign in to join this conversation.
No description provided.