@rsweeten/dropbox-sync 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.github/workflows/test-pr.yml +30 -0
  2. package/README.md +521 -315
  3. package/__mocks__/nuxt/app.js +20 -0
  4. package/dist/adapters/__tests__/angular.spec.d.ts +1 -0
  5. package/dist/adapters/__tests__/angular.spec.js +237 -0
  6. package/dist/adapters/__tests__/next.spec.d.ts +1 -0
  7. package/dist/adapters/__tests__/next.spec.js +179 -0
  8. package/dist/adapters/__tests__/nuxt.spec.d.ts +1 -0
  9. package/dist/adapters/__tests__/nuxt.spec.js +145 -0
  10. package/dist/adapters/__tests__/svelte.spec.d.ts +1 -0
  11. package/dist/adapters/__tests__/svelte.spec.js +149 -0
  12. package/dist/core/__tests__/auth.spec.d.ts +1 -0
  13. package/dist/core/__tests__/auth.spec.js +83 -0
  14. package/dist/core/__tests__/client.spec.d.ts +1 -0
  15. package/dist/core/__tests__/client.spec.js +102 -0
  16. package/dist/core/__tests__/socket.spec.d.ts +1 -0
  17. package/dist/core/__tests__/socket.spec.js +122 -0
  18. package/dist/core/__tests__/sync.spec.d.ts +1 -0
  19. package/dist/core/__tests__/sync.spec.js +375 -0
  20. package/dist/core/sync.js +30 -11
  21. package/jest.config.js +24 -0
  22. package/jest.setup.js +38 -0
  23. package/package.json +77 -74
  24. package/src/adapters/__tests__/angular.spec.ts +338 -0
  25. package/src/adapters/__tests__/next.spec.ts +240 -0
  26. package/src/adapters/__tests__/nuxt.spec.ts +185 -0
  27. package/src/adapters/__tests__/svelte.spec.ts +194 -0
  28. package/src/core/__tests__/auth.spec.ts +142 -0
  29. package/src/core/__tests__/client.spec.ts +128 -0
  30. package/src/core/__tests__/socket.spec.ts +153 -0
  31. package/src/core/__tests__/sync.spec.ts +508 -0
  32. package/src/core/sync.ts +503 -476
