|
1 | | -import { ClerkOfflineError, EmailLinkErrorCodeStatus } from '@clerk/shared/error'; |
| 1 | +import { ClerkOfflineError, ClerkRuntimeError, EmailLinkErrorCodeStatus } from '@clerk/shared/error'; |
2 | 2 | import { ERROR_CODES } from '@clerk/shared/internal/clerk-js/constants'; |
3 | 3 | import type { |
4 | 4 | ActiveSessionResource, |
@@ -1290,6 +1290,53 @@ describe('Clerk singleton', () => { |
1290 | 1290 | }, |
1291 | 1291 | ); |
1292 | 1292 |
|
| 1293 | + it('completes local sign-out when removing sessions fails with an offline network error', async () => { |
| 1294 | + mockClientRemoveSessions.mockRejectedValue( |
| 1295 | + new ClerkRuntimeError('Network request failed.', { code: 'network_error' }), |
| 1296 | + ); |
| 1297 | + mockClientFetch.mockReturnValue( |
| 1298 | + Promise.resolve({ |
| 1299 | + ...clientTouchDefaults, |
| 1300 | + signedInSessions: [mockSession1], |
| 1301 | + sessions: [mockSession1], |
| 1302 | + destroy: mockClientDestroy, |
| 1303 | + removeSessions: mockClientRemoveSessions, |
| 1304 | + }), |
| 1305 | + ); |
| 1306 | + |
| 1307 | + const sut = new Clerk(productionPublishableKey); |
| 1308 | + sut.navigate = vi.fn(); |
| 1309 | + await sut.load(); |
| 1310 | + |
| 1311 | + await expect(sut.signOut()).resolves.toBeUndefined(); |
| 1312 | + |
| 1313 | + expect(sut.session).toBeNull(); |
| 1314 | + expect(sut.navigate).toHaveBeenCalledWith('/'); |
| 1315 | + }); |
| 1316 | + |
| 1317 | + it('rethrows non-network errors when removing sessions during sign-out', async () => { |
| 1318 | + const error = new ClerkRuntimeError('Request failed.', { code: 'unexpected_error' }); |
| 1319 | + mockClientRemoveSessions.mockRejectedValue(error); |
| 1320 | + mockClientFetch.mockReturnValue( |
| 1321 | + Promise.resolve({ |
| 1322 | + ...clientTouchDefaults, |
| 1323 | + signedInSessions: [mockSession1], |
| 1324 | + sessions: [mockSession1], |
| 1325 | + destroy: mockClientDestroy, |
| 1326 | + removeSessions: mockClientRemoveSessions, |
| 1327 | + }), |
| 1328 | + ); |
| 1329 | + |
| 1330 | + const sut = new Clerk(productionPublishableKey); |
| 1331 | + sut.navigate = vi.fn(); |
| 1332 | + await sut.load(); |
| 1333 | + |
| 1334 | + await expect(sut.signOut()).rejects.toBe(error); |
| 1335 | + |
| 1336 | + expect(sut.session).toBeUndefined(); |
| 1337 | + expect(sut.navigate).not.toHaveBeenCalled(); |
| 1338 | + }); |
| 1339 | + |
1293 | 1340 | it('only removes the session that corresponds to the passed sessionId if it is not the current', async () => { |
1294 | 1341 | mockClientFetch.mockReturnValue( |
1295 | 1342 | Promise.resolve({ |
|
0 commit comments