From 6bda4165d7f300e5f415144cef92b807b627a129 Mon Sep 17 00:00:00 2001 From: JBigman Date: Wed, 26 Jul 2023 13:11:09 +0200 Subject: [PATCH 01/25] Fixed code and unit tests - fixed search: more section title is not always empty, it can contain "Apps" - fixed missing comments (ds:9 => ds:8) - new url called to test throttle, - updated expected results --- lib/app.js | 2 +- lib/search.js | 2 +- test/lib.app.js | 6 ++++-- test/lib.search.js | 8 ++++---- test/utils.throttle.js | 9 ++++++--- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/app.js b/lib/app.js index 7fc41dbc..f29ee11b 100644 --- a/lib/app.js +++ b/lib/app.js @@ -140,7 +140,7 @@ const MAPPINGS = { }, recentChanges: ['ds:5', 1, 2, 144, 1, 1], comments: { - path: ['ds:9', 0], + path: ['ds:8', 0], isArray: true, fun: helper.extractComments } diff --git a/lib/search.js b/lib/search.js index 2f0717ed..08b17ca8 100644 --- a/lib/search.js +++ b/lib/search.js @@ -113,7 +113,7 @@ async function processFirstPage (html, opts, savedApps, mappings) { function isMoreSection (section) { const sectionTitle = R.path(SECTIONS_MAPPING.title, section); - return R.is(String, sectionTitle) && R.isEmpty(sectionTitle); + return R.is(String, sectionTitle); } /** diff --git a/test/lib.app.js b/test/lib.app.js index 51474e71..bd0e54ce 100644 --- a/test/lib.app.js +++ b/test/lib.app.js @@ -112,7 +112,9 @@ describe('App method', () => { it('should get the developer physical address', () => { return gplay.app({ appId: 'com.snapchat.android' }) .then((app) => { - assert.equal(app.developerAddress, '63 Market St.\nVenice CA, 90291'); + assert.equal(app.developerAddress, '2772 Donald Douglas Loop, North\n' + + 'Santa Monica, CA 90405\n' + + 'USA'); }); }); @@ -177,7 +179,7 @@ describe('App method', () => { it('should fetch valid internal developer_id, if it differs from developer_id', () => { return gplay.app({ appId: 'air.com.bitrhymes.bingo' }) .then((app) => { - assert.equal(app.developerInternalID, '6289421402968163029'); + assert.equal(app.developerInternalID, '9028773071151690823'); }); }); diff --git a/test/lib.search.js b/test/lib.search.js index 0565af5b..ac99a8d6 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -64,11 +64,11 @@ describe('Search method', () => { }); describe('more results mapping', () => { - it('schould return few netflix apps', () => { + it('should return few netflix apps', () => { return gplay.search({ term: 'netflix' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); - assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.StrangerThings'); + assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); }); }); @@ -76,11 +76,11 @@ describe('Search method', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); - assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.StrangerThings'); + assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.android_vr'); }); }); - it('should reutrn few google mail apps', () => { + it('should return few google mail apps', () => { return gplay.search({ term: 'gmail' }) .then((apps) => { assert.equal(apps[0].appId, 'com.google.android.gm'); diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 1ed50c67..5aa1ae8d 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -8,18 +8,21 @@ it('Should make three requests with 5000ms interval. (Throttle function)', funct interval: 5000 }); - Promise.all([req({ url: 'https://httpbin.org/uuid' }), req({ url: 'https://httpbin.org/uuid' }), req({ url: 'https://httpbin.org/uuid' })]) + Promise.all([ + req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' }), + req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' }), + req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) .then((dates) => { const firstAndSecondReq = dates[1] - dates[0]; const secondAndThirdReq = dates[2] - dates[1]; if ( (firstAndSecondReq >= 5000 && firstAndSecondReq <= 6500) && - (secondAndThirdReq >= 5000 && secondAndThirdReq <= 6500) + (secondAndThirdReq >= 5000 && secondAndThirdReq <= 6500) ) { done(); } else { - throw new Error('Wrong interval beetween requests.'); + throw new Error('Wrong interval between requests.'); } }); }); From ccb3bb4fe45ecae7b2ccf3dfe7851733632edc89 Mon Sep 17 00:00:00 2001 From: JBigman Date: Wed, 26 Jul 2023 13:24:32 +0200 Subject: [PATCH 02/25] Bump semver from 6.3.0 to 6.3.1 and word-wrap from 1.2.3 to 1.2.4 --- package-lock.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 56eccb8a..8af061b7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2895,9 +2895,9 @@ ] }, "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -3199,9 +3199,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -5404,9 +5404,9 @@ "dev": true }, "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true }, "serialize-javascript": { @@ -5636,9 +5636,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "workerpool": { From afca862aa038104678a4c8f8fa7b7b407884a978 Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 26 Jul 2023 13:54:35 +0200 Subject: [PATCH 03/25] String optimisation --- lib/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/search.js b/lib/search.js index 08b17ca8..320758f3 100644 --- a/lib/search.js +++ b/lib/search.js @@ -179,7 +179,7 @@ function search (appData, opts) { } if (opts.num && opts.num > 250) { - throw Error("The number of results can't exceed 250"); + throw Error('The number of results can\'t exceed 250'); } opts = { From 32c4b0087dd1be12a0a0c26ebdf1316affcb999e Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 26 Jul 2023 14:02:30 +0200 Subject: [PATCH 04/25] Use https://yesno.wtf/api for throttle tests --- test/utils.throttle.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 5aa1ae8d..655e137b 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -8,10 +8,7 @@ it('Should make three requests with 5000ms interval. (Throttle function)', funct interval: 5000 }); - Promise.all([ - req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' }), - req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' }), - req({ url: 'https://www.randomnumberapi.com/api/v1.0/random' })]) + Promise.all([req({ url: 'https://yesno.wtf/api' }), req({ url: 'https://yesno.wtf/api' }), req({ url: 'https://yesno.wtf/api' })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) .then((dates) => { const firstAndSecondReq = dates[1] - dates[0]; From 3c9ba745a9ade8a2cfdb02744cb315df843befa6 Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 26 Jul 2023 16:21:57 +0200 Subject: [PATCH 05/25] Set timeout to 18000ms: (3 times 5000ms + margin) --- test/utils.throttle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 655e137b..47eea9cd 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -2,7 +2,7 @@ const requestLib = require('got'); const throttled = require('../lib/utils/throttle'); it('Should make three requests with 5000ms interval. (Throttle function)', function (done) { - this.timeout(15000); + this.timeout(18000); const req = throttled(requestLib, { limit: 1, interval: 5000 From e6467c458381ab28631509386ab4e9bba224e79d Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 26 Jul 2023 16:24:43 +0200 Subject: [PATCH 06/25] Set timeout to 30000ms: because we can't ensure called rest services will answer quickly --- test/utils.throttle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 47eea9cd..263ae029 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -2,7 +2,7 @@ const requestLib = require('got'); const throttled = require('../lib/utils/throttle'); it('Should make three requests with 5000ms interval. (Throttle function)', function (done) { - this.timeout(18000); + this.timeout(30000); const req = throttled(requestLib, { limit: 1, interval: 5000 From e49ac115ddbd294c2419bd26ce263b0f431f3e58 Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 26 Jul 2023 16:30:58 +0200 Subject: [PATCH 07/25] Rerun checks --- lib/utils/throttle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/throttle.js b/lib/utils/throttle.js index 7ab965a0..e615f368 100644 --- a/lib/utils/throttle.js +++ b/lib/utils/throttle.js @@ -26,7 +26,7 @@ function Throttle () { * Function is basically if else statement, that checks if the function could be executed right now or need to wait until the end of a delay. * For the condition, it uses interval and limit options and compares them to the state variables. * @return result of the executed function from parent settingOption @function - */ + */ return async function returnedFunction (...args) { // Set Date Variable if it's Empty if (!startedAt) startedAt = Date.now(); From f09e5377aa9e5671f44ca16e2fcd2627ce58bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20G?= Date: Thu, 27 Jul 2023 13:33:44 +0200 Subject: [PATCH 08/25] Create main.yml --- .github/workflows/main.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..4ad2ae26 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,22 @@ +name: build +on: + push: + branches: + - main + pull_request: +jobs: + checks: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x, 18.x] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run lint + - run: npm test + - run: npm audit From 505b4ef3d7a84d28e6e2b6591dc7438f05c8b772 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 27 Jul 2023 14:11:17 +0200 Subject: [PATCH 09/25] Added logs to understand why check fails --- test/lib.search.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lib.search.js b/test/lib.search.js index ac99a8d6..2174026b 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -76,6 +76,7 @@ describe('Search method', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); + console.log(apps.map((app) => app.appId)); assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.android_vr'); }); }); From 4cdf2b3af27130bf7cefc07a99e144b8071ad612 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 27 Jul 2023 14:17:07 +0200 Subject: [PATCH 10/25] Added logs to understand why check fails --- .github/workflows/main.yml | 22 ---------------------- test/lib.search.js | 3 ++- 2 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 4ad2ae26..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: build -on: - push: - branches: - - main - pull_request: -jobs: - checks: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [16.x, 18.x] - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - run: npm ci - - run: npm run lint - - run: npm test - - run: npm audit diff --git a/test/lib.search.js b/test/lib.search.js index 2174026b..c2e84c19 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -67,6 +67,7 @@ describe('Search method', () => { it('should return few netflix apps', () => { return gplay.search({ term: 'netflix' }) .then((apps) => { + console.log(apps.map((app) => app.appId)); assert.equal(apps[0].appId, 'com.netflix.mediaclient'); assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); }); @@ -75,8 +76,8 @@ describe('Search method', () => { it('should return few netflix apps from german store with german language', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { - assert.equal(apps[0].appId, 'com.netflix.mediaclient'); console.log(apps.map((app) => app.appId)); + assert.equal(apps[0].appId, 'com.netflix.mediaclient'); assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.android_vr'); }); }); From 9f098ccc1f6d553435207704338f4e026f4a6f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20G?= Date: Thu, 27 Jul 2023 23:28:56 +0200 Subject: [PATCH 11/25] Removed logs --- test/lib.search.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/lib.search.js b/test/lib.search.js index c2e84c19..ac99a8d6 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -67,7 +67,6 @@ describe('Search method', () => { it('should return few netflix apps', () => { return gplay.search({ term: 'netflix' }) .then((apps) => { - console.log(apps.map((app) => app.appId)); assert.equal(apps[0].appId, 'com.netflix.mediaclient'); assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); }); @@ -76,7 +75,6 @@ describe('Search method', () => { it('should return few netflix apps from german store with german language', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { - console.log(apps.map((app) => app.appId)); assert.equal(apps[0].appId, 'com.netflix.mediaclient'); assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.android_vr'); }); From 378a71fe6e3811cde818b44ab942cb261c04cba4 Mon Sep 17 00:00:00 2001 From: jbigman Date: Fri, 28 Jul 2023 00:26:08 +0200 Subject: [PATCH 12/25] Updated expected result for more reliable ones --- test/lib.search.js | 2 +- test/lib.similar.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib.search.js b/test/lib.search.js index ac99a8d6..5f57653e 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -76,7 +76,7 @@ describe('Search method', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); - assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.android_vr'); + assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); }); }); diff --git a/test/lib.similar.js b/test/lib.similar.js index d686550d..cc962a7c 100644 --- a/test/lib.similar.js +++ b/test/lib.similar.js @@ -11,7 +11,7 @@ describe('Similar method', () => { }); it('should fetch games from different developers', () => { - return gplay.similar({ appId: 'com.mojang.minecraftpe' }) + return gplay.similar({ appId: 'com.instagram.android' }) .then((apps) => assert.isTrue(apps.some(app => app.developer !== apps[0].developer))); }); }); From 74cd435e36fc554fa4ce3ba31aae0e960e4f2948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20G?= Date: Fri, 28 Jul 2023 14:38:31 +0200 Subject: [PATCH 13/25] 39aaa8a9(Node version 12.x and 14.x are not supported anymore: https://endoflife.date/nodejs) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 78bd0531..cad16df1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x, 14.x, 16.x, 18.x] + node-version: [16.x, 18.x, 20.x] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} From b7dfebd2161463b3e455096472f2948db8ddc709 Mon Sep 17 00:00:00 2001 From: jbigman Date: Fri, 28 Jul 2023 14:45:41 +0200 Subject: [PATCH 14/25] Updated should return apps from suggested search in european country results. --- test/lib.search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib.search.js b/test/lib.search.js index 5f57653e..5ae56235 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -122,7 +122,7 @@ describe('Search method', () => { return gplay.search({ term: 'runing tracker', country: 'GR' }) .then((apps) => { apps.map(assertValidApp); - assertIdsInArray(apps, 'com.runtastic.android', 'running.tracker.gps.map', 'com.google.android.apps.fitness'); + assertIdsInArray(apps, 'com.runtastic.android', 'running.tracker.gps.map'); }); }); }); From 86395bfb3fed04cec9aad439c02fcd3747acbbb0 Mon Sep 17 00:00:00 2001 From: jbigman Date: Fri, 28 Jul 2023 14:58:41 +0200 Subject: [PATCH 15/25] Updated assertions "search with german language" --- test/lib.search.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib.search.js b/test/lib.search.js index 5ae56235..35362762 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -76,7 +76,8 @@ describe('Search method', () => { return gplay.search({ term: 'netflix', lang: 'de', country: 'DE' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); - assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); + // Don't check specific ids, as results may vary + assert.isAbove(apps.length, 1); }); }); From 880a00437108c1d2f2d356c21a99942235a1bfde Mon Sep 17 00:00:00 2001 From: jbigman Date: Wed, 2 Aug 2023 18:19:26 +0200 Subject: [PATCH 16/25] Added back preregister property and added earlyAccessEnabled --- README.md | 3 +++ lib/app.js | 8 ++++++++ test/lib.app.js | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15373273..634447ce 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,9 @@ Results: version: 'Varies with device', recentChanges: 'Improved offline translations with upgraded language downloads', comments: [], + preregister: false, + earlyAccessEnabled: false, + isAvailableInPlayPass: false, editorsChoice: true, features: [ { diff --git a/lib/app.js b/lib/app.js index 6eca8269..b53a9673 100644 --- a/lib/app.js +++ b/lib/app.js @@ -156,6 +156,14 @@ const MAPPINGS = { isArray: true, fun: helper.extractComments }, + preregister: { + path: ['ds:5', 1, 2, 18, 0], + fun: (val) => val === 1 + }, + earlyAccessEnabled: { + path: ['ds:5', 1, 2, 18, 2], + fun: (val) => typeof val === 'string' + }, isAvailableInPlayPass: { path: ['ds:5', 1, 2, 62], fun: (field) => !!field diff --git a/test/lib.app.js b/test/lib.app.js index 0d4e3ff4..a8a12aca 100644 --- a/test/lib.app.js +++ b/test/lib.app.js @@ -44,7 +44,8 @@ const validateAppDetails = (app) => { assert.isTrue(app.free); assert.isTrue(app.offersIAP); assert.isString(app.IAPRange); - // assert(app.preregister === false); + assert.isFalse(app.preregister); + assert.isFalse(app.earlyAccessEnabled); assert.equal(app.developer, 'Jam City, Inc.'); assert.equal(app.developerId, '5509190841173705883'); From 9f54194a741b08586f38044b050b5da472315389 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 18:04:55 +0200 Subject: [PATCH 17/25] Added androidMaxVersion property --- README.md | 1 + lib/app.js | 4 ++++ test/lib.app.js | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 634447ce..5941f145 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Results: size: 'Varies with device', androidVersion: 'VARY', androidVersionText: 'Varies with device', + androidMaxVersion: 'VARY', developer: 'Google LLC', developerId: '5700313618786177705', developerEmail: 'translate-android-support@google.com', diff --git a/lib/app.js b/lib/app.js index b53a9673..856f2324 100644 --- a/lib/app.js +++ b/lib/app.js @@ -94,6 +94,10 @@ const MAPPINGS = { path: ['ds:5', 1, 2, 140, 1, 1, 0, 0, 1], fun: (version) => version || 'Varies with device' }, + androidMaxVersion: { + path: ['ds:5', 1, 2, 140, 1, 1, 0, 1, 1], + fun: helper.normalizeAndroidVersion + }, developer: ['ds:5', 1, 2, 68, 0], developerId: { path: ['ds:5', 1, 2, 68, 1, 4, 2], diff --git a/test/lib.app.js b/test/lib.app.js index a8a12aca..38638693 100644 --- a/test/lib.app.js +++ b/test/lib.app.js @@ -37,6 +37,7 @@ const validateAppDetails = (app) => { assert.isString(app.contentRating); assert.equal(app.androidVersion, '7.0'); + assert.equal(app.androidMaxVersion, 'VARY'); assert.isBoolean(app.available); assert.equal(app.priceText, 'Free'); @@ -196,4 +197,12 @@ describe('App method', () => { assert.equal(app.available, false); }); }); + + it('should fetch android version limit set for some old apps', () => { + return gplay.app({ appId: 'air.com.zinkia.playset' }) + .then((app) => { + assert.equal(app.androidVersion, '4.2'); + assert.equal(app.androidMaxVersion, '7.1.1'); + }); + }); }); From ceeeebeab5404c5e0c658d09c89daca432bd6bb4 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 18:09:00 +0200 Subject: [PATCH 18/25] Added originalPrice and discountEndDate properties --- lib/app.js | 6 ++++++ test/lib.app.js | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/app.js b/lib/app.js index 856f2324..36ddb061 100644 --- a/lib/app.js +++ b/lib/app.js @@ -67,6 +67,12 @@ const MAPPINGS = { path: ['ds:5', 1, 2, 57, 0, 0, 0, 0, 1, 0, 0], fun: (val) => val / 1000000 || 0 }, + // If there is a discount, originalPrice if filled. + originalPrice: { + path: ['ds:5', 1, 2, 57, 0, 0, 0, 0, 1, 1, 0], + fun: (price) => price ? price / 1000000 : undefined + }, + discountEndDate: ['ds:5', 1, 2, 57, 0, 0, 0, 0, 14, 1], free: { path: ['ds:5', 1, 2, 57, 0, 0, 0, 0, 1, 0, 0], // considered free only if price is exactly zero diff --git a/test/lib.app.js b/test/lib.app.js index 38638693..f9605d08 100644 --- a/test/lib.app.js +++ b/test/lib.app.js @@ -47,6 +47,8 @@ const validateAppDetails = (app) => { assert.isString(app.IAPRange); assert.isFalse(app.preregister); assert.isFalse(app.earlyAccessEnabled); + assert.isUndefined(app.originalPrice); + assert.isUndefined(app.discountEndDate); assert.equal(app.developer, 'Jam City, Inc.'); assert.equal(app.developerId, '5509190841173705883'); From 93ce5df6bb13a4f1e1ef20464e97357c4e38715d Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 18:18:44 +0200 Subject: [PATCH 19/25] Fixed throttle tests (add mocks and updated expected results) --- package-lock.json | 226 +++++++++++++++++++++++++++++++++++++++-- package.json | 3 +- test/lib.search.js | 2 +- test/utils.throttle.js | 50 +++++---- 4 files changed, 251 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8af061b7..5810eb68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "debug": "^3.1.0", "got": "^11.8.6", "memoizee": "^0.4.11", - "ramda": "^0.21.0" + "ramda": "^0.21.0", + "sinon": "^15.2.0" }, "devDependencies": { "chai": "^4.1.2", @@ -126,6 +127,45 @@ "url": "https://github.com/sindresorhus/is?sponsor=1" } }, + "node_modules/@sinonjs/commons": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", + "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", + "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/text-encoding": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==" + }, "node_modules/@szmarczak/http-timer": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", @@ -1711,7 +1751,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "engines": { "node": ">=8" } @@ -2104,6 +2143,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -2151,6 +2195,11 @@ "json5": "lib/cli.js" } }, + "node_modules/just-extend": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==" + }, "node_modules/keyv": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.2.tgz", @@ -2185,6 +2234,11 @@ "node": ">=4" } }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -2470,6 +2524,26 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" }, + "node_modules/nise": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", + "integrity": "sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==", + "dependencies": { + "@sinonjs/commons": "^2.0.0", + "@sinonjs/fake-timers": "^10.0.2", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "path-to-regexp": "^1.7.0" + } + }, + "node_modules/nise/node_modules/@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "dependencies": { + "type-detect": "4.0.8" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -2688,6 +2762,14 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dependencies": { + "isarray": "0.0.1" + } + }, "node_modules/pathval": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", @@ -2947,6 +3029,31 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sinon": { + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-15.2.0.tgz", + "integrity": "sha512-nPS85arNqwBXaIsFCkolHjGIkFo+Oxu9vbgmBJizLAhqe6P2o3Qmj3KCUoRkfhHtvgDhZdWD3risLHAUJ8npjw==", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^10.3.0", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.1.0", + "nise": "^5.1.4", + "supports-color": "^7.2.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/sinon" + } + }, + "node_modules/sinon/node_modules/diff": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.1.0.tgz", + "integrity": "sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -3026,7 +3133,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -3111,7 +3217,6 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, "engines": { "node": ">=4" } @@ -3373,6 +3478,47 @@ "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==" }, + "@sinonjs/commons": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.0.tgz", + "integrity": "sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==", + "requires": { + "type-detect": "4.0.8" + } + }, + "@sinonjs/fake-timers": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "requires": { + "@sinonjs/commons": "^3.0.0" + } + }, + "@sinonjs/samsam": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-8.0.0.tgz", + "integrity": "sha512-Bp8KUVlLp8ibJZrnvq2foVhP0IVX2CIprMJPK0vqGqgrDa0OHVKeZyBykqskkrdxV6yKBPmGasO8LVjAKR3Gew==", + "requires": { + "@sinonjs/commons": "^2.0.0", + "lodash.get": "^4.4.2", + "type-detect": "^4.0.8" + }, + "dependencies": { + "@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "requires": { + "type-detect": "4.0.8" + } + } + } + }, + "@sinonjs/text-encoding": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==" + }, "@szmarczak/http-timer": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", @@ -4567,8 +4713,7 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "has-property-descriptors": { "version": "1.0.0", @@ -4831,6 +4976,11 @@ "call-bind": "^1.0.2" } }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4872,6 +5022,11 @@ "minimist": "^1.2.0" } }, + "just-extend": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==" + }, "keyv": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.2.tgz", @@ -4900,6 +5055,11 @@ "path-exists": "^3.0.0" } }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==" + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -5113,6 +5273,28 @@ "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" }, + "nise": { + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", + "integrity": "sha512-8+Ib8rRJ4L0o3kfmyVCL7gzrohyDe0cMFTBa2d364yIrEGMEoetznKJx899YxjybU6bL9SQkYPSBBs1gyYs8Xg==", + "requires": { + "@sinonjs/commons": "^2.0.0", + "@sinonjs/fake-timers": "^10.0.2", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "path-to-regexp": "^1.7.0" + }, + "dependencies": { + "@sinonjs/commons": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", + "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "requires": { + "type-detect": "4.0.8" + } + } + } + }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -5268,6 +5450,14 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "requires": { + "isarray": "0.0.1" + } + }, "pathval": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", @@ -5444,6 +5634,26 @@ "object-inspect": "^1.9.0" } }, + "sinon": { + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-15.2.0.tgz", + "integrity": "sha512-nPS85arNqwBXaIsFCkolHjGIkFo+Oxu9vbgmBJizLAhqe6P2o3Qmj3KCUoRkfhHtvgDhZdWD3risLHAUJ8npjw==", + "requires": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^10.3.0", + "@sinonjs/samsam": "^8.0.0", + "diff": "^5.1.0", + "nise": "^5.1.4", + "supports-color": "^7.2.0" + }, + "dependencies": { + "diff": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.1.0.tgz", + "integrity": "sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==" + } + } + }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -5502,7 +5712,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "requires": { "has-flag": "^4.0.0" } @@ -5571,8 +5780,7 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" }, "type-fest": { "version": "0.20.2", diff --git a/package.json b/package.json index 669f3749..edfd9cbf 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "debug": "^3.1.0", "got": "^11.8.6", "memoizee": "^0.4.11", - "ramda": "^0.21.0" + "ramda": "^0.21.0", + "sinon": "^15.2.0" }, "devDependencies": { "chai": "^4.1.2", diff --git a/test/lib.search.js b/test/lib.search.js index 35362762..09cee084 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -68,7 +68,7 @@ describe('Search method', () => { return gplay.search({ term: 'netflix' }) .then((apps) => { assert.equal(apps[0].appId, 'com.netflix.mediaclient'); - assertIdsInArray(apps, 'com.netflix.ninja', 'com.netflix.NGP.Poinpy'); + assert.isAbove(apps.length, 0); }); }); diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 263ae029..37eae326 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -1,25 +1,37 @@ const requestLib = require('got'); const throttled = require('../lib/utils/throttle'); +const sinon = require('sinon'); +const assert = require('chai').assert; -it('Should make three requests with 5000ms interval. (Throttle function)', function (done) { - this.timeout(30000); - const req = throttled(requestLib, { - limit: 1, - interval: 5000 +describe('Throttle tests', function () { + let server; + this.timeout(15000); + + before(function () { + server = sinon.fakeServer.create(); + }); + after(function () { + server.restore(); }); - Promise.all([req({ url: 'https://yesno.wtf/api' }), req({ url: 'https://yesno.wtf/api' }), req({ url: 'https://yesno.wtf/api' })]) - .then((response) => response.map(req => new Date(req.headers.date).getTime())) - .then((dates) => { - const firstAndSecondReq = dates[1] - dates[0]; - const secondAndThirdReq = dates[2] - dates[1]; - if ( - (firstAndSecondReq >= 5000 && firstAndSecondReq <= 6500) && - (secondAndThirdReq >= 5000 && secondAndThirdReq <= 6500) - ) { - done(); - } else { - throw new Error('Wrong interval between requests.'); - } + const url = 'https://yesno.wtf/api'; + + it('Should make three requests with 5000ms interval. (Throttle function)', function () { + server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); + const req = throttled(requestLib, { + limit: 1, + interval: 5000 }); -}); + return Promise.all([req({ url }), req({ url }), req({ url })]) + .then((response) => response.map(req => new Date(req.headers.date).getTime())) + .then((dates) => { + const firstAndSecondReq = dates[1] - dates[0]; + const secondAndThirdReq = dates[2] - dates[1]; + + assert.isAtLeast(firstAndSecondReq, 5000); + assert.isAtMost(firstAndSecondReq, 6500); + assert.isAtLeast(secondAndThirdReq, 5000); + assert.isAtMost(secondAndThirdReq, 6500); + }); + }); +}); \ No newline at end of file From c336f832f2f1b2bb02d1283292c17acbc024c44f Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 18:22:03 +0200 Subject: [PATCH 20/25] Fixed eslint eol-last --- test/utils.throttle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 37eae326..7f22c231 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -34,4 +34,4 @@ describe('Throttle tests', function () { assert.isAtMost(secondAndThirdReq, 6500); }); }); -}); \ No newline at end of file +}); From 55d435fb22fe48c87a37ebd1095ee1ffd01a0a62 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 18:25:44 +0200 Subject: [PATCH 21/25] Fixed gmail search assertions --- test/lib.search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib.search.js b/test/lib.search.js index 09cee084..bcb29c36 100644 --- a/test/lib.search.js +++ b/test/lib.search.js @@ -85,7 +85,7 @@ describe('Search method', () => { return gplay.search({ term: 'gmail' }) .then((apps) => { assert.equal(apps[0].appId, 'com.google.android.gm'); - assertIdsInArray(apps, 'com.google.android.gm.lite', 'com.google.android.apps.docs'); + assert.isTrue(apps.some((app) => app.appId === 'com.google.android.gm.lite')); }); }); From 3364f8a54d9409c29cf7d423c1639e66c221cb82 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 19:52:49 +0200 Subject: [PATCH 22/25] Moved sinon in dev dependencies, updated throttle tests with a 1000ms interval and added comments on sinon usage. --- package.json | 4 ++-- test/utils.throttle.js | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index edfd9cbf..aaed6e47 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ "debug": "^3.1.0", "got": "^11.8.6", "memoizee": "^0.4.11", - "ramda": "^0.21.0", - "sinon": "^15.2.0" + "ramda": "^0.21.0" }, "devDependencies": { "chai": "^4.1.2", @@ -41,6 +40,7 @@ "eslint-plugin-standard": "^4.0.0", "mocha": "^9.1.4", "promise-log": "^0.1.0", + "sinon": "^15.2.0", "validator": "^13.7.0" } } diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 7f22c231..dbff3cd2 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -5,22 +5,27 @@ const assert = require('chai').assert; describe('Throttle tests', function () { let server; - this.timeout(15000); + // Create a fake http server to emulate http call and responses. before(function () { server = sinon.fakeServer.create(); }); + + // Remove any server responses added in current test suite. after(function () { server.restore(); }); - const url = 'https://yesno.wtf/api'; + const url = 'https://yesno.wtf/api'; // Fake url used in this test, it could be anything. + + it('Should make three requests with 1000ms interval. (Throttle function)', function () { - it('Should make three requests with 5000ms interval. (Throttle function)', function () { + // If there is any http request with specified url, the http call will be handled by the fake server and return specified object + // This way we remove the dependance with any http api. server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); const req = throttled(requestLib, { limit: 1, - interval: 5000 + interval: 2000 }); return Promise.all([req({ url }), req({ url }), req({ url })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) @@ -28,10 +33,10 @@ describe('Throttle tests', function () { const firstAndSecondReq = dates[1] - dates[0]; const secondAndThirdReq = dates[2] - dates[1]; - assert.isAtLeast(firstAndSecondReq, 5000); - assert.isAtMost(firstAndSecondReq, 6500); - assert.isAtLeast(secondAndThirdReq, 5000); - assert.isAtMost(secondAndThirdReq, 6500); + assert.isAtLeast(firstAndSecondReq, 1000); + assert.isAtMost(firstAndSecondReq, 2000); + assert.isAtLeast(secondAndThirdReq, 1000); + assert.isAtMost(secondAndThirdReq, 2000); }); }); }); From 73d3732af19b1993ac8da2637fc895de23140c2c Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 19:57:18 +0200 Subject: [PATCH 23/25] Fixed eslint --- test/utils.throttle.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index dbff3cd2..e55c3fcb 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -19,7 +19,6 @@ describe('Throttle tests', function () { const url = 'https://yesno.wtf/api'; // Fake url used in this test, it could be anything. it('Should make three requests with 1000ms interval. (Throttle function)', function () { - // If there is any http request with specified url, the http call will be handled by the fake server and return specified object // This way we remove the dependance with any http api. server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); From f16c23a49eedda9e5329d6905d85b4da10a3bd06 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 20:00:43 +0200 Subject: [PATCH 24/25] Moved sinon in dev dependencies, updated throttle tests with a 1000ms interval and added comments on sinon usage. --- test/utils.throttle.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index e55c3fcb..2a266e11 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -19,12 +19,12 @@ describe('Throttle tests', function () { const url = 'https://yesno.wtf/api'; // Fake url used in this test, it could be anything. it('Should make three requests with 1000ms interval. (Throttle function)', function () { - // If there is any http request with specified url, the http call will be handled by the fake server and return specified object - // This way we remove the dependance with any http api. + // If we don't want to rely on the availability of a particular api we can use mocks. + // The fake server intercept http calls and return specified objects if it mach the same method/url. server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); const req = throttled(requestLib, { limit: 1, - interval: 2000 + interval: 1000 }); return Promise.all([req({ url }), req({ url }), req({ url })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) From d944ed0dfa71d79420283c43bff496f603d18328 Mon Sep 17 00:00:00 2001 From: jbigman Date: Thu, 3 Aug 2023 20:06:54 +0200 Subject: [PATCH 25/25] Updated throttle to 2000ms interval and assertions checks results +/- 1000ms --- test/utils.throttle.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/utils.throttle.js b/test/utils.throttle.js index 2a266e11..fe25721f 100644 --- a/test/utils.throttle.js +++ b/test/utils.throttle.js @@ -4,6 +4,7 @@ const sinon = require('sinon'); const assert = require('chai').assert; describe('Throttle tests', function () { + this.timeout(6000); let server; // Create a fake http server to emulate http call and responses. @@ -18,13 +19,13 @@ describe('Throttle tests', function () { const url = 'https://yesno.wtf/api'; // Fake url used in this test, it could be anything. - it('Should make three requests with 1000ms interval. (Throttle function)', function () { + it('Should make three requests with 2000ms interval. (Throttle function)', function () { // If we don't want to rely on the availability of a particular api we can use mocks. // The fake server intercept http calls and return specified objects if it mach the same method/url. server.respondWith('GET', url, JSON.stringify({ test: 'this works' })); const req = throttled(requestLib, { limit: 1, - interval: 1000 + interval: 2000 }); return Promise.all([req({ url }), req({ url }), req({ url })]) .then((response) => response.map(req => new Date(req.headers.date).getTime())) @@ -33,9 +34,9 @@ describe('Throttle tests', function () { const secondAndThirdReq = dates[2] - dates[1]; assert.isAtLeast(firstAndSecondReq, 1000); - assert.isAtMost(firstAndSecondReq, 2000); + assert.isAtMost(firstAndSecondReq, 3000); assert.isAtLeast(secondAndThirdReq, 1000); - assert.isAtMost(secondAndThirdReq, 2000); + assert.isAtMost(secondAndThirdReq, 3000); }); }); });