|
1 | | -import { ClerkAPIResponseError, ClerkOfflineError } from '@clerk/shared/error'; |
| 1 | +import { ClerkOfflineError } from '@clerk/shared/error'; |
2 | 2 | import type { InstanceType, OrganizationJSON, SessionJSON } from '@clerk/shared/types'; |
3 | 3 | import { afterEach, beforeEach, describe, expect, it, type Mock, vi } from 'vitest'; |
4 | 4 |
|
@@ -1522,153 +1522,6 @@ describe('Session', () => { |
1522 | 1522 | }); |
1523 | 1523 | }); |
1524 | 1524 |
|
1525 | | - describe('origin outage mode fallback', () => { |
1526 | | - let dispatchSpy: ReturnType<typeof vi.spyOn>; |
1527 | | - let fetchSpy: ReturnType<typeof vi.spyOn>; |
1528 | | - |
1529 | | - beforeEach(() => { |
1530 | | - SessionTokenCache.clear(); |
1531 | | - dispatchSpy = vi.spyOn(eventBus, 'emit'); |
1532 | | - fetchSpy = vi.spyOn(BaseResource, '_fetch' as any); |
1533 | | - BaseResource.clerk = clerkMock() as any; |
1534 | | - }); |
1535 | | - |
1536 | | - afterEach(() => { |
1537 | | - dispatchSpy?.mockRestore(); |
1538 | | - fetchSpy?.mockRestore(); |
1539 | | - BaseResource.clerk = null as any; |
1540 | | - }); |
1541 | | - |
1542 | | - it('should retry with expired token when API returns 422 with missing_expired_token error', async () => { |
1543 | | - const session = new Session({ |
1544 | | - status: 'active', |
1545 | | - id: 'session_1', |
1546 | | - object: 'session', |
1547 | | - user: createUser({}), |
1548 | | - last_active_organization_id: null, |
1549 | | - last_active_token: { object: 'token', jwt: mockJwt }, |
1550 | | - actor: null, |
1551 | | - created_at: new Date().getTime(), |
1552 | | - updated_at: new Date().getTime(), |
1553 | | - } as SessionJSON); |
1554 | | - |
1555 | | - SessionTokenCache.clear(); |
1556 | | - |
1557 | | - const errorResponse = new ClerkAPIResponseError('Missing expired token', { |
1558 | | - data: [ |
1559 | | - { code: 'missing_expired_token', message: 'Missing expired token', long_message: 'Missing expired token' }, |
1560 | | - ], |
1561 | | - status: 422, |
1562 | | - }); |
1563 | | - fetchSpy.mockRejectedValueOnce(errorResponse); |
1564 | | - |
1565 | | - fetchSpy.mockResolvedValueOnce({ object: 'token', jwt: mockJwt }); |
1566 | | - |
1567 | | - await session.getToken(); |
1568 | | - |
1569 | | - expect(fetchSpy).toHaveBeenCalledTimes(2); |
1570 | | - |
1571 | | - expect(fetchSpy.mock.calls[0][0]).toMatchObject({ |
1572 | | - path: '/client/sessions/session_1/tokens', |
1573 | | - method: 'POST', |
1574 | | - body: { organizationId: null }, |
1575 | | - }); |
1576 | | - |
1577 | | - expect(fetchSpy.mock.calls[1][0]).toMatchObject({ |
1578 | | - path: '/client/sessions/session_1/tokens', |
1579 | | - method: 'POST', |
1580 | | - body: { organizationId: null }, |
1581 | | - search: { expired_token: mockJwt }, |
1582 | | - }); |
1583 | | - }); |
1584 | | - |
1585 | | - it('should not retry with expired token when lastActiveToken is not available', async () => { |
1586 | | - const session = new Session({ |
1587 | | - status: 'active', |
1588 | | - id: 'session_1', |
1589 | | - object: 'session', |
1590 | | - user: createUser({}), |
1591 | | - last_active_organization_id: null, |
1592 | | - last_active_token: null, |
1593 | | - actor: null, |
1594 | | - created_at: new Date().getTime(), |
1595 | | - updated_at: new Date().getTime(), |
1596 | | - } as unknown as SessionJSON); |
1597 | | - |
1598 | | - SessionTokenCache.clear(); |
1599 | | - |
1600 | | - const errorResponse = new ClerkAPIResponseError('Missing expired token', { |
1601 | | - data: [ |
1602 | | - { code: 'missing_expired_token', message: 'Missing expired token', long_message: 'Missing expired token' }, |
1603 | | - ], |
1604 | | - status: 422, |
1605 | | - }); |
1606 | | - fetchSpy.mockRejectedValue(errorResponse); |
1607 | | - |
1608 | | - await expect(session.getToken()).rejects.toMatchObject({ |
1609 | | - status: 422, |
1610 | | - errors: [{ code: 'missing_expired_token' }], |
1611 | | - }); |
1612 | | - |
1613 | | - expect(fetchSpy).toHaveBeenCalledTimes(1); |
1614 | | - }); |
1615 | | - |
1616 | | - it('should not retry with expired token for non-422 errors', async () => { |
1617 | | - const session = new Session({ |
1618 | | - status: 'active', |
1619 | | - id: 'session_1', |
1620 | | - object: 'session', |
1621 | | - user: createUser({}), |
1622 | | - last_active_organization_id: null, |
1623 | | - last_active_token: { object: 'token', jwt: mockJwt }, |
1624 | | - actor: null, |
1625 | | - created_at: new Date().getTime(), |
1626 | | - updated_at: new Date().getTime(), |
1627 | | - } as SessionJSON); |
1628 | | - |
1629 | | - SessionTokenCache.clear(); |
1630 | | - |
1631 | | - const errorResponse = new ClerkAPIResponseError('Bad request', { |
1632 | | - data: [{ code: 'bad_request', message: 'Bad request', long_message: 'Bad request' }], |
1633 | | - status: 400, |
1634 | | - }); |
1635 | | - fetchSpy.mockRejectedValueOnce(errorResponse); |
1636 | | - |
1637 | | - await expect(session.getToken()).rejects.toThrow(ClerkAPIResponseError); |
1638 | | - |
1639 | | - expect(fetchSpy).toHaveBeenCalledTimes(1); |
1640 | | - }); |
1641 | | - |
1642 | | - it('should not retry with expired token when error code is different', async () => { |
1643 | | - const session = new Session({ |
1644 | | - status: 'active', |
1645 | | - id: 'session_1', |
1646 | | - object: 'session', |
1647 | | - user: createUser({}), |
1648 | | - last_active_organization_id: null, |
1649 | | - last_active_token: { object: 'token', jwt: mockJwt }, |
1650 | | - actor: null, |
1651 | | - created_at: new Date().getTime(), |
1652 | | - updated_at: new Date().getTime(), |
1653 | | - } as unknown as SessionJSON); |
1654 | | - |
1655 | | - SessionTokenCache.clear(); |
1656 | | - |
1657 | | - const errorResponse = new ClerkAPIResponseError('Validation failed', { |
1658 | | - data: [{ code: 'validation_error', message: 'Validation failed', long_message: 'Validation failed' }], |
1659 | | - status: 422, |
1660 | | - }); |
1661 | | - fetchSpy.mockRejectedValue(errorResponse); |
1662 | | - |
1663 | | - await expect(session.getToken()).rejects.toMatchObject({ |
1664 | | - status: 422, |
1665 | | - errors: [{ code: 'validation_error' }], |
1666 | | - }); |
1667 | | - |
1668 | | - expect(fetchSpy).toHaveBeenCalledTimes(1); |
1669 | | - }); |
1670 | | - }); |
1671 | | - |
1672 | 1525 | describe('agent', () => { |
1673 | 1526 | it('sets agent to null when actor is null', () => { |
1674 | 1527 | const session = new Session({ |
|
0 commit comments