use existing auth db method for identifier creation
authorJustin Wind <justin.wind+git@gmail.com>
Sat, 16 Mar 2024 20:51:31 +0000 (13:51 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Sat, 16 Mar 2024 20:51:31 +0000 (13:51 -0700)
lib/authenticator.js
test/lib/authenticator.js
test/stub-db.js

index 7390db5d8803c8271e0cbc32c254e3198d057df0..36c1574b507c223fe380a35ab6f0eb991de085e4 100644 (file)
@@ -33,7 +33,7 @@ class Authenticator {
    * @property {(DBContextExec) => Promise<any>} context
    * @property {(dbCtx: any, identifier: String) => Promise<AuthInfo> } authenticationGet
    * @property {(dbCtx: any, identifier: String) => Promise<void>} authenticationSuccess
-   * @property {(dbCtx: any, identifier: String, credential: String, otpKey: String=) => Promise<void>} authenticationInsertIdentifier
+   * @property {(dbCtx: any, identifier: String, credential: String, otpKey: String=) => Promise<void>} authenticationUpsert
    * @property {(dbCtx: any, identifier: String, otpKey: String) => Promise<void>} authenticationUpdateOTPKey
    * @property {(dbCtx: any, identifier: String, credential: AuthInfo) => Promise<void>} authenticationUpdateCredential
    */
@@ -117,7 +117,7 @@ class Authenticator {
     const _scope = _fileScope('createIdentifier');
     try {
       const secureCredential = await this._secureCredential(credential);
-      await this.db.authenticationInsertIdentifier(dbCtx, identifier, secureCredential, otpKey);
+      await this.db.authenticationUpsert(dbCtx, identifier, secureCredential, otpKey);
     } catch (e) {
       this.logger.error(_scope, 'failed', { error: e, identifier });
       throw e;
index dea4a84427e2d9634b10e401a9084b1bea5370f9..534fd02df14165d8029582ab6c3a816b24fbfe9a 100644 (file)
@@ -60,18 +60,18 @@ describe('Authenticator', function () {
     it('covers success', async function () {
       const otpKey = '1234567890123456789012';
       await authenticator.createIdentifier(dbCtx, identifier, credential, otpKey);
-      assert(authenticator.db.authenticationInsertIdentifier.called);
+      assert(authenticator.db.authenticationUpsert.called);
     });
     it('covers failure', async function () {
       const expected = new Error('blah');
-      await authenticator.db.authenticationInsertIdentifier.rejects(expected);
+      await authenticator.db.authenticationUpsert.rejects(expected);
       // assert.rejects was not happy to handle this for some reason
       try {
         await authenticator.createIdentifier(dbCtx, identifier, credential);
         assert.fail('no expecte exception');
       } catch (e) {
         assert.deepStrictEqual(e, expected);
-        assert(authenticator.db.authenticationInsertIdentifier.called);
+        assert(authenticator.db.authenticationUpsert.called);
         assert(authenticator.logger.error.called);
         }
     });
index 62f5f3d14fa0eb7b4e6f48a7478c0f1601b76c47..0df6b9ebb097d225304e8d699418edf2afdf20ff 100644 (file)
@@ -10,7 +10,7 @@ const spyFns = [
 
 const stubFns = [
   'authenticationGet',
-  'authenticationInsertIdentifier',
+  'authenticationUpsert',
   'authenticationSuccess',
   'authenticationUpdateCredential',
   'authenticationUpdateOTPKey',