Skip to content

Commit aa3bc95

Browse files
style(tests): format JSON objects for better readability in NativeAuth0Client tests
1 parent 330fd97 commit aa3bc95

1 file changed

Lines changed: 32 additions & 29 deletions

File tree

src/platforms/native/adapters/__tests__/NativeAuth0Client.spec.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ describe('NativeAuth0Client', () => {
283283
authSession: 'mock-auth-session-123',
284284
authParamsPublicKey: {
285285
rp: { id: 'my-tenant.auth0.com', name: 'My App' },
286-
user: { id: 'dXNlci1pZA', name: 'user@example.com', displayName: 'User' },
286+
user: {
287+
id: 'dXNlci1pZA',
288+
name: 'user@example.com',
289+
displayName: 'User',
290+
},
287291
challenge: 'Y2hhbGxlbmdl',
288292
pubKeyCredParams: [{ type: 'public-key', alg: -7 }],
289293
},
@@ -422,10 +426,7 @@ describe('NativeAuth0Client', () => {
422426

423427
expect(
424428
(mockBridgeInstance as any).passkeyLoginChallenge
425-
).toHaveBeenCalledWith(
426-
'Username-Password-Authentication',
427-
'org_123'
428-
);
429+
).toHaveBeenCalledWith('Username-Password-Authentication', 'org_123');
429430
});
430431

431432
it('should return challenge response from passkeyLoginChallenge', async () => {
@@ -491,9 +492,7 @@ describe('NativeAuth0Client', () => {
491492
organization: 'org_123',
492493
});
493494

494-
expect(
495-
(mockBridgeInstance as any).passkeyExchange
496-
).toHaveBeenCalledWith(
495+
expect((mockBridgeInstance as any).passkeyExchange).toHaveBeenCalledWith(
497496
'auth-session-123',
498497
'{"id":"cred-id","type":"public-key","response":{}}',
499498
'Username-Password-Authentication',
@@ -512,9 +511,7 @@ describe('NativeAuth0Client', () => {
512511
authResponse: '{"id":"cred-id","type":"public-key","response":{}}',
513512
});
514513

515-
expect(
516-
(mockBridgeInstance as any).passkeyExchange
517-
).toHaveBeenCalledWith(
514+
expect((mockBridgeInstance as any).passkeyExchange).toHaveBeenCalledWith(
518515
'auth-session-123',
519516
'{"id":"cred-id","type":"public-key","response":{}}',
520517
undefined,
@@ -540,13 +537,11 @@ describe('NativeAuth0Client', () => {
540537
const { AuthError } = require('../../../../core/models');
541538
const { PasskeyError } = require('../../../../core/models');
542539

543-
(mockBridgeInstance as any).passkeyExchange = jest
544-
.fn()
545-
.mockRejectedValue(
546-
new AuthError('PASSKEY_EXCHANGE_FAILED', 'Exchange failed', {
547-
code: 'PASSKEY_EXCHANGE_FAILED',
548-
})
549-
);
540+
(mockBridgeInstance as any).passkeyExchange = jest.fn().mockRejectedValue(
541+
new AuthError('PASSKEY_EXCHANGE_FAILED', 'Exchange failed', {
542+
code: 'PASSKEY_EXCHANGE_FAILED',
543+
})
544+
);
550545

551546
const client = new NativeAuth0Client(options);
552547
await new Promise(process.nextTick);
@@ -561,7 +556,8 @@ describe('NativeAuth0Client', () => {
561556
});
562557

563558
describe('passkeyRegistration', () => {
564-
const mockResponseJson = '{"id":"cred-id","rawId":"cred-id","type":"public-key","response":{"clientDataJSON":"abc","attestationObject":"def"},"authenticatorAttachment":"platform"}';
559+
const mockResponseJson =
560+
'{"id":"cred-id","rawId":"cred-id","type":"public-key","response":{"clientDataJSON":"abc","attestationObject":"def"},"authenticatorAttachment":"platform"}';
565561

566562
beforeEach(() => {
567563
(mockBridgeInstance as any).passkeyRegistration = jest
@@ -573,7 +569,8 @@ describe('NativeAuth0Client', () => {
573569
const client = new NativeAuth0Client(options);
574570
await new Promise(process.nextTick);
575571

576-
const challengeJson = '{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}';
572+
const challengeJson =
573+
'{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}';
577574

578575
await client.passkeyRegistration({ challengeJson });
579576

@@ -587,7 +584,8 @@ describe('NativeAuth0Client', () => {
587584
await new Promise(process.nextTick);
588585

589586
const result = await client.passkeyRegistration({
590-
challengeJson: '{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}',
587+
challengeJson:
588+
'{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}',
591589
});
592590

593591
expect(result).toEqual(mockResponseJson);
@@ -610,14 +608,16 @@ describe('NativeAuth0Client', () => {
610608

611609
await expect(
612610
client.passkeyRegistration({
613-
challengeJson: '{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}',
611+
challengeJson:
612+
'{"rp":{"id":"example.com"},"challenge":"abc","user":{"id":"123","name":"user@example.com"}}',
614613
})
615614
).rejects.toBeInstanceOf(PasskeyError);
616615
});
617616
});
618617

619618
describe('passkeyAssertion', () => {
620-
const mockResponseJson = '{"id":"cred-id","rawId":"cred-id","type":"public-key","response":{"clientDataJSON":"abc","authenticatorData":"def","signature":"ghi","userHandle":"jkl"},"authenticatorAttachment":"platform"}';
619+
const mockResponseJson =
620+
'{"id":"cred-id","rawId":"cred-id","type":"public-key","response":{"clientDataJSON":"abc","authenticatorData":"def","signature":"ghi","userHandle":"jkl"},"authenticatorAttachment":"platform"}';
621621

622622
beforeEach(() => {
623623
(mockBridgeInstance as any).passkeyAssertion = jest
@@ -629,21 +629,23 @@ describe('NativeAuth0Client', () => {
629629
const client = new NativeAuth0Client(options);
630630
await new Promise(process.nextTick);
631631

632-
const challengeJson = '{"rpId":"example.com","challenge":"abc","allowCredentials":[]}';
632+
const challengeJson =
633+
'{"rpId":"example.com","challenge":"abc","allowCredentials":[]}';
633634

634635
await client.passkeyAssertion({ challengeJson });
635636

636-
expect(
637-
(mockBridgeInstance as any).passkeyAssertion
638-
).toHaveBeenCalledWith(challengeJson);
637+
expect((mockBridgeInstance as any).passkeyAssertion).toHaveBeenCalledWith(
638+
challengeJson
639+
);
639640
});
640641

641642
it('should return credential response JSON string', async () => {
642643
const client = new NativeAuth0Client(options);
643644
await new Promise(process.nextTick);
644645

645646
const result = await client.passkeyAssertion({
646-
challengeJson: '{"rpId":"example.com","challenge":"abc","allowCredentials":[]}',
647+
challengeJson:
648+
'{"rpId":"example.com","challenge":"abc","allowCredentials":[]}',
647649
});
648650

649651
expect(result).toEqual(mockResponseJson);
@@ -666,7 +668,8 @@ describe('NativeAuth0Client', () => {
666668

667669
await expect(
668670
client.passkeyAssertion({
669-
challengeJson: '{"rpId":"example.com","challenge":"abc","allowCredentials":[]}',
671+
challengeJson:
672+
'{"rpId":"example.com","challenge":"abc","allowCredentials":[]}',
670673
})
671674
).rejects.toBeInstanceOf(PasskeyError);
672675
});

0 commit comments

Comments
 (0)