From c9f7b74bc7625b6e6e62debb5d740f36c16c370c Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 12 Jun 2018 06:51:04 +0200
Subject: [PATCH] refactor: add releases to lookupUpdates return

---
 .../repository/process/lookup/index.js        |  6 +++
 .../lookup/__snapshots__/index.spec.js.snap   | 37 +++++++++++++++++++
 .../repository/process/lookup/index.spec.js   | 12 ++++++
 3 files changed, 55 insertions(+)

diff --git a/lib/workers/repository/process/lookup/index.js b/lib/workers/repository/process/lookup/index.js
index f002ed0e1d..c5bc16a6a6 100644
--- a/lib/workers/repository/process/lookup/index.js
+++ b/lib/workers/repository/process/lookup/index.js
@@ -136,7 +136,13 @@ async function lookupUpdates(config) {
   if (!(repositoryUrl && repositoryUrl.length)) {
     repositoryUrl = null;
   }
+  const filteredReleases = releases.filter(
+    release =>
+      filteredVersions.includes(release.version) ||
+      release.version === fromVersion
+  );
   return {
+    releases: filteredReleases,
     repositoryUrl,
     updates,
   };
diff --git a/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap b/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap
index 87e1a28585..ccc9b3bd23 100644
--- a/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap
+++ b/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap
@@ -228,6 +228,43 @@ Array [
 ]
 `;
 
+exports[`manager/npm/lookup .lookupUpdates() returns complex object 1`] = `
+Object {
+  "releases": Array [
+    Object {
+      "canBeUnpublished": false,
+      "gitRef": "b26cace16f6070e756b6a546cf2693bece03f8f8",
+      "time": "2015-04-26T16:42:11.311Z",
+      "version": "1.3.0",
+    },
+    Object {
+      "canBeUnpublished": false,
+      "gitRef": "05e20dc704421ca820553721c7178168a8461506",
+      "time": "2015-05-09T16:52:40.699Z",
+      "version": "1.4.0",
+    },
+    Object {
+      "canBeUnpublished": false,
+      "gitRef": "d373079d3620152e3d60e82f27265a09ee0e81bd",
+      "time": "2015-05-17T04:25:07.299Z",
+      "version": "1.4.1",
+    },
+  ],
+  "repositoryUrl": "https://github.com/kriskowal/q",
+  "updates": Array [
+    Object {
+      "canBeUnpublished": false,
+      "fromVersion": "1.3.0",
+      "newMajor": 1,
+      "newMinor": 4,
+      "newValue": "1.4.1",
+      "toVersion": "1.4.1",
+      "type": "minor",
+    },
+  ],
+}
+`;
+
 exports[`manager/npm/lookup .lookupUpdates() returns minor update if automerging both patch and minor 1`] = `
 Array [
   Object {
diff --git a/test/workers/repository/process/lookup/index.spec.js b/test/workers/repository/process/lookup/index.spec.js
index c3c0c300dc..216a4e8a4c 100644
--- a/test/workers/repository/process/lookup/index.spec.js
+++ b/test/workers/repository/process/lookup/index.spec.js
@@ -846,5 +846,17 @@ describe('manager/npm/lookup', () => {
       const res = await lookup.lookupUpdates(config);
       expect(res.updates).toMatchSnapshot();
     });
+    it('returns complex object', async () => {
+      config.currentValue = '1.3.0';
+      config.depName = 'q';
+      config.purl = 'pkg:npm/q';
+      nock('https://registry.npmjs.org')
+        .get('/q')
+        .reply(200, qJson);
+      const res = await lookup.lookupUpdates(config);
+      expect(res).toMatchSnapshot();
+      expect(res.releases).toHaveLength(3);
+      expect(res.repositoryUrl).toBeDefined();
+    });
   });
 });
-- 
GitLab