diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-25 11:50:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 11:50:22 -0700 |
commit | d0205b9a4f2b4e304447e8072e4384f52dcc0c51 (patch) | |
tree | f68fe8f67d53efb6faa84d8e35c25a65b315507a /packages/browser/src/methods/startAttestation.test.ts | |
parent | 2cda08e3fc9935eff5613f08c7f9e4a30cf19c85 (diff) | |
parent | 5ef053d8785afc0cc25936add1b9b9097efbe45e (diff) |
Merge pull request #10 from MasterKale/feature/linting
feature/linting
Diffstat (limited to 'packages/browser/src/methods/startAttestation.test.ts')
-rw-r--r-- | packages/browser/src/methods/startAttestation.test.ts | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startAttestation.test.ts index 0efec48..539ffe5 100644 --- a/packages/browser/src/methods/startAttestation.test.ts +++ b/packages/browser/src/methods/startAttestation.test.ts @@ -1,6 +1,9 @@ import base64js from 'base64-js'; -import { AttestationCredential, PublicKeyCredentialCreationOptionsJSON } from '@webauthntine/typescript-types'; +import { + AttestationCredential, + PublicKeyCredentialCreationOptionsJSON, +} from '@webauthntine/typescript-types'; import toUint8Array from '../helpers/toUint8Array'; import supportsWebauthn from '../helpers/supportsWebauthn'; @@ -9,8 +12,8 @@ import startAttestation from './startAttestation'; jest.mock('../helpers/supportsWebauthn'); -const mockNavigatorCreate = (window.navigator.credentials.create as jest.Mock); -const mockSupportsWebauthn = (supportsWebauthn as jest.Mock); +const mockNavigatorCreate = window.navigator.credentials.create as jest.Mock; +const mockSupportsWebauthn = supportsWebauthn as jest.Mock; const mockAttestationObject = 'mockAtte'; const mockClientDataJSON = 'mockClie'; @@ -19,10 +22,12 @@ const goodOpts1: PublicKeyCredentialCreationOptionsJSON = { publicKey: { challenge: 'fizz', attestation: 'direct', - pubKeyCredParams: [{ - alg: -7, - type: "public-key", - }], + pubKeyCredParams: [ + { + alg: -7, + type: 'public-key', + }, + ], rp: { id: '1234', name: 'webauthntine', @@ -41,15 +46,17 @@ beforeEach(() => { mockSupportsWebauthn.mockReset(); }); -test('should convert options before passing to navigator.credentials.create(...)', async (done) => { +test('should convert options before passing to navigator.credentials.create(...)', async done => { mockSupportsWebauthn.mockReturnValue(true); // Stub out a response so the method won't throw - mockNavigatorCreate.mockImplementation((): Promise<any> => { - return new Promise((resolve) => { - resolve({ response: {} }); - }); - }); + mockNavigatorCreate.mockImplementation( + (): Promise<any> => { + return new Promise(resolve => { + resolve({ response: {} }); + }); + }, + ); await startAttestation(goodOpts1); @@ -61,23 +68,25 @@ test('should convert options before passing to navigator.credentials.create(...) done(); }); -test('should return base64-encoded response values', async (done) => { +test('should return base64-encoded response values', async done => { mockSupportsWebauthn.mockReturnValue(true); - mockNavigatorCreate.mockImplementation((): Promise<AttestationCredential> => { - return new Promise((resolve) => { - resolve({ - id: 'foobar', - rawId: toUint8Array('foobar'), - response: { - attestationObject: base64js.toByteArray(mockAttestationObject), - clientDataJSON: base64js.toByteArray(mockClientDataJSON), - }, - getClientExtensionResults: () => ({}), - type: 'webauthn.create', + mockNavigatorCreate.mockImplementation( + (): Promise<AttestationCredential> => { + return new Promise(resolve => { + resolve({ + id: 'foobar', + rawId: toUint8Array('foobar'), + response: { + attestationObject: base64js.toByteArray(mockAttestationObject), + clientDataJSON: base64js.toByteArray(mockClientDataJSON), + }, + getClientExtensionResults: () => ({}), + type: 'webauthn.create', + }); }); - }); - }); + }, + ); const response = await startAttestation(goodOpts1); @@ -87,24 +96,28 @@ test('should return base64-encoded response values', async (done) => { }); done(); -}) +}); -test('should throw error if WebAuthn isn\'t supported', async (done) => { +test("should throw error if WebAuthn isn't supported", async done => { mockSupportsWebauthn.mockReturnValue(false); - await expect(startAttestation(goodOpts1)).rejects.toThrow('WebAuthn is not supported in this browser'); + await expect(startAttestation(goodOpts1)).rejects.toThrow( + 'WebAuthn is not supported in this browser', + ); done(); }); -test('should throw error if attestation is cancelled for some reason', async (done) => { +test('should throw error if attestation is cancelled for some reason', async done => { mockSupportsWebauthn.mockReturnValue(true); - mockNavigatorCreate.mockImplementation((): Promise<null> => { - return new Promise((resolve) => { - resolve(null); - }); - }); + mockNavigatorCreate.mockImplementation( + (): Promise<null> => { + return new Promise(resolve => { + resolve(null); + }); + }, + ); await expect(startAttestation(goodOpts1)).rejects.toThrow('Attestation was not completed'); |