Skip to content

Commit f1273a0

Browse files
committed
test: avoid browser dependency for pinia auth client
1 parent a3eebbb commit f1273a0

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

test/pinia-setup-store.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath } from 'node:url'
2-
import { $fetch, createPage, setup } from '@nuxt/test-utils/e2e'
2+
import { $fetch, setup } from '@nuxt/test-utils/e2e'
33
import { describe, expect, it } from 'vitest'
44

55
describe('pinia setup store auth regression', async () => {
@@ -10,11 +10,4 @@ describe('pinia setup store auth regression', async () => {
1010
it('renders setup stores that expose auth state and client facades', async () => {
1111
await expect($fetch('/')).resolves.toContain('Pinia Auth Store')
1212
})
13-
14-
it('keeps the forwarded auth client callable methods available on client', async () => {
15-
const page = await createPage('/')
16-
17-
await expect(page.getByTestId('client-type').textContent()).resolves.toContain('Client type: object')
18-
await expect(page.getByTestId('verification-type').textContent()).resolves.toContain('Verification type: function')
19-
})
2013
})

test/use-user-session.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2+
import { createPinia, defineStore, setActivePinia } from 'pinia'
23
import { isReactive, isReadonly, isRef, reactive, ref, watch } from 'vue'
34

45
interface SessionState {
@@ -549,6 +550,32 @@ describe('useUserSession hydration bootstrap', () => {
549550
expect(isStateLike((store.signUp as Record<string, unknown>).email)).toBe(false)
550551
})
551552

553+
it('keeps forwarded authClient methods callable in an actual Pinia setup store', async () => {
554+
const rawClient = createDynamicAuthProxy({
555+
useSession: mockClient.useSession,
556+
getSession: mockClient.getSession,
557+
signOut: mockClient.signOut,
558+
signIn: createDynamicAuthProxy(),
559+
signUp: createDynamicAuthProxy(),
560+
$store: mockClient.$store,
561+
})
562+
activeClient = rawClient
563+
setActivePinia(createPinia())
564+
565+
const useUserSession = await loadUseUserSession()
566+
const useAuthStore = defineStore('auth-client-forwarding', () => {
567+
const { client: authClient, ...auth } = useUserSession()
568+
return { authClient, ...auth }
569+
})
570+
const store = useAuthStore()
571+
572+
expect(typeof store.authClient).toBe('object')
573+
expect(typeof (store.authClient as Record<string, unknown>).sendVerificationEmail).toBe('function')
574+
expect(isRef(store.authClient as unknown)).toBe(false)
575+
expect(isReactive(store.authClient as unknown)).toBe(false)
576+
expect(isReactive((store.authClient as Record<string, unknown>).sendVerificationEmail)).toBe(false)
577+
})
578+
552579
it('allows server-side auth method reads but still rejects invocation', async () => {
553580
setRuntimeFlags({ client: false, server: true })
554581

0 commit comments

Comments
 (0)