aglinxinyuan opened a new issue, #5780:
URL: https://github.com/apache/texera/issues/5780
### Task Summary
Add `admin-guard.service.spec.ts` that pins the route-guard behavior of
`AdminGuardService.canActivate()`: admins are allowed through, non-admins are
blocked and redirected.
## Background
`AdminGuardService`
(`frontend/src/app/dashboard/service/admin/guard/admin-guard.service.ts`)
implements Angular's `CanActivate`. It allows navigation when
`UserService.isAdmin()` is `true`; otherwise it redirects to `USER_WORKFLOW`
and returns `false`. It has no spec.
```ts
canActivate(): boolean {
if (this.userService.isAdmin()) {
return true;
} else {
this.router.navigate([USER_WORKFLOW]);
return false;
}
}
```
## Behavior to pin
| Scenario | Contract |
| --- | --- |
| user is an admin | `canActivate()` returns `true` and `Router.navigate` is
NOT called |
| user is not an admin | `canActivate()` returns `false` and
`Router.navigate` is called with `[USER_WORKFLOW]` |
## Scope
- New spec: `admin-guard.service.spec.ts` next to the service.
- Use `TestBed` + Vitest (`vi.fn()`); provide `UserService` via
`StubUserService` (drive `isAdmin()` by setting the stub user's `role` to
`Role.ADMIN` / `Role.REGULAR`) and a `Router` spy. Mirror the existing
`frontend/src/app/common/service/user/auth-guard.service.spec.ts`.
- No production-code changes.
### Task Type
- [ ] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [x] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]