diff --git a/packages/clerk-js/src/core/resources/Client.test.ts b/packages/clerk-js/src/core/resources/Client.test.ts index 389af7384a..ba6ceeef3c 100644 --- a/packages/clerk-js/src/core/resources/Client.test.ts +++ b/packages/clerk-js/src/core/resources/Client.test.ts @@ -3,12 +3,9 @@ import type { ClientJSON } from '@clerk/types'; import { createSession } from '../test/fixtures'; import { BaseResource, Client } from './internal'; -export const mockJwt = - 'eyJhbGciOiJSUzI1NiIsImtpZCI6Imluc18yR0lvUWhiVXB5MGhYN0IyY1ZrdVRNaW5Yb0QiLCJ0eXAiOiJKV1QifQ.eyJhenAiOiJodHRwczovL2FjY291bnRzLmluc3BpcmVkLnB1bWEtNzQubGNsLmRldiIsImV4cCI6MTY2NjY0ODMxMCwiaWF0IjoxNjY2NjQ4MjUwLCJpc3MiOiJodHRwczovL2NsZXJrLmluc3BpcmVkLnB1bWEtNzQubGNsLmRldiIsIm5iZiI6MTY2NjY0ODI0MCwic2lkIjoic2Vzc18yR2JEQjRlbk5kQ2E1dlMxenBDM1h6Zzl0SzkiLCJzdWIiOiJ1c2VyXzJHSXBYT0VwVnlKdzUxcmtabjlLbW5jNlN4ciJ9.n1Usc-DLDftqA0Xb-_2w8IGs4yjCmwc5RngwbSRvwevuZOIuRoeHmE2sgCdEvjfJEa7ewL6EVGVcM557TWPW--g_J1XQPwBy8tXfz7-S73CEuyRFiR97L2AHRdvRtvGtwR-o6l8aHaFxtlmfWbQXfg4kFJz2UGe9afmh3U9-f_4JOZ5fa3mI98UMy1-bo20vjXeWQ9aGrqaxHQxjnzzC-1Kpi5LdPvhQ16H0dPB8MHRTSM5TAuLKTpPV7wqixmbtcc2-0k6b9FKYZNqRVTaIyV-lifZloBvdzlfOF8nW1VVH_fx-iW5Q3hovHFcJIULHEC1kcAYTubbxzpgeVQepGg'; - describe('Client Singleton', () => { it('destroy', async () => { - const session = createSession({}); + const session = createSession(); const clientObjectJSON: ClientJSON = { object: 'client', id: 'test_id', @@ -17,14 +14,33 @@ describe('Client Singleton', () => { sign_in: null, sign_up: null, sessions: [session], - created_at: jest.now(), + created_at: jest.now() - 1000, + updated_at: jest.now(), + }; + + const destroyedSession = createSession({ + id: 'test_session_id', + abandon_at: jest.now(), + status: 'ended', + last_active_token: undefined, + }); + + const clientObjectDeletedJSON = { + id: 'test_id_deleted', + status: 'ended', + last_active_session_id: null, + sign_in: null, + sign_up: null, + sessions: [destroyedSession], + created_at: jest.now() - 1000, updated_at: jest.now(), }; // @ts-expect-error This is a private method that we are mocking BaseResource._fetch = jest.fn().mockReturnValue( Promise.resolve({ - response: clientObjectJSON, + client: null, + response: clientObjectDeletedJSON, }), ); diff --git a/packages/clerk-js/src/core/test/fixtures.ts b/packages/clerk-js/src/core/test/fixtures.ts index 27d831458a..75dae9b1f9 100644 --- a/packages/clerk-js/src/core/test/fixtures.ts +++ b/packages/clerk-js/src/core/test/fixtures.ts @@ -26,6 +26,8 @@ type WithUserParams = Omit< organization_memberships?: Array; }; +type WithSessionParams = Partial; + export const getOrganizationId = (orgParams: OrgParams) => orgParams?.id || orgParams?.name || 'test_id'; export const createOrganizationMembership = (params: OrgParams): OrganizationMembershipJSON => { @@ -164,17 +166,17 @@ export const createUser = (params: WithUserParams): UserJSON => { return res; }; -export const createSession = (params: WithUserParams) => { - const user = createUser(params); +export const createSession = (sessionParams: WithSessionParams = {}, userParams: WithUserParams = {}) => { + const user = createUser(userParams); return { object: 'session', - id: 'session_1', - status: 'active', - expire_at: jest.now() + 5000, - abandon_at: jest.now() + 5000, - last_active_at: jest.now(), - last_active_organization_id: null, - actor: null, + id: sessionParams.id, + status: sessionParams.status, + expire_at: sessionParams.expire_at || jest.now() + 5000, + abandon_at: sessionParams.abandon_at, + last_active_at: sessionParams.last_active_at || jest.now(), + last_active_organization_id: sessionParams.last_active_organization_id, + actor: sessionParams.actor, user: createUser({}), public_user_data: { first_name: user.first_name, @@ -184,8 +186,8 @@ export const createSession = (params: WithUserParams) => { identifier: user.email_addresses.find(e => e.id === user.primary_email_address_id)?.email_address || '', profile_image_url: user.profile_image_url, }, - created_at: 1697449745962, - updated_at: 1698763366892, + created_at: sessionParams.created_at || jest.now() - 1000, + updated_at: sessionParams.updated_at || jest.now(), last_active_token: { object: 'token', jwt: mockJwt,