@@ -0,0 +1,240 @@
1
+ import {
2
+ useNextDropboxSync,
3
+ getCredentialsFromCookies,
4
+ handleOAuthCallback,
5
+ createNextDropboxApiHandlers,
6
+ } from '../next'
7
+ import { createDropboxSyncClient } from '../../core/client'
8
+ import { cookies } from 'next/headers'
9
+ import { NextRequest, NextResponse } from 'next/server'
10
+
11
+ // Mock dependencies
12
+ jest.mock('../../core/client')
13
+ jest.mock('next/headers')
14
+ jest.mock('next/server')
15
+
16
+ describe('Next.js adapter', () => {
17
+ beforeEach(() => {
18
+ jest.clearAllMocks()
19
+
20
+ // Mock process.env
21
+ process.env.DROPBOX_APP_KEY = 'test-app-key'
22
+ process.env.DROPBOX_APP_SECRET = 'test-app-secret'
23
+ process.env.NEXT_PUBLIC_APP_URL = 'https://example.com'
24
+ })
25
+
26
+ describe('useNextDropboxSync', () => {
27
+ it('should create a Dropbox sync client with provided credentials', () => {
28
+ const mockCredentials = {
29
+ clientId: 'custom-client-id',
30
+ clientSecret: 'custom-client-secret',
31
+ }
32
+
33
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue({
34
+ mock: 'client',
35
+ })
36
+
37
+ const result = useNextDropboxSync(mockCredentials)
38
+
39
+ expect(createDropboxSyncClient).toHaveBeenCalledWith(
40
+ mockCredentials
41
+ )
42
+ expect(result).toEqual({ mock: 'client' })
43
+ })
44
+ })
45
+
46
+ describe('getCredentialsFromCookies', () => {
47
+ it('should get credentials from cookies', async () => {
48
+ const mockCookieStore = {
49
+ get: jest.fn((name) => {
50
+ if (name === 'dropbox_access_token')
51
+ return { value: 'test-access-token' }
52
+ if (name === 'dropbox_refresh_token')
53
+ return { value: 'test-refresh-token' }
54
+ return null
55
+ }),
56
+ }
57
+
58
+ ;(cookies as jest.Mock).mockResolvedValue(mockCookieStore)
59
+
60
+ const credentials = await getCredentialsFromCookies()
61
+
62
+ expect(cookies).toHaveBeenCalled()
63
+ expect(credentials).toEqual({
64
+ clientId: 'test-app-key',
65
+ clientSecret: 'test-app-secret',
66
+ accessToken: 'test-access-token',
67
+ refreshToken: 'test-refresh-token',
68
+ })
69
+ })
70
+
71
+ it('should handle missing cookie values', async () => {
72
+ const mockCookieStore = {
73
+ get: jest.fn().mockReturnValue(null),
74
+ }
75
+
76
+ ;(cookies as jest.Mock).mockResolvedValue(mockCookieStore)
77
+
78
+ const credentials = await getCredentialsFromCookies()
79
+
80
+ expect(credentials).toEqual({
81
+ clientId: 'test-app-key',
82
+ clientSecret: 'test-app-secret',
83
+ accessToken: undefined,
84
+ refreshToken: undefined,
85
+ })
86
+ })
87
+ })
88
+
89
+ describe('handleOAuthCallback', () => {
90
+ it('should handle successful OAuth callback', async () => {
91
+ // Mock URL with auth code
92
+ const mockRequest = {
93
+ url: 'https://example.com/callback?code=test-auth-code',
94
+ } as unknown as NextRequest
95
+
96
+ // Mock URL constructor behavior
97
+ ;(global as any).URL = jest.fn().mockImplementation(() => {
98
+ return {
99
+ searchParams: {
100
+ get: jest.fn().mockReturnValue('test-auth-code'),
101
+ },
102
+ }
103
+ })
104
+
105
+ // Mock Dropbox client
106
+ const mockClient = {
107
+ auth: {
108
+ exchangeCodeForToken: jest.fn().mockResolvedValue({
109
+ accessToken: 'new-access-token',
110
+ refreshToken: 'new-refresh-token',
111
+ expiresAt: Date.now() + 14400 * 1000,
112
+ }),
113
+ },
114
+ }
115
+
116
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue(mockClient)
117
+
118
+ // Mock NextResponse
119
+ const mockResponseCookies = {
120
+ set: jest.fn(),
121
+ }
122
+
123
+ const mockResponse = {
124
+ cookies: mockResponseCookies,
125
+ }
126
+
127
+ ;(NextResponse.redirect as jest.Mock).mockReturnValue(mockResponse)
128
+
129
+ await handleOAuthCallback(mockRequest)
130
+
131
+ expect(createDropboxSyncClient).toHaveBeenCalled()
132
+ expect(mockClient.auth.exchangeCodeForToken).toHaveBeenCalledWith(
133
+ 'test-auth-code',
134
+ expect.any(String)
135
+ )
136
+ expect(NextResponse.redirect).toHaveBeenCalled()
137
+ expect(mockResponseCookies.set).toHaveBeenCalledTimes(3) // Access, refresh, and connected cookies
138
+ })
139
+
140
+ it('should redirect to error page if code is missing', async () => {
141
+ const mockRequest = {
142
+ url: 'https://example.com/callback',
143
+ } as unknown as NextRequest
144
+
145
+ ;(global as any).URL = jest.fn().mockImplementation(() => {
146
+ return {
147
+ searchParams: {
148
+ get: jest.fn().mockReturnValue(null),
149
+ },
150
+ }
151
+ })
152
+
153
+ // Create a proper URL string for the mock response
154
+ const errorUrl = 'https://example.com/auth/error'
155
+
156
+ // Mock the redirect implementation to return this URL
157
+ ;(NextResponse.redirect as jest.Mock).mockReturnValue({
158
+ url: errorUrl,
159
+ })
160
+
161
+ const result = await handleOAuthCallback(mockRequest)
162
+
163
+ // Now we'll check that the redirect was called, and the result contains our URL
164
+ expect(NextResponse.redirect).toHaveBeenCalled()
165
+ expect(result.url).toBe(errorUrl)
166
+ })
167
+ })
168
+
169
+ describe('createNextDropboxApiHandlers', () => {
170
+ it('should create API handlers with necessary methods', () => {
171
+ const handlers = createNextDropboxApiHandlers()
172
+
173
+ expect(handlers).toHaveProperty('status')
174
+ expect(handlers).toHaveProperty('oauthStart')
175
+ expect(handlers).toHaveProperty('logout')
176
+ })
177
+
178
+ it('should check status from cookies', async () => {
179
+ const mockCookieStore = {
180
+ get: jest.fn().mockReturnValue({ value: 'test-token' }),
181
+ }
182
+
183
+ ;(cookies as jest.Mock).mockResolvedValue(mockCookieStore)
184
+ ;(NextResponse.json as jest.Mock).mockReturnValue({
185
+ json: 'response',
186
+ })
187
+
188
+ const handlers = createNextDropboxApiHandlers()
189
+ const response = await handlers.status()
190
+
191
+ expect(cookies).toHaveBeenCalled()
192
+ expect(mockCookieStore.get).toHaveBeenCalledWith(
193
+ 'dropbox_access_token'
194
+ )
195
+ expect(NextResponse.json).toHaveBeenCalledWith({ connected: true })
196
+ })
197
+
198
+ it('should start OAuth flow', async () => {
199
+ const mockClient = {
200
+ auth: {
201
+ getAuthUrl: jest
202
+ .fn()
203
+ .mockResolvedValue('https://dropbox.com/oauth'),
204
+ },
205
+ }
206
+
207
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue(mockClient)
208
+ ;(NextResponse.redirect as jest.Mock).mockReturnValue({
209
+ redirect: 'response',
210
+ })
211
+
212
+ const handlers = createNextDropboxApiHandlers()
213
+ const response = await handlers.oauthStart()
214
+
215
+ expect(createDropboxSyncClient).toHaveBeenCalled()
216
+ expect(mockClient.auth.getAuthUrl).toHaveBeenCalled()
217
+ expect(NextResponse.redirect).toHaveBeenCalledWith(
218
+ 'https://dropbox.com/oauth'
219
+ )
220
+ })
221
+
222
+ it('should handle logout', async () => {
223
+ const mockResponseCookies = {
224
+ delete: jest.fn(),
225
+ }
226
+
227
+ const mockResponse = {
228
+ cookies: mockResponseCookies,
229
+ }
230
+
231
+ ;(NextResponse.json as jest.Mock).mockReturnValue(mockResponse)
232
+
233
+ const handlers = createNextDropboxApiHandlers()
234
+ const response = await handlers.logout()
235
+
236
+ expect(NextResponse.json).toHaveBeenCalledWith({ success: true })
237
+ expect(mockResponseCookies.delete).toHaveBeenCalledTimes(3) // Should delete three cookies
238
+ })
239
+ })
240
+ })
@@ -0,0 +1,185 @@
1
+ import {
2
+ useNuxtDropboxSync,
3
+ getCredentialsFromCookies,
4
+ createNuxtApiHandlers,
5
+ } from '../nuxt'
6
+ import { createDropboxSyncClient } from '../../core/client'
7
+ import type { H3Event } from 'h3'
8
+
9
+ // Mock dependencies
10
+ jest.mock('../../core/client')
11
+
12
+ // Manual mocks for Nuxt modules
13
+ jest.mock('nuxt/app', () => ({
14
+ useRuntimeConfig: jest.fn().mockReturnValue({
15
+ public: {
16
+ dropboxAppKey: 'test-app-key',
17
+ appUrl: 'https://example.com',
18
+ },
19
+ dropboxAppSecret: 'test-app-secret',
20
+ dropboxRedirectUri: 'https://example.com/api/dropbox/auth/callback',
21
+ }),
22
+ useCookie: jest.fn().mockImplementation((name) => {
23
+ if (name === 'dropbox_access_token') {
24
+ return { value: 'test-access-token' }
25
+ }
26
+ if (name === 'dropbox_refresh_token') {
27
+ return { value: 'test-refresh-token' }
28
+ }
29
+ return { value: null }
30
+ }),
31
+ }))
32
+
33
+ // Mock H3 utilities
34
+ const mockGetCookie = jest.fn()
35
+ const mockSetCookie = jest.fn()
36
+ const mockDeleteCookie = jest.fn()
37
+ const mockGetQuery = jest.fn()
38
+ const mockSendRedirect = jest.fn()
39
+
40
+ jest.mock('h3', () => ({
41
+ getCookie: mockGetCookie,
42
+ setCookie: mockSetCookie,
43
+ deleteCookie: mockDeleteCookie,
44
+ getQuery: mockGetQuery,
45
+ sendRedirect: mockSendRedirect,
46
+ }))
47
+
48
+ describe('Nuxt.js adapter', () => {
49
+ beforeEach(() => {
50
+ jest.clearAllMocks()
51
+
52
+ // Define process.client as a property for client/server detection
53
+ if (!('client' in process)) {
54
+ Object.defineProperty(process, 'client', {
55
+ value: false,
56
+ writable: true,
57
+ configurable: true,
58
+ })
59
+ } else {
60
+ ;(process as any).client = false
61
+ }
62
+ })
63
+
64
+ describe('useNuxtDropboxSync', () => {
65
+ it('should create a Dropbox sync client with config values', () => {
66
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue({
67
+ mock: 'client',
68
+ })
69
+
70
+ const result = useNuxtDropboxSync()
71
+
72
+ expect(createDropboxSyncClient).toHaveBeenCalledWith({
73
+ clientId: 'test-app-key',
74
+ clientSecret: 'test-app-secret',
75
+ })
76
+ expect(result).toEqual({ mock: 'client' })
77
+ })
78
+
79
+ it('should add cookie values on client-side', () => {
80
+ // Set as client-side
81
+ ;(process as any).client = true
82
+
83
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue({
84
+ mock: 'client',
85
+ })
86
+
87
+ const result = useNuxtDropboxSync()
88
+
89
+ expect(createDropboxSyncClient).toHaveBeenCalledWith(
90
+ expect.objectContaining({
91
+ clientId: 'test-app-key',
92
+ clientSecret: 'test-app-secret',
93
+ accessToken: 'test-access-token',
94
+ refreshToken: 'test-refresh-token',
95
+ })
96
+ )
97
+ })
98
+ })
99
+
100
+ describe('getCredentialsFromCookies', () => {
101
+ it('should get credentials from H3 event', () => {
102
+ const mockEvent = {} as H3Event
103
+
104
+ // Set up mock implementation
105
+ mockGetCookie.mockImplementation((event: any, name: string) => {
106
+ if (name === 'dropbox_access_token') return 'h3-access-token'
107
+ if (name === 'dropbox_refresh_token') return 'h3-refresh-token'
108
+ return null
109
+ })
110
+
111
+ const credentials = getCredentialsFromCookies(mockEvent)
112
+
113
+ expect(mockGetCookie).toHaveBeenCalledWith(
114
+ mockEvent,
115
+ 'dropbox_access_token'
116
+ )
117
+ expect(mockGetCookie).toHaveBeenCalledWith(
118
+ mockEvent,
119
+ 'dropbox_refresh_token'
120
+ )
121
+ expect(credentials).toEqual({
122
+ clientId: 'test-app-key',
123
+ clientSecret: 'test-app-secret',
124
+ accessToken: 'h3-access-token',
125
+ refreshToken: 'h3-refresh-token',
126
+ })
127
+ })
128
+ })
129
+
130
+ describe('createNuxtApiHandlers', () => {
131
+ const mockEvent = {} as H3Event
132
+
133
+ beforeEach(() => {
134
+ // Reset H3 mocks for each test
135
+ mockGetCookie.mockReset()
136
+ mockSetCookie.mockReset()
137
+ mockDeleteCookie.mockReset()
138
+ mockGetQuery.mockReset()
139
+ mockSendRedirect.mockReset()
140
+ })
141
+
142
+ it('should create Nuxt API handlers with necessary methods', () => {
143
+ const handlers = createNuxtApiHandlers()
144
+
145
+ expect(handlers).toHaveProperty('status')
146
+ expect(handlers).toHaveProperty('oauthStart')
147
+ expect(handlers).toHaveProperty('oauthCallback')
148
+ expect(handlers).toHaveProperty('logout')
149
+ })
150
+
151
+ it('should check connection status', async () => {
152
+ mockGetCookie.mockReturnValue('h3-access-token')
153
+
154
+ const handlers = createNuxtApiHandlers()
155
+ const result = await handlers.status(mockEvent)
156
+
157
+ expect(mockGetCookie).toHaveBeenCalledWith(
158
+ mockEvent,
159
+ 'dropbox_access_token'
160
+ )
161
+ expect(result).toEqual({ connected: true })
162
+ })
163
+
164
+ it('should handle OAuth start', async () => {
165
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue({
166
+ auth: {
167
+ getAuthUrl: jest
168
+ .fn()
169
+ .mockResolvedValue('https://dropbox.com/oauth'),
170
+ },
171
+ })
172
+
173
+ mockSendRedirect.mockImplementation(() => ({ redirected: true }))
174
+
175
+ const handlers = createNuxtApiHandlers()
176
+ await handlers.oauthStart(mockEvent)
177
+
178
+ expect(createDropboxSyncClient).toHaveBeenCalled()
179
+ expect(mockSendRedirect).toHaveBeenCalledWith(
180
+ mockEvent,
181
+ 'https://dropbox.com/oauth'
182
+ )
183
+ })
184
+ })
185
+ })
@@ -0,0 +1,194 @@
1
+ import {
2
+ useSvelteDropboxSync,
3
+ getCredentialsFromCookies,
4
+ createSvelteKitHandlers,
5
+ } from '../svelte'
6
+ import { createDropboxSyncClient } from '../../core/client'
7
+ import type { Cookies } from '@sveltejs/kit'
8
+
9
+ // Mock dependencies
10
+ jest.mock('../../core/client')
11
+
12
+ describe('SvelteKit adapter', () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks()
15
+
16
+ // Mock process.env
17
+ process.env.DROPBOX_APP_KEY = 'test-app-key'
18
+ process.env.DROPBOX_APP_SECRET = 'test-app-secret'
19
+ process.env.PUBLIC_APP_URL = 'https://example.com'
20
+ })
21
+
22
+ describe('useSvelteDropboxSync', () => {
23
+ it('should create a Dropbox sync client with provided credentials', () => {
24
+ const mockCredentials = {
25
+ clientId: 'custom-client-id',
26
+ clientSecret: 'custom-client-secret',
27
+ }
28
+
29
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue({
30
+ mock: 'client',
31
+ })
32
+
33
+ const result = useSvelteDropboxSync(mockCredentials)
34
+
35
+ expect(createDropboxSyncClient).toHaveBeenCalledWith(
36
+ mockCredentials
37
+ )
38
+ expect(result).toEqual({ mock: 'client' })
39
+ })
40
+ })
41
+
42
+ describe('getCredentialsFromCookies', () => {
43
+ it('should get credentials from cookies', () => {
44
+ const mockCookies = {
45
+ get: jest.fn((name) => {
46
+ if (name === 'dropbox_access_token')
47
+ return 'test-access-token'
48
+ if (name === 'dropbox_refresh_token')
49
+ return 'test-refresh-token'
50
+ return null
51
+ }),
52
+ } as unknown as Cookies
53
+
54
+ const credentials = getCredentialsFromCookies(mockCookies)
55
+
56
+ expect(mockCookies.get).toHaveBeenCalledWith('dropbox_access_token')
57
+ expect(mockCookies.get).toHaveBeenCalledWith(
58
+ 'dropbox_refresh_token'
59
+ )
60
+ expect(credentials).toEqual({
61
+ clientId: 'test-app-key',
62
+ clientSecret: 'test-app-secret',
63
+ accessToken: 'test-access-token',
64
+ refreshToken: 'test-refresh-token',
65
+ })
66
+ })
67
+ })
68
+
69
+ describe('createSvelteKitHandlers', () => {
70
+ it('should create SvelteKit handlers with necessary methods', () => {
71
+ const handlers = createSvelteKitHandlers()
72
+
73
+ expect(handlers).toHaveProperty('status')
74
+ expect(handlers).toHaveProperty('oauthStart')
75
+ expect(handlers).toHaveProperty('oauthCallback')
76
+ expect(handlers).toHaveProperty('logout')
77
+ })
78
+
79
+ it('should check connection status', async () => {
80
+ const mockCookies = {
81
+ get: jest.fn().mockReturnValue('test-token'),
82
+ }
83
+
84
+ const handlers = createSvelteKitHandlers()
85
+ const response = await handlers.status({
86
+ cookies: mockCookies as unknown as Cookies,
87
+ })
88
+
89
+ expect(mockCookies.get).toHaveBeenCalledWith('dropbox_access_token')
90
+ expect(response.status).toBe(200)
91
+
92
+ // Parse the response body
93
+ const responseText = await response.text()
94
+ const responseData = JSON.parse(responseText)
95
+ expect(responseData).toEqual({ connected: true })
96
+ })
97
+
98
+ it('should start OAuth flow', async () => {
99
+ const mockClient = {
100
+ auth: {
101
+ getAuthUrl: jest
102
+ .fn()
103
+ .mockResolvedValue('https://dropbox.com/oauth'),
104
+ },
105
+ }
106
+
107
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue(mockClient)
108
+
109
+ const handlers = createSvelteKitHandlers()
110
+ const response = await handlers.oauthStart()
111
+
112
+ expect(createDropboxSyncClient).toHaveBeenCalled()
113
+ expect(mockClient.auth.getAuthUrl).toHaveBeenCalled()
114
+ expect(response.status).toBe(302)
115
+ expect(response.headers.get('Location')).toBe(
116
+ 'https://dropbox.com/oauth'
117
+ )
118
+ })
119
+
120
+ it('should handle OAuth callback success', async () => {
121
+ const mockUrl = {
122
+ searchParams: {
123
+ get: jest.fn().mockReturnValue('test-auth-code'),
124
+ },
125
+ } as unknown as URL
126
+
127
+ const mockCookies = {
128
+ set: jest.fn(),
129
+ } as unknown as Cookies
130
+
131
+ const mockClient = {
132
+ auth: {
133
+ exchangeCodeForToken: jest.fn().mockResolvedValue({
134
+ accessToken: 'new-access-token',
135
+ refreshToken: 'new-refresh-token',
136
+ expiresAt: Date.now() + 14400 * 1000,
137
+ }),
138
+ },
139
+ }
140
+
141
+ ;(createDropboxSyncClient as jest.Mock).mockReturnValue(mockClient)
142
+
143
+ const handlers = createSvelteKitHandlers()
144
+ const response = await handlers.oauthCallback({
145
+ url: mockUrl,
146
+ cookies: mockCookies,
147
+ })
148
+
149
+ expect(mockUrl.searchParams.get).toHaveBeenCalledWith('code')
150
+ expect(createDropboxSyncClient).toHaveBeenCalled()
151
+ expect(mockClient.auth.exchangeCodeForToken).toHaveBeenCalled()
152
+ expect(mockCookies.set).toHaveBeenCalledTimes(3) // Access, refresh, and connected cookies
153
+ expect(response.status).toBe(302)
154
+ expect(response.headers.get('Location')).toBe('/')
155
+ })
156
+
157
+ it('should handle OAuth callback with missing code', async () => {
158
+ const mockUrl = {
159
+ searchParams: {
160
+ get: jest.fn().mockReturnValue(null),
161
+ },
162
+ } as unknown as URL
163
+
164
+ const mockCookies = {} as unknown as Cookies
165
+
166
+ const handlers = createSvelteKitHandlers()
167
+ const response = await handlers.oauthCallback({
168
+ url: mockUrl,
169
+ cookies: mockCookies,
170
+ })
171
+
172
+ expect(mockUrl.searchParams.get).toHaveBeenCalledWith('code')
173
+ expect(response.status).toBe(302)
174
+ expect(response.headers.get('Location')).toBe('/auth/error')
175
+ })
176
+
177
+ it('should handle logout', async () => {
178
+ const mockCookies = {
179
+ delete: jest.fn(),
180
+ } as unknown as Cookies
181
+
182
+ const handlers = createSvelteKitHandlers()
183
+ const response = await handlers.logout({ cookies: mockCookies })
184
+
185
+ expect(mockCookies.delete).toHaveBeenCalledTimes(3) // Should delete three cookies
186
+ expect(response.status).toBe(200)
187
+
188
+ // Parse the response body
189
+ const responseText = await response.text()
190
+ const responseData = JSON.parse(responseText)
191
+ expect(responseData).toEqual({ success: true })
192
+ })
193
+ })
194
+ })