Skip to content

Commit f255055

Browse files
committed
Cleanup mock-auth
1 parent 2683b65 commit f255055

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

test/mock-auth.mts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@ import type { CResult } from '../src/types.mts'
2525

2626
export interface MockAuthOptions {
2727
/** Whether the operation should succeed. */
28-
shouldSucceed?: boolean
28+
shouldSucceed?: boolean | undefined
2929
/** Custom delay in milliseconds to simulate network latency. */
30-
delay?: number
30+
delay?: number | undefined
3131
/** Custom error message for failure scenarios. */
32-
errorMessage?: string
32+
errorMessage?: string | undefined
3333
/** Custom response data for success scenarios. */
34-
responseData?: any
34+
responseData?: any | undefined
3535
}
3636

3737
export interface MockLoginOptions extends MockAuthOptions {
3838
/** Mock email address for login. */
39-
email?: string
39+
email?: string | undefined
4040
/** Mock organization slug. */
41-
orgSlug?: string
41+
orgSlug?: string | undefined
4242
/** Mock API token to return. */
43-
apiToken?: string
43+
apiToken?: string | undefined
4444
/** Whether to simulate MFA requirement. */
45-
requireMfa?: boolean
45+
requireMfa?: boolean | undefined
4646
}
4747

4848
export interface MockTokenOptions extends MockAuthOptions {
4949
/** The token to validate. */
50-
token?: string
50+
token?: string | undefined
5151
/** Token permissions/scopes. */
52-
scopes?: string[]
52+
scopes?: string[] | readonly string[] | undefined
5353
/** Token expiration time. */
54-
expiresAt?: Date
54+
expiresAt?: Date | undefined
5555
}
5656

5757
export interface MockOrgOptions extends MockAuthOptions {
@@ -61,11 +61,15 @@ export interface MockOrgOptions extends MockAuthOptions {
6161
slug: string
6262
name: string
6363
role: string
64-
}>
64+
}> | undefined
6565
/** Selected organization index. */
66-
selectedIndex?: number
66+
selectedIndex?: number | undefined
6767
}
6868

69+
const MILLISECONDS_1_DAY = Date.now() + 24 * 60 * 60 * 1000
70+
71+
const MILLISECONDS_30_DAYS = Date.now() + 30 * 24 * 60 * 60 * 1000
72+
6973
/**
7074
* Simulate a delay for realistic async behavior.
7175
*/
@@ -77,7 +81,7 @@ function simulateDelay(ms: number): Promise<void> {
7781
* Mock interactive login flow.
7882
*/
7983
export async function mockInteractiveLogin(
80-
options?: MockLoginOptions,
84+
options?: MockLoginOptions | undefined,
8185
): Promise<CResult<{ apiToken: string; orgSlug: string }>> {
8286
const {
8387
apiToken = 'test-token-123',
@@ -124,7 +128,7 @@ export async function mockApiTokenAuth(
124128
const {
125129
delay = 50,
126130
errorMessage = 'Invalid token',
127-
expiresAt = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days.
131+
expiresAt = new Date(MILLISECONDS_30_DAYS),
128132
scopes = ['read', 'write'],
129133
shouldSucceed = true,
130134
token = 'test-token',
@@ -465,7 +469,7 @@ export async function mockValidateSession(
465469
data: {
466470
valid: isValid,
467471
expiresAt: isValid
468-
? new Date(Date.now() + 24 * 60 * 60 * 1000) // 24 hours.
472+
? new Date(MILLISECONDS_1_DAY)
469473
: undefined,
470474
},
471475
}

0 commit comments

Comments
 (0)