Skip to content

Commit a5d86bf

Browse files
jacekradkoCopilot
andauthored
chore(clerk-js): Refactor snapshot tests (#6094)
Co-authored-by: Copilot <[email protected]>
1 parent 25025ae commit a5d86bf

25 files changed

+335
-1743
lines changed

.changeset/gentle-crews-warn.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/clerk-js/src/core/resources/__tests__/Client.test.ts

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,27 @@ describe('Client Singleton', () => {
268268
// @ts-expect-error We cannot mess with the singleton when tests are running in parallel
269269
const client = new Client(clientJSON);
270270

271-
expect(client).toMatchSnapshot();
271+
expect(client).toMatchObject({
272+
id: 'client_DUMMY_ID',
273+
sessions: [],
274+
signUp: expect.objectContaining({
275+
status: null,
276+
missingFields: [],
277+
unverifiedFields: [],
278+
verifications: expect.objectContaining({
279+
emailAddress: expect.objectContaining({
280+
status: null,
281+
}),
282+
}),
283+
}),
284+
signIn: expect.objectContaining({
285+
status: null,
286+
identifier: null,
287+
}),
288+
lastActiveSessionId: null,
289+
createdAt: expect.any(Date),
290+
updatedAt: expect.any(Date),
291+
});
272292
});
273293

274294
it('__internal_toSnapshot()', () => {
@@ -404,6 +424,27 @@ describe('Client Singleton', () => {
404424
// @ts-expect-error We cannot mess with the singleton when tests are running in parallel
405425
const client = new Client(clientJSON);
406426

407-
expect(client.__internal_toSnapshot()).toMatchSnapshot();
427+
expect(client.__internal_toSnapshot()).toMatchObject({
428+
object: 'client',
429+
id: 'client_DUMMY_ID',
430+
sessions: [],
431+
sign_up: expect.objectContaining({
432+
status: null,
433+
missing_fields: [],
434+
unverified_fields: [],
435+
verifications: expect.objectContaining({
436+
email_address: expect.objectContaining({
437+
status: null,
438+
}),
439+
}),
440+
}),
441+
sign_in: expect.objectContaining({
442+
status: null,
443+
identifier: null,
444+
}),
445+
last_active_session_id: null,
446+
created_at: expect.any(Number),
447+
updated_at: expect.any(Number),
448+
});
408449
});
409450
});

packages/clerk-js/src/core/resources/__tests__/Environment.test.ts

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,41 @@ describe('Environment', () => {
66
it('defaults values when instantiated without arguments', () => {
77
const environment = new Environment();
88

9-
expect(environment).toMatchSnapshot();
9+
expect(environment).toMatchObject({
10+
authConfig: expect.objectContaining({
11+
singleSessionMode: false,
12+
reverification: false,
13+
}),
14+
displayConfig: expect.objectContaining({
15+
instanceEnvironmentType: '',
16+
preferredSignInStrategy: 'password',
17+
branded: false,
18+
showDevModeWarning: false,
19+
}),
20+
userSettings: expect.objectContaining({
21+
attributes: expect.objectContaining({
22+
email_address: expect.objectContaining({
23+
enabled: true,
24+
required: true,
25+
used_for_first_factor: true,
26+
verify_at_sign_up: true,
27+
}),
28+
password: expect.objectContaining({
29+
enabled: true,
30+
required: true,
31+
}),
32+
}),
33+
actions: expect.objectContaining({
34+
delete_self: false,
35+
create_organization: false,
36+
}),
37+
}),
38+
organizationSettings: expect.objectContaining({
39+
enabled: false,
40+
maxAllowedMemberships: 1,
41+
}),
42+
maintenanceMode: false,
43+
});
1044
});
1145

1246
it('has the same initial properties', () => {
@@ -246,7 +280,53 @@ describe('Environment', () => {
246280

247281
const environment = new Environment(environmentJSON);
248282

249-
expect(environment).toMatchSnapshot();
283+
expect(environment).toMatchObject({
284+
authConfig: expect.objectContaining({
285+
singleSessionMode: true,
286+
reverification: true,
287+
}),
288+
displayConfig: expect.objectContaining({
289+
instanceEnvironmentType: 'development',
290+
applicationName: '',
291+
branded: true,
292+
showDevModeWarning: true,
293+
preferredSignInStrategy: 'password',
294+
theme: expect.objectContaining({
295+
general: expect.objectContaining({
296+
color: '#6c47ff',
297+
}),
298+
}),
299+
}),
300+
userSettings: expect.objectContaining({
301+
attributes: expect.objectContaining({
302+
email_address: expect.objectContaining({
303+
enabled: true,
304+
required: true,
305+
used_for_first_factor: true,
306+
verify_at_sign_up: true,
307+
}),
308+
password: expect.objectContaining({
309+
enabled: true,
310+
required: true,
311+
}),
312+
}),
313+
actions: expect.objectContaining({
314+
delete_self: true,
315+
create_organization: true,
316+
}),
317+
social: expect.objectContaining({
318+
oauth_google: expect.objectContaining({
319+
enabled: true,
320+
authenticatable: true,
321+
}),
322+
}),
323+
}),
324+
organizationSettings: expect.objectContaining({
325+
enabled: false,
326+
maxAllowedMemberships: 5,
327+
}),
328+
maintenanceMode: false,
329+
});
250330
});
251331

252332
it('__internal_toSnapshot()', () => {
@@ -485,6 +565,42 @@ describe('Environment', () => {
485565

486566
const environment = new Environment(environmentJSON);
487567

488-
expect(environment.__internal_toSnapshot()).toMatchSnapshot();
568+
expect(environment.__internal_toSnapshot()).toMatchObject({
569+
object: 'environment',
570+
auth_config: expect.objectContaining({
571+
single_session_mode: true,
572+
reverification: true,
573+
}),
574+
display_config: expect.objectContaining({
575+
instance_environment_type: 'development',
576+
application_name: '',
577+
branded: true,
578+
show_devmode_warning: true,
579+
preferred_sign_in_strategy: 'password',
580+
}),
581+
user_settings: expect.objectContaining({
582+
attributes: expect.objectContaining({
583+
email_address: expect.objectContaining({
584+
enabled: true,
585+
required: true,
586+
used_for_first_factor: true,
587+
verify_at_sign_up: true,
588+
}),
589+
password: expect.objectContaining({
590+
enabled: true,
591+
required: true,
592+
}),
593+
}),
594+
actions: expect.objectContaining({
595+
delete_self: true,
596+
create_organization: true,
597+
}),
598+
}),
599+
organization_settings: expect.objectContaining({
600+
enabled: false,
601+
max_allowed_memberships: 5,
602+
}),
603+
maintenance_mode: false,
604+
});
489605
});
490606
});

packages/clerk-js/src/core/resources/__tests__/Organization.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ describe('Organization', () => {
1919
has_image: true,
2020
});
2121

22-
expect(organization).toMatchSnapshot();
22+
expect(organization).toMatchObject({
23+
id: 'test_id',
24+
name: 'test_name',
25+
slug: 'test_slug',
26+
hasImage: true,
27+
imageUrl:
28+
'https://img.clerk.com/eyJ0eXBlIjoiZGVmYXVsdCIsImlpZCI6Imluc18xbHlXRFppb2JyNjAwQUtVZVFEb1NsckVtb00iLCJyaWQiOiJ1c2VyXzJKbElJQTN2VXNjWXh1N2VUMnhINmFrTGgxOCIsImluaXRpYWxzIjoiREsifQ?width=160',
29+
membersCount: 1,
30+
pendingInvitationsCount: 10,
31+
maxAllowedMemberships: 3,
32+
adminDeleteEnabled: true,
33+
createdAt: expect.any(Date),
34+
updatedAt: expect.any(Date),
35+
publicMetadata: {
36+
public: 'metadata',
37+
},
38+
});
2339
});
2440
});

packages/clerk-js/src/core/resources/__tests__/OrganizationDomain.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ describe('OrganizationDomain', () => {
2121
total_pending_suggestions: 0,
2222
});
2323

24-
expect(organization).toMatchSnapshot();
24+
expect(organization).toMatchObject({
25+
id: 'test_domain_id',
26+
name: 'clerk.com',
27+
organizationId: 'test_org_id',
28+
enrollmentMode: 'manual_invitation',
29+
affiliationEmailAddress: '[email protected]',
30+
totalPendingInvitations: 0,
31+
totalPendingSuggestions: 0,
32+
verification: {
33+
attempts: 1,
34+
expiresAt: expect.any(Date),
35+
status: 'verified',
36+
strategy: 'email_code',
37+
},
38+
});
2539
});
2640

