- tests_/mercado-interval-helpers.test.ts
- tests_/unit/employee/profile.test.ts
- tests_/unit/employee/notifications.test.ts
- tests_/unit/employee/employee-stats.test.ts
- tests_/unit/employee/employee-mercado.test.ts
- tests_/unit/employee/employee-leaderboard.test.ts
- tests_/unit/shared/attendance.test.ts
- tests_/unit/manager/badge-editor.test.ts
- tests_/unit/manager/badge-assignment.test.ts
- tests_/unit/manager/assigned-tasks.test.ts
- tests_/unit/manager/task-verification.test.ts
- tests_/unit/hr/hr-leaderboard.test.ts
- tests_/unit/hr/mercado-items.test.ts
- tests_/unit/hr/rewards-requests.test.ts
- tests_/unit/superadmin/superadmin.test.ts
TEST COVERAGE FOR MERCADO INTERVAL HELPERS
Describe: Mercado interval helpers
- marks weekly items as expired after Saturday
- weekly date ranges span Monday through Saturday
TEST COVERAGE FOR EMPLOYEE PROFILE (UNIT)
Describe: When the employee loads a profile
- fetchUserProfileById action returns normalized profile details
- fetchUserProfileById action returns a readable error when the profile is missing
- fetchUserProfileByIdHandler returns null and shows a toast when the action reports an error Describe: When the employee updates their own profile
- updateOwnProfile action sends only the editable profile fields to the RPC
- updateOwnProfile action blocks the request when there is no active session
- updateOwnProfileHandler returns null and shows a toast when the action fails Describe: When the employee uploads a profile picture
- uploadOwnProfilePicture action stores the file in the employees bucket
- uploadOwnProfilePictureHandler returns null and shows a toast when the action fails Describe: When the employee removes a profile picture
- deleteOwnProfilePicture action removes the storage object for the current user
- deleteOwnProfilePictureHandler returns false and shows a toast when the action fails
TEST COVERAGE FOR EMPLOYEE NOTIFICATIONS (UNIT)
Describe: When the employee opens the notifications list
- fetchNotifications action returns normalized notification items
- fetchNotifications action stops when the employee is not authenticated
- handleFetchNotifications handler forwards the action error without showing a toast Describe: When the employee marks a single notification as read
- markNotificationRead action updates the current notification row
- handleMarkNotificationRead handler returns an error and shows a toast when the action fails Describe: When the employee marks all notifications as read
- markAllNotificationsRead action updates every unread notification for the current employee
- handleMarkAllNotificationsRead handler shows a success toast after the action succeeds
TEST COVERAGE FOR EMPLOYEE STATS (UNIT)
Describe: When the employee reads points and XP data
- getEmployeePoints action returns the current points and deducted points
- getEmployeeXP action falls back to derived total XP when the stored total is missing
- handleFetchEmployeePoints handler returns the points data without showing a toast
- handleFetchEmployeeXP handler returns null and shows an error toast when the action fails Describe: When the employee reads level thresholds
- getXPRequiredForNextLevel action returns zero at the level cap
- getAllLevelMetadata action returns the fallback level list when the Level table is empty
- handlers return threshold and metadata data without showing error toasts on the happy path Describe: When the employee adjusts active XP for level progression
- adjustActiveUserXPByDelta action updates XP, total XP, and level using the level thresholds
- adjustActiveUserXPByDelta action floors total XP at zero when a large negative delta is applied
- handleAdjustActiveUserXPByDelta handler returns null and shows an error toast when the update fails
TEST COVERAGE FOR EMPLOYEE MERCADO (UNIT)
Describe: When the employee loads Mercado page data
- useMercadoPageData returns available rewards, pending requests, and points
- useMercadoPageData disables reward loading when includeRewards is false
- useMercadoPageData surfaces loading when any underlying query is loading
- useMercadoPageData preserves reward query errors only when rewards are included Describe: When the employee orders and cancels Mercado items
- handleCreateRedemptionRequestAction returns true when the order request succeeds
- handleCreateRedemptionRequestAction returns false and shows an error toast when ordering fails
- handleCancelMyRedemptionRequestAction returns true when cancellation succeeds
- handleCancelMyRedemptionRequestAction returns false and shows an error toast when cancellation fails
TEST COVERAGE FOR EMPLOYEE LEADERBOARD (UNIT)
Describe: When the employee reads leaderboard snapshots
- getEmployeeRank action returns rank, performance score, and total employees
- getEmployeeTopWeeklyRanks action returns mapped top entries with profile URLs
- getEmployeeTopRanksByPeriod action returns null when no visible rows exist for the period Describe: When employee leaderboard handlers process action responses
- leaderboard handlers return data without showing error toasts on the happy path
- period leaderboard handler returns null and shows an error toast when the user is unauthenticated
TEST COVERAGE FOR ATTENDANCE (UNIT)
Describe: When the employee loads attendance configuration data
- getAttendanceConfigAction action returns the configured attendance windows
- handleGetAttendanceConfig handler forwards the configuration without showing an error toast Describe: When the employee loads the attendance timeline
- getTodayAttendanceTimelineAction action returns the ordered timeline with late, break, and undertime notes
- handleGetTodayAttendanceTimeline handler returns the timeline entries when the action succeeds Describe: When the employee loads the current attendance status
- getTodayAttendanceStatusAction action auto-marks the day absent when no time in exists after timeout
- handleGetTodayAttendanceStatus handler returns the current break state without showing a toast Describe: When the employee records attendance actions
- timeInAttendanceAction action creates the first attendance log for the day
- timeOutAttendanceAction action prevents timing out while the employee is still on break
- startBreakAction action starts the current break and the handler shows a success toast
- endBreakAction action marks the break as over duration when it exceeds the configured limit
- handleTimeOutAttendance handler updates the log and shows a success toast after timing out
- handleTimeInAttendance handler returns an error and shows a toast when time in is outside the allowed window
- handleEndBreak handler shows the over-break toast when the employee exceeded the break duration
TEST COVERAGE FOR BADGE EDITOR (UNIT)
Describe: Badge Editor Server Actions
- fetchBadges returns normalized badges
- fetchBadges returns error on query failure
- fetch badge options returns task options
- fetch badge options handles task option error
- fetch badge options attribute options are static
- fetch badge options attendance options are static
- uploadBadgeImage rejects oversized file
- uploadBadgeImage rejects unsupported type
- uploadBadgeImage returns error when upload fails
- uploadBadgeImage returns error when update fails
- uploadBadgeImage uploads and returns public url
- deleteBadgeImage removes image and clears column
- deleteBadgeImage handles storage removal error
- deleteBadgeImage handles badge image clear error
- addBadge rejects invalid input
- addBadge creates badge with requirements
- addBadge returns error when badge insert fails
- addBadge returns error when requirement insert fails
- editBadge updates badge and replaces requirements
- editBadge returns error when update fails
- editBadge returns error when requirement reinsertion fails
- deleteBadge removes badge and requirements
- deleteBadge returns error when delete fails Describe: Badge Editor Handlers (safeAction + toasts)
- handleFetchBadges returns data and no toast
- handleFetchBadges surfaces error
- handleAddBadge shows success toast
- handleAddBadge shows error toast on failure
- handleEditBadge respects suppressToast
- handleDeleteBadge returns false on error
- handleUploadBadgeImage returns url and invalidates cache flag via toast
- handleUploadBadgeImage returns null on failure
- handleDeleteBadgeImage returns false on error
TEST COVERAGE FOR BADGE ASSIGNMENT (UNIT)
Describe: When the manager loads manual badges
- fetchManualBadges action returns only manual badges from the admin client
- handleFetchManualBadges handler returns an empty array and shows a toast when the query fails Describe: When the manager loads badge assignment users
- fetchBadgeAssignmentUsers action returns users with collected badges and profile URLs
- handleFetchBadgeAssignmentUsers handler returns an empty array and shows a toast when collected badges fail to load Describe: When the manager awards a manual badge
- assignManualBadgeToUser action creates the award, updates user points, and inserts a notification
- handleAssignManualBadgeToUser handler returns false and shows a toast when the user already has the badge Describe: When the manager loads badge award debug entries
- fetchBadgeAwardDebugEntries action returns the normalized debug rows
- handleFetchBadgeAwardDebugEntries handler returns an empty array and shows a toast when the manager is unauthorized Describe: When the manager removes a badge award
- removeBadgeAward action deletes the award and deducts the badge points from the user
- handleRemoveBadgeAward handler returns false and shows a toast when the delete fails Describe: When the manager loads the full badge catalog
- fetchAllBadges action returns both manual and automatic badges
TEST COVERAGE FOR ASSIGNED TASKS (UNIT)
Describe: When the manager loads assigned-task data through handlers
- task-view pagination handler returns assigned-task payload without error toast
- employee-view pagination handler returns assigned-task payload without error toast Describe: When the manager clears or deletes assigned tasks through handlers
- clear-unstarted-by-employee handler returns cleared count and shows success toast
- delete-task handler returns false and shows an error toast when action fails
TEST COVERAGE FOR TASK VERIFICATION (UNIT)
Describe: When the manager loads tasks that need review
- fetchTasksToReview action returns the in-review tasks from the task view
- fetchTasksToReviewPaginated action returns paginated data and total pages
- handleFetchTasksToReview handler returns an empty list and shows a toast when the action fails Describe: When the manager loads approved or rejected tasks
- approved and denied task actions return the expected task collections
- paginated approved and denied task handlers return fallback pagination when the action fails Describe: When the manager approves a task submission
- approveTaskAction updates the task, clears pending orders, and creates a notification
- handleApproveTask handler returns null and shows a toast when the action fails Describe: When the manager rejects a task submission
- rejectTaskAction updates the task and creates a rejection notification
- handleRejectTask handler returns null and shows a toast when the action fails
TEST COVERAGE FOR HR LEADERBOARD (UNIT)
Describe: When HR generates leaderboard rankings through the action handler
- generate handler returns rows when the wrapped server action succeeds
- generate handler throws when the wrapped server action result contains an error Describe: When HR toggles leaderboard visibility through the action handler
- visibility handler returns the updated row when the wrapped action succeeds
- visibility handler throws when the wrapped action returns missing data
TEST COVERAGE FOR HR MERCADO ITEMS (UNIT)
Describe: When HR loads Mercado items
- getRewardsAction returns transformed items with redeemed counts and stock flags
- handleGetRewardsAction throws when reward loading fails Describe: When HR adds and edits Mercado items
- addRewardAction creates a new item with normalized fields
- handleAddRewardAction returns the new item and shows a success toast
- handleAddRewardAction returns null and shows a toast for invalid redeeming limit
- editRewardAction updates an existing item and preserves the reward record
- handleEditRewardAction returns the updated item and shows a success toast
- handleEditRewardAction returns null and shows a toast when validation fails
- editRewardAction blocks redeeming limit above current quantity when quantity is not included Describe: When HR updates Mercado item visibility and lifecycle
- hideRewardAction marks an item as hidden
- handleHideRewardAction returns true and shows a success toast on unhide
- deleteRewardAction removes the item and its storage picture
- handleDeleteRewardAction returns true and shows a success toast
- handleDeleteRewardAction returns false and shows a toast when delete fails Describe: When HR uploads Mercado item pictures
- uploadRewardPicture returns a public URL for a valid image
- handleUploadRewardPicture rejects oversized images before upload
TEST COVERAGE FOR HR REWARD REQUESTS (UNIT)
Describe: When HR loads reward requests
- getRedemptionRequestsAction returns pending requests with transformed fields
- handleGetRedemptionRequestsAction throws when fetch fails
- getRedemptionRequestsAction excludes employee-cancelled rows in rejected filter Describe: When HR accepts a pending request
- acceptRedemptionRequestAction approves the request, deducts stock, and creates a notification
- handleAcceptRedemptionRequestAction returns an error payload and shows a toast when the request is already processed Describe: When HR declines a pending request
- declineRedemptionRequestAction rejects the request, refunds points, restores stock, and creates a notification
- handleDeclineRedemptionRequestAction returns success and shows the success toast with remarks
TEST COVERAGE FOR SUPERADMIN USERS (UNIT)
Describe: fetchUsersAction
- returns users when fetch succeeds
- throws when fetch fails Describe: fetchUsersPaginatedAction
- returns paginated data on success
- returns error when fetch rejects Describe: addUserAction
- rejects invalid input (email)
- creates user when backend succeeds
- returns error when backend returns error Describe: editUserAction
- rejects invalid input
- updates user via rpc when valid
- changes password before rpc when provided
- propagates rpc error Describe: deleteUserAction
- deletes user and profile picture
- returns error when profile removal fails Describe: uploadProfilePicture
- returns public URL when file exists
- fails when file missing Describe: deleteProfilePicture
- removes picture successfully
- returns error on storage failure Describe: API Routes
- adduser route creates user and writes to memDb
- adduser route rejects duplicate email
- changepw route updates password with valid input
- changepw route rejects short password
- deluser route deletes existing user
- deluser route returns error when user missing
- filter route filters by role and paginates Describe: Error Handling and Edge Cases
- adduser route handles malformed JSON
- addUserAction rejects whitespace-only name via zod
- editUserAction rejects long address