From 08c121c21a7e429e43e2d51fa4a3d8bd945c5d01 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 16 Feb 2026 21:51:17 +0900 Subject: test(backend): add unit tests for admin handlers and taskqueue Add comprehensive tests for previously untested packages: - admin: middleware auth checks, CRUD handlers for users/games/problems/testcases - taskqueue: task creation, payload serialization, code hash calculation - api: expose SetUserInContext helper for cross-package test support Co-Authored-By: Claude Opus 4.6 --- backend/api/auth_middleware.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'backend/api/auth_middleware.go') diff --git a/backend/api/auth_middleware.go b/backend/api/auth_middleware.go index 0b0dfc8..94ef4e4 100644 --- a/backend/api/auth_middleware.go +++ b/backend/api/auth_middleware.go @@ -42,3 +42,8 @@ func GetUserFromContext(ctx context.Context) (*db.User, bool) { user, ok := ctx.Value(userContextKey{}).(*db.User) return user, ok } + +// SetUserInContext sets a user in the context. Intended for testing. +func SetUserInContext(ctx context.Context, user *db.User) context.Context { + return context.WithValue(ctx, userContextKey{}, user) +} -- cgit v1.3.1