use native dns promises
[squeep-indieauth-helper] / test / lib / communication.js
index c79d2613f5388485862a3eb83ef7d84304b8582c..7ecad8e817b396f5681953ec72e822bf65afe1e1 100644 (file)
@@ -528,7 +528,7 @@ describe('Communication', function () {
     beforeEach(function () {
       url = 'https://example.com/';
       validationOptions = {};
-      sinon.stub(dns, 'lookupAsync').resolves([{ family: 4, address: '10.11.12.14' }]);
+      sinon.stub(dns.promises, 'lookup').resolves([{ family: 4, address: '10.11.12.14' }]);
     });
     it('rejects invalid url', async function () {
       url = 'bad url';
@@ -550,7 +550,7 @@ describe('Communication', function () {
     beforeEach(function () {
       url = 'https://example.com/';
       validationOptions = {};
-      sinon.stub(dns, 'lookupAsync').resolves([{ family: 4, address: '10.11.12.13' }]);
+      sinon.stub(dns.promises, 'lookup').resolves([{ family: 4, address: '10.11.12.13' }]);
     });
     it('rejects invalid url', async function () {
       await assert.rejects(() => communication.validateClientIdentifier('bad url'), ValidationError);
@@ -594,12 +594,12 @@ describe('Communication', function () {
       assert.strictEqual(result.isLoopback, true);
     });
     it('accepts resolved ipv4 loopback', async function () {
-      dns.lookupAsync.resolves([{ family: 4, address: '127.0.0.1' }]);
+      dns.promises.lookup.resolves([{ family: 4, address: '127.0.0.1' }]);
       const result = await communication.validateClientIdentifier(url, validationOptions);
       assert.strictEqual(result.isLoopback, true);
     });
     it('accepts resolved ipv6 loopback', async function () {
-      dns.lookupAsync.resolves([{ family: 6, address: '::1' }]);
+      dns.promises.lookup.resolves([{ family: 6, address: '::1' }]);
       const result = await communication.validateClientIdentifier(url, validationOptions);
       assert.strictEqual(result.isLoopback, true);
     });
@@ -608,15 +608,15 @@ describe('Communication', function () {
       assert.strictEqual(result.isLoopback, false);
     });
     it('rejects resolution failure', async function () {
-      dns.lookupAsync.rejects(new Error('oh no'));
+      dns.promises.lookup.rejects(new Error('oh no'));
       await assert.rejects(() => communication.validateClientIdentifier(url, validationOptions), ValidationError);
     });
     it('rejects mismatched resolutions', async function () {
-      dns.lookupAsync.onCall(1).resolves([{ family: 4, address: '10.9.8.7' }]);
+      dns.promises.lookup.onCall(1).resolves([{ family: 4, address: '10.9.8.7' }]);
       await assert.rejects(() => communication.validateClientIdentifier(url, validationOptions), ValidationError);
     });
     it('ignores unknown dns family', async function () {
-      dns.lookupAsync.resolves([{ family: 5, address: '10.9.8.7' }]);
+      dns.promises.lookup.resolves([{ family: 5, address: '10.9.8.7' }]);
       const result = await communication.validateClientIdentifier(url, validationOptions);
       assert.strictEqual(result.isLoopback, false);
     });
@@ -626,7 +626,7 @@ describe('Communication', function () {
       assert.strictEqual(result.isLoopback, false);
     });
     it('covers unresolved', async function () {
-      dns.lookupAsync.resolves();
+      dns.promises.lookup.resolves();
       const result = await communication.validateClientIdentifier(url, validationOptions);
       assert.strictEqual(result.isLoopback, false);
     });
@@ -870,7 +870,7 @@ describe('Communication', function () {
     });
   }); // fetchProfile
 
-  describe('redeemProfileCode', function () {
+  describe('redeemCode', function () {
     let expected, urlObj, code, codeVerifier, clientId, redirectURI;
     beforeEach(function () {
       urlObj = new URL('https://example.com/auth');
@@ -887,6 +887,18 @@ describe('Communication', function () {
         me: 'https://profile.example.com/',
       };
 
+      const result = await communication.redeemCode(urlObj, code, codeVerifier, clientId, redirectURI);
+
+      assert.deepStrictEqual(result, expected);
+    });
+    it('covers deprecated method name', async function () {
+      communication.axios.resolves({
+        data: '{"me":"https://profile.example.com/"}',
+      });
+      expected = {
+        me: 'https://profile.example.com/',
+      };
+
       const result = await communication.redeemProfileCode(urlObj, code, codeVerifier, clientId, redirectURI);
 
       assert.deepStrictEqual(result, expected);
@@ -894,11 +906,11 @@ describe('Communication', function () {
     it('covers failure', async function () {
       communication.axios.resolves('Not a JSON payload.');
 
-      const result = await communication.redeemProfileCode(urlObj, code, codeVerifier, clientId, redirectURI);
+      const result = await communication.redeemCode(urlObj, code, codeVerifier, clientId, redirectURI);
 
       assert.strictEqual(result, undefined);
     });
-  }); // redeemProfileCode
+  }); // redeemCode
 
   describe('introspectToken', function () {
     let introspectionUrlObj, authenticationHeader, token;
@@ -958,4 +970,4 @@ describe('Communication', function () {
     });
   }); // deliverTicket
 
-}); // Communication
\ No newline at end of file
+}); // Communication