From b4d6c4cc500bbb282ba207c58a412f475bfb7874 Mon Sep 17 00:00:00 2001 From: modos189 Date: Sun, 25 Dec 2022 22:16:04 +0300 Subject: [PATCH 1/3] Fixed a bug when deleting a custom plugin that overwrites a built-in plugin. Added testing for this --- src/manager.js | 6 +- test/fixtures/release/meta.json | 9 ++ .../fixtures/release/plugins/missions.meta.js | 13 +++ .../fixtures/release/plugins/missions.user.js | 13 +++ test/manager.1.build-in.spec.js | 7 +- test/manager.2.external.spec.js | 102 ++++++++++++++++-- 6 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/release/plugins/missions.meta.js create mode 100644 test/fixtures/release/plugins/missions.user.js diff --git a/src/manager.js b/src/manager.js index 8aa26d1..b4c1b64 100644 --- a/src/manager.js +++ b/src/manager.js @@ -183,7 +183,11 @@ export class Manager extends Worker { } if (action === 'delete') { if (plugins_flat[uid]['override']) { - plugins_flat[uid] = { ...plugins_local[uid] }; + if (plugins_local[uid] !== undefined) { + plugins_flat[uid] = { ...plugins_local[uid] }; + } + plugins_flat[uid]['user'] = false; + plugins_flat[uid]['override'] = false; plugins_flat[uid]['status'] = 'off'; } else { delete plugins_flat[uid]; diff --git a/test/fixtures/release/meta.json b/test/fixtures/release/meta.json index 8b9a828..8ec05f5 100644 --- a/test/fixtures/release/meta.json +++ b/test/fixtures/release/meta.json @@ -12,6 +12,15 @@ "description": "Displays the per-team AP gains available in the current view.", "namespace": "https://github.com/IITC-CE/ingress-intel-total-conversion", "version": "0.4.2" + }, + { + "filename": "missions.user.js", + "id": "missions", + "name": "Missions", + "author": "jonatkins", + "description": "View missions. Marking progress on waypoints/missions basis. Showing mission paths on the map.", + "namespace": "https://github.com/IITC-CE/ingress-intel-total-conversion", + "version": "0.3.0" } ] }, diff --git a/test/fixtures/release/plugins/missions.meta.js b/test/fixtures/release/plugins/missions.meta.js new file mode 100644 index 0000000..b64efd9 --- /dev/null +++ b/test/fixtures/release/plugins/missions.meta.js @@ -0,0 +1,13 @@ +// ==UserScript== +// @author jonatkins +// @name IITC plugin: Missions +// @category Info +// @version 0.3.0 +// @description View missions. Marking progress on waypoints/missions basis. Showing mission paths on the map. +// @id missions +// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion +// @updateURL https://iitc.app/build/release/plugins/missions.meta.js +// @downloadURL https://iitc.app/build/release/plugins/missions.user.js +// @match https://intel.ingress.com/* +// @grant none +// ==/UserScript== diff --git a/test/fixtures/release/plugins/missions.user.js b/test/fixtures/release/plugins/missions.user.js new file mode 100644 index 0000000..b64efd9 --- /dev/null +++ b/test/fixtures/release/plugins/missions.user.js @@ -0,0 +1,13 @@ +// ==UserScript== +// @author jonatkins +// @name IITC plugin: Missions +// @category Info +// @version 0.3.0 +// @description View missions. Marking progress on waypoints/missions basis. Showing mission paths on the map. +// @id missions +// @namespace https://github.com/IITC-CE/ingress-intel-total-conversion +// @updateURL https://iitc.app/build/release/plugins/missions.meta.js +// @downloadURL https://iitc.app/build/release/plugins/missions.user.js +// @match https://intel.ingress.com/* +// @grant none +// ==/UserScript== diff --git a/test/manager.1.build-in.spec.js b/test/manager.1.build-in.spec.js index 32b5d7f..7a75295 100644 --- a/test/manager.1.build-in.spec.js +++ b/test/manager.1.build-in.spec.js @@ -29,6 +29,7 @@ describe('manage.js build-in plugins integration tests', function () { const first_plugin_uid = 'Available AP statistics+https://github.com/IITC-CE/ingress-intel-total-conversion'; const second_plugin_uid = 'Bing maps+https://github.com/IITC-CE/ingress-intel-total-conversion'; + const third_plugin_uid = 'Missions+https://github.com/IITC-CE/ingress-intel-total-conversion'; describe('run', function () { it('Should not return an error', async function () { @@ -43,7 +44,7 @@ describe('manage.js build-in plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_local']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_local'], 'release_plugins_local').to.have.all.keys(first_plugin_uid); expect(db_data['release_plugins_local'][first_plugin_uid]['status'], 'release_plugins_local: ' + first_plugin_uid).to.equal('on'); @@ -56,7 +57,7 @@ describe('manage.js build-in plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_local']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_local'], 'release_plugins_local').to.have.all.keys(first_plugin_uid, second_plugin_uid); expect(db_data['release_plugins_local'][first_plugin_uid]['status'], 'release_plugins_local: ' + first_plugin_uid).to.equal('on'); @@ -73,7 +74,7 @@ describe('manage.js build-in plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_local']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_local'], 'release_plugins_local').to.have.all.keys(first_plugin_uid, second_plugin_uid); expect(db_data['release_plugins_local'][first_plugin_uid]['status'], 'release_plugins_local: ' + first_plugin_uid).to.equal('off'); diff --git a/test/manager.2.external.spec.js b/test/manager.2.external.spec.js index 2851691..c4c07af 100644 --- a/test/manager.2.external.spec.js +++ b/test/manager.2.external.spec.js @@ -42,6 +42,7 @@ describe('manage.js external plugins integration tests', function () { const first_plugin_uid = 'Available AP statistics+https://github.com/IITC-CE/ingress-intel-total-conversion'; const second_plugin_uid = 'Bing maps+https://github.com/IITC-CE/ingress-intel-total-conversion'; + const third_plugin_uid = 'Missions+https://github.com/IITC-CE/ingress-intel-total-conversion'; const external_code = '// ==UserScript==\nreturn false;'; describe('run', function () { @@ -83,7 +84,12 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.deep.equal(installed); const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, external_1_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( + first_plugin_uid, + second_plugin_uid, + third_plugin_uid, + external_1_uid + ); expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_1_uid); expect(db_data['release_plugins_user'][external_1_uid]['status'], "release_plugins_user['status']: " + external_1_uid).to.equal('on'); @@ -123,6 +129,7 @@ describe('manage.js external plugins integration tests', function () { expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( first_plugin_uid, second_plugin_uid, + third_plugin_uid, external_1_uid, external_2_uid ); @@ -154,6 +161,7 @@ describe('manage.js external plugins integration tests', function () { expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( first_plugin_uid, second_plugin_uid, + third_plugin_uid, external_1_uid, external_2_uid ); @@ -183,6 +191,7 @@ describe('manage.js external plugins integration tests', function () { expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( first_plugin_uid, second_plugin_uid, + third_plugin_uid, external_1_uid, external_2_uid ); @@ -201,6 +210,7 @@ describe('manage.js external plugins integration tests', function () { expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( first_plugin_uid, second_plugin_uid, + third_plugin_uid, external_1_uid, external_2_uid ); @@ -216,7 +226,12 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, external_1_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( + first_plugin_uid, + second_plugin_uid, + third_plugin_uid, + external_1_uid + ); expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_1_uid); }); @@ -225,7 +240,7 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_user'], 'release_plugins_user').to.be.empty; }); }); @@ -272,7 +287,12 @@ describe('manage.js external plugins integration tests', function () { it('Check external plugin', async function () { const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, external_1_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys( + first_plugin_uid, + second_plugin_uid, + third_plugin_uid, + external_1_uid + ); expect(db_data['release_plugins_flat'][external_1_uid]['override']).to.be.undefined; expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_1_uid); }); @@ -282,7 +302,7 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_user'], 'release_plugins_user').to.be.empty; }); }); @@ -321,7 +341,7 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.deep.equal(installed); const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_1_uid); expect(db_data['release_plugins_user'][external_1_uid]['code'], "release_plugins_user['code']: " + external_1_uid).to.equal(external_code); @@ -346,7 +366,7 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_1_uid); expect(db_data['release_plugins_flat'][external_1_uid]['status'], "release_plugins_flat['status']: " + external_1_uid).to.equal('off'); @@ -359,7 +379,7 @@ describe('manage.js external plugins integration tests', function () { expect(run).to.be.undefined; const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); - expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); expect(db_data['release_plugins_user'], 'release_plugins_user').to.be.empty; expect(db_data['release_plugins_flat'][external_1_uid]['status'], "release_plugins_flat['status']: " + external_1_uid).to.equal('off'); @@ -369,4 +389,70 @@ describe('manage.js external plugins integration tests', function () { expect(db_data['release_plugins_flat'][external_1_uid]['override'], "release_plugins_flat['override']: " + external_1_uid).to.not.be.true; }); }); + + describe('Adding and removing an external plugin that overwrites a built-in plugin', function () { + const external_3_uid = 'Missions+https://github.com/IITC-CE/ingress-intel-total-conversion'; + const external_3_plugin = { + meta: { + namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion', + name: 'Missions', + }, + code: external_code, + }; + + it('Add external plugin and replace built-in plugin', async function () { + const installed = { + 'Missions+https://github.com/IITC-CE/ingress-intel-total-conversion': { + uid: external_3_uid, + id: 'missions', + author: 'jonatkins', + description: 'View missions. Marking progress on waypoints/missions basis. Showing mission paths on the map.', + filename: 'missions.user.js', + namespace: 'https://github.com/IITC-CE/ingress-intel-total-conversion', + name: 'Missions', + category: 'Info', + status: 'on', + override: true, + user: true, + version: '0.3.0', + code: external_code, + }, + }; + const run = await manager.addUserScripts([external_3_plugin]); + expect(run).to.deep.equal(installed); + + const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); + expect(db_data['release_plugins_user'], 'release_plugins_user').to.have.all.keys(external_3_uid); + + expect(db_data['release_plugins_user'][external_3_uid]['code'], "release_plugins_user['code']: " + external_3_uid).to.equal(external_code); + expect(db_data['release_plugins_flat'][external_3_uid]['code'], "release_plugins_flat['code']: " + external_3_uid).to.equal(external_code); + expect(db_data['release_plugins_flat'][external_3_uid]['override'], "release_plugins_flat['override']: " + external_3_uid).to.be.true; + }); + + it('Remove external plugin and replace it with built-in plugin', async function () { + const run = await manager.managePlugin(external_3_uid, 'delete'); + expect(run).to.be.undefined; + + const db_data = await storage.get(['release_plugins_flat', 'release_plugins_user']); + expect(db_data['release_plugins_flat'], 'release_plugins_flat').to.have.all.keys(first_plugin_uid, second_plugin_uid, third_plugin_uid); + expect(db_data['release_plugins_user'], 'release_plugins_user').to.be.empty; + + expect(db_data['release_plugins_flat'][external_3_uid]['status'], "release_plugins_flat['status']: " + external_3_uid).to.equal('off'); + expect(db_data['release_plugins_flat'][external_3_uid]['override'], "release_plugins_flat['override']: " + external_3_uid).to.be.false; + }); + + it('Enable and disable build-in plugin', async function () { + const run1 = await manager.managePlugin(external_3_uid, 'on'); + expect(run1).to.be.undefined; + + const run2 = await manager.managePlugin(external_3_uid, 'off'); + expect(run2).to.be.undefined; + + const db_data = await storage.get(['release_plugins_flat']); + expect(db_data['release_plugins_flat'][external_3_uid]['status'], "release_plugins_flat['status']: " + external_3_uid).to.equal('off'); + expect(db_data['release_plugins_flat'][external_3_uid]['code'], "release_plugins_flat['code']: " + external_3_uid).to.have.lengthOf(596); + expect(db_data['release_plugins_flat'][external_3_uid]['override'], "release_plugins_flat['override']: " + external_3_uid).to.be.false; + }); + }); }); From 09e47827ee6f9ae57e26ef7982759d5655c0f84c Mon Sep 17 00:00:00 2001 From: modos189 Date: Sun, 25 Dec 2022 23:05:49 +0300 Subject: [PATCH 2/3] 1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d195d2a..fec1b1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lib-iitc-manager", - "version": "1.4.0", + "version": "1.4.1", "description": "Library for managing IITC plugins", "main": "src/index.js", "type": "module", From 9e3e21ec70af3e0e43b9fb7936b42faa0f12ff5c Mon Sep 17 00:00:00 2001 From: modos189 Date: Sun, 25 Dec 2022 23:20:25 +0300 Subject: [PATCH 3/3] 1.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fec1b1a..46be63f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lib-iitc-manager", - "version": "1.4.1", + "version": "1.4.2", "description": "Library for managing IITC plugins", "main": "src/index.js", "type": "module",