2741
it('has the same initial nullable properties', () => {
@@ -39,6 +53,15 @@ describe('OrganizationDomain', () => {
3953
total_pending_suggestions: 0,
4054
});
4155

42-
expect(organization).toMatchSnapshot();
56+
expect(organization).toMatchObject({
57+
id: 'test_domain_id',
58+
name: 'clerk.com',
59+
organizationId: 'test_org_id',
60+
enrollmentMode: 'manual_invitation',
61+
affiliationEmailAddress: null,
62+
totalPendingInvitations: 0,
63+
totalPendingSuggestions: 0,
64+
verification: null,
65+
});
4366
});
4467
});

packages/clerk-js/src/core/resources/__tests__/OrganizationInvitation.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ describe('OrganizationInvitation', () => {
1616
status: 'pending',
1717
});
1818

19-
expect(organizationInvitation).toMatchSnapshot();
19+
expect(organizationInvitation).toMatchObject({
20+
id: 'test_id',
21+
emailAddress: 'test_email',
22+
organizationId: 'test_organization_id',
23+
role: 'basic_member',
24+
roleName: undefined,
25+
status: 'pending',
26+
createdAt: expect.any(Date),
27+
updatedAt: expect.any(Date),
28+
publicMetadata: {
29+
public: 'metadata',
30+
},
31+
});
2032
});
2133
});

packages/clerk-js/src/core/resources/__tests__/OrganizationMembership.test.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { OrganizationMembership } from '../internal';
22

33
describe('OrganizationMembership', () => {
44
it('has the same initial properties', () => {
5-
const organizationMemberShip = new OrganizationMembership({
5+
const organizationMembership = new OrganizationMembership({
66
object: 'organization_membership',
77
id: 'test_id',
88
created_at: 12345,
@@ -40,6 +40,35 @@ describe('OrganizationMembership', () => {
4040
},
4141
});
4242

43-
expect(organizationMemberShip).toMatchSnapshot();
43+
expect(organizationMembership).toMatchObject({
44+
id: 'test_id',
45+
role: 'admin',
46+
roleName: undefined,
47+
createdAt: expect.any(Date),
48+
updatedAt: expect.any(Date),
49+
permissions: [],
50+
publicMetadata: {
51+
foo: 'bar',
52+
},
53+
organization: expect.objectContaining({
54+
id: 'test_org_id',
55+
name: 'test_name',
56+
slug: 'test_slug',
57+
hasImage: true,
58+
membersCount: 1,
59+
pendingInvitationsCount: 10,
60+
maxAllowedMemberships: 3,
61+
adminDeleteEnabled: true,
62+
publicMetadata: {
63+
public: 'metadata',
64+
},
65+
}),
66+
publicUserData: expect.objectContaining({
67+
firstName: 'test_first_name',
68+
lastName: 'test_last_name',
69+
hasImage: true,
70+
identifier: '[email protected]',
71+
}),
72+
});
4473
});
4574
});

packages/clerk-js/src/core/resources/__tests__/OrganizationMembershipRequest.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ describe('OrganizationMembership', () => {
2020
},
2121
});
2222

23-
expect(organizationMembershipRequest).toMatchSnapshot();
23+
expect(organizationMembershipRequest).toMatchObject({
24+
id: 'test_id',
25+
organizationId: 'test_org_id',
26+
status: 'pending',
27+
createdAt: expect.any(Date),
28+
updatedAt: expect.any(Date),
29+
publicUserData: expect.objectContaining({
30+
firstName: 'test_first_name',
31+
lastName: 'test_last_name',
32+
hasImage: true,
33+
identifier: '[email protected]',
34+
imageUrl: 'https://clerk.com',
35+
}),
36+
});
2437
});
2538
});

packages/clerk-js/src/core/resources/__tests__/OrganizationSuggestion.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ describe('OrganizationSuggestion', () => {
1717
updated_at: 5678,
1818
});
1919

20-
expect(organizationSuggestion).toMatchSnapshot();
20+
expect(organizationSuggestion).toMatchObject({
21+
id: 'test_id',
22+
status: 'pending',
23+
createdAt: expect.any(Date),
24+
updatedAt: expect.any(Date),
25+
publicOrganizationData: {
26+
hasImage: true,
27+
id: 'test_org_id',
28+
imageUrl: 'test_image_url',
29+
name: 'Test org',
30+
slug: 'test-org',
31+
},
32+
});
2133
});
2234
});

packages/clerk-js/src/core/resources/__tests__/PublicUserData.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ describe('PublicUserData', () => {
1313
user_id: '123',
1414
});
1515

16-
expect(JSON.stringify(pud)).toMatchSnapshot();
16+
expect(pud).toMatchObject({
17+
firstName: 'John',
18+
lastName: 'Doe',
19+
imageUrl: 'https://example.com/image.jpg',
20+
hasImage: true,
21+
identifier: 'john-doe',
22+
userId: '123',
23+
});
1724
});
1825
});

0 commit comments

Comments
 (0)