11import type { User } from "@clerk/backend" ;
22import type { Context } from "@worker/trpc/context" ;
3- import { getUser } from "@worker/trpc/middlewares/auth" ;
3+ import { authFunction } from "@worker/trpc/middlewares/auth" ;
44import { beforeEach , describe , expect , it , mock } from "bun:test" ;
55
66// Mock the Clerk module
@@ -13,7 +13,7 @@ mock.module("@clerk/backend", () => ({
1313 createClerkClient : mockCreateClerkClient ,
1414} ) ) ;
1515
16- describe ( "getUser " , ( ) => {
16+ describe ( "authFunction " , ( ) => {
1717 let mockContext : Context ;
1818
1919 beforeEach ( ( ) => {
@@ -51,7 +51,7 @@ describe("getUser", () => {
5151 mockGetUser . mockResolvedValue ( mockUser ) ;
5252
5353 // When
54- const result = await getUser ( mockContext ) ;
54+ const result = await authFunction ( mockContext ) ;
5555
5656 // Then
5757 expect ( result ) . toBe ( mockUser ) ;
@@ -77,7 +77,7 @@ describe("getUser", () => {
7777 mockToAuth . mockReturnValue ( mockAuth ) ;
7878
7979 // When & Then
80- expect ( getUser ( mockContext ) ) . rejects . toThrow ( "User is not authenticated" ) ;
80+ expect ( authFunction ( mockContext ) ) . rejects . toThrow ( "User is not authenticated" ) ;
8181 expect ( mockGetUser ) . not . toHaveBeenCalled ( ) ;
8282 } ) ;
8383
@@ -87,7 +87,7 @@ describe("getUser", () => {
8787 mockAuthenticateRequest . mockRejectedValue ( clerkError ) ;
8888
8989 // When & Then
90- expect ( getUser ( mockContext ) ) . rejects . toThrow ( "Clerk API error" ) ;
90+ expect ( authFunction ( mockContext ) ) . rejects . toThrow ( "Clerk API error" ) ;
9191 expect ( mockGetUser ) . not . toHaveBeenCalled ( ) ;
9292 } ) ;
9393} ) ;
0 commit comments