diff --git a/src/core/helpers/asarLibs.js b/src/core/helpers/asarLibs.js index f992ca5e..345cbc4c 100644 --- a/src/core/helpers/asarLibs.js +++ b/src/core/helpers/asarLibs.js @@ -29,7 +29,7 @@ const packageInfo = require("../../../package.json"); */ function asarLibPathHack(lib) { return packageInfo.package - ? path.join(__dirname, "../../../app.asar.unpacked/node_modules/", lib) + ? path.join(__dirname, "../../../../app.asar.unpacked/node_modules/", lib) : lib; } diff --git a/src/core/plugins/core/plugin.js b/src/core/plugins/core/plugin.js index 51c5f652..5c16ef8a 100644 --- a/src/core/plugins/core/plugin.js +++ b/src/core/plugins/core/plugin.js @@ -121,7 +121,7 @@ class CorePlugin extends Plugin { this.cachePath, this.props.config.codename, group, - path.basename(file.url) + file.name || path.basename(file.url) ) })), (progress, speed) => { @@ -130,8 +130,9 @@ class CorePlugin extends Plugin { this.event.emit("user:write:under", "Downloading"); }, (current, total) => { - if (current > 1) + if (current > 0) this.log.info(`Downloaded file ${current} of ${total}`); + else this.log.info(`Downloading ${total} files`); this.event.emit( "user:write:status", `${current} of ${total} files downloaded and verified`, @@ -208,6 +209,11 @@ class CorePlugin extends Plugin { ); } + /** + * core:manual_download action + * @param {Object} param0 {group, file} + * @returns {Promise} + */ action__manual_download({ group, file }) { return Promise.resolve() .then(() => { diff --git a/src/core/plugins/core/plugin.spec.js b/src/core/plugins/core/plugin.spec.js index 9dc3631d..f3cda43a 100644 --- a/src/core/plugins/core/plugin.spec.js +++ b/src/core/plugins/core/plugin.spec.js @@ -132,18 +132,46 @@ describe("core plugin", () => { describe("action__download()", () => { it("should download", () => - core.action__download({ - group: "fimrware", - files: [ - { url: "a/c", checksum: { sum: "b", algorithm: "sha256" } }, - { url: "a/b", checksum: { sum: "a", algorithm: "sha256" } } - ] - })); // TODO add assertions for event messages + core + .action__download({ + group: "firmware", + files: [ + { url: "a/c", checksum: { sum: "b", algorithm: "sha256" } }, + { url: "a/b" }, + { url: "a/c", name: "d" } + ] + }) + .then(r => { + expect(r).toEqual(undefined); + expect(download).toHaveBeenCalledTimes(1); + expect(download).toHaveBeenCalledWith( + [ + { + checksum: { algorithm: "sha256", sum: "b" }, + path: expect.stringMatching(/a.yggdrasil.firmware.c/), + url: "a/c" + }, + { + path: expect.stringMatching(/a.yggdrasil.firmware.b/), + url: "a/b" + }, + { + name: "d", + path: expect.stringMatching(/a.yggdrasil.firmware.d/), + url: "a/c" + } + ], + expect.any(Function), + expect.any(Function), + expect.any(Function) + ); + expect(mainEvent.emit).toHaveBeenCalledTimes(20); + })); it("should show network error", done => { download.mockRejectedValueOnce("download error"); core .action__download({ - group: "fimrware", + group: "firmware", files: [ { url: "a/c", checksum: { sum: "b", algorithm: "sha256" } }, { url: "a/b", checksum: { sum: "a", algorithm: "sha256" } }