diff --git a/feature-utils/poly-import/package-lock.json b/feature-utils/poly-import/package-lock.json index fff9a21c01..33a5d1d1f3 100644 --- a/feature-utils/poly-import/package-lock.json +++ b/feature-utils/poly-import/package-lock.json @@ -4,7 +4,63 @@ "requires": true, "packages": { "": { - "name": "@polypoly-eu/poly-import" + "name": "@polypoly-eu/poly-import", + "devDependencies": { + "@polypoly-eu/api": "file:../../platform/feature-api/api" + } + }, + "../../platform/feature-api/api": { + "version": "0.3.1", + "dev": true, + "dependencies": { + "chai": "^4.2.0", + "chai-as-promised": "^7.1.1", + "fast-check": "^2.2.1", + "uuid": "^8.3.2" + }, + "devDependencies": { + "@graphy/core.data.factory": "^4.3.4", + "@graphy/memory.dataset.fast": "^4.3.3", + "@polypoly-eu/dummy-server": "file:../../../dev-utils/dummy-server", + "@rdfjs/data-model": "^1.1.3", + "@rdfjs/dataset": "^1.0.1", + "@types/chai": "^4.2.14", + "@types/chai-as-promised": "^7.1.5", + "@types/n3": "^1.10.3", + "@types/rdfjs__dataset": "^1.0.4", + "@types/uuid": "^8.3.4", + "memfs": "^3.4.1", + "n3": "^1.8.0", + "rdf-data-factory": "^1.0.4" + } + }, + "node_modules/@polypoly-eu/api": { + "resolved": "../../platform/feature-api/api", + "link": true + } + }, + "dependencies": { + "@polypoly-eu/api": { + "version": "file:../../platform/feature-api/api", + "requires": { + "@graphy/core.data.factory": "^4.3.4", + "@graphy/memory.dataset.fast": "^4.3.3", + "@polypoly-eu/dummy-server": "file:../../../dev-utils/dummy-server", + "@rdfjs/data-model": "^1.1.3", + "@rdfjs/dataset": "^1.0.1", + "@types/chai": "^4.2.14", + "@types/chai-as-promised": "^7.1.5", + "@types/n3": "^1.10.3", + "@types/rdfjs__dataset": "^1.0.4", + "@types/uuid": "^8.3.4", + "chai": "^4.2.0", + "chai-as-promised": "^7.1.1", + "fast-check": "^2.2.1", + "memfs": "^3.4.1", + "n3": "^1.8.0", + "rdf-data-factory": "^1.0.4", + "uuid": "^8.3.2" + } } } } diff --git a/feature-utils/poly-import/package.json b/feature-utils/poly-import/package.json index 94b9d8ba82..025563dded 100644 --- a/feature-utils/poly-import/package.json +++ b/feature-utils/poly-import/package.json @@ -6,5 +6,15 @@ "scripts": { "build": "rollup -c rollup.config.js", "test": "jest --coverage" + }, + "jest": { + "verbose": true, + "transform": { + "\\.[jt]sx?$": "babel-jest" + }, + "testEnvironment": "jsdom" + }, + "devDependencies": { + "@polypoly-eu/api": "file:../../platform/feature-api/api" } } diff --git a/feature-utils/poly-import/src/errors/polyIn-errors.js b/feature-utils/poly-import/src/errors/polyIn-errors.js index e752cc8fd8..bba5f781b3 100644 --- a/feature-utils/poly-import/src/errors/polyIn-errors.js +++ b/feature-utils/poly-import/src/errors/polyIn-errors.js @@ -2,26 +2,24 @@ class PolyImportError extends Error { constructor(type, cause) { super(`Failed to ${type} file`); this.cause = cause; + this.name = this.constructor.name; } } export class FileImportError extends PolyImportError { constructor(cause) { super("import", cause); - this.name = "FileImportError"; } } export class FileSelectionError extends PolyImportError { constructor(cause) { super("select", cause); - this.name = "FileSelectionError"; } } export class RefreshFilesError extends PolyImportError { constructor(cause) { super("refresh", cause); - this.name = "RefreshFilesError"; } } diff --git a/feature-utils/poly-import/src/importer.js b/feature-utils/poly-import/src/importer.js index 26852f7089..9a2be05c1f 100644 --- a/feature-utils/poly-import/src/importer.js +++ b/feature-utils/poly-import/src/importer.js @@ -3,7 +3,7 @@ import { Telemetry } from "../utils/performance-telemetry"; export class Importer { async import({ zipFile, dataAccount }) { - throw new Error( + throw new TypeError( `Calling abstract base class with ${zipFile}, ${dataAccount}` ); } diff --git a/feature-utils/poly-import/test/importer.test.js b/feature-utils/poly-import/test/importer.test.js new file mode 100644 index 0000000000..3c04748f86 --- /dev/null +++ b/feature-utils/poly-import/test/importer.test.js @@ -0,0 +1,11 @@ +import { Importer } from "../src"; + +describe("Importer can't be instantiated ", () => { + it("throws a TypeError", async () => { + try { + await new Importer().import({ zipFile: null, dataAccount: null }); + } catch (e) { + expect(e).toBeInstanceOf(TypeError); + } + }); +}); diff --git a/feature-utils/poly-import/test/polyIn-errors.test.js b/feature-utils/poly-import/test/polyIn-errors.test.js new file mode 100644 index 0000000000..bfd57cca5e --- /dev/null +++ b/feature-utils/poly-import/test/polyIn-errors.test.js @@ -0,0 +1,23 @@ +import { FileImportError, FileSelectionError, RefreshFilesError } from "../src"; + +const classData = [ + [FileImportError, "import"], + [FileSelectionError, "select"], + [RefreshFilesError, "refresh"], +]; + +describe("Errors have the right API ", () => { + it("throw correctly their type errors", () => { + classData.forEach(([testClass, testMsg]) => { + const testCause = "test"; + try { + throw new testClass(testCause); + } catch (error) { + expect(error).toBeInstanceOf(testClass); + expect(error.message).toMatch(new RegExp(testMsg)); + expect(error.name).toBe(new testClass().constructor.name); + expect(error.cause).toBe(testCause); + } + }); + }); +}); diff --git a/feature-utils/poly-import/test/storage.test.js b/feature-utils/poly-import/test/storage.test.js new file mode 100644 index 0000000000..0d796dfff5 --- /dev/null +++ b/feature-utils/poly-import/test/storage.test.js @@ -0,0 +1,28 @@ +import { polyProtocolRegex } from "@polypoly-eu/api"; +import { MockPod } from "@polypoly-eu/api/dist/mock-pod"; +import { FeatureFileStorage } from "../src"; + +describe("File storage ", () => { + let fileStorage; + beforeAll(() => { + const pod = new MockPod(); + fileStorage = new FeatureFileStorage(pod); + }); + it("when instantiated there are no files stored", () => { + expect(fileStorage.files).toBeNull; + }); +}); + +describe("File storage", () => { + let fileStorage; + let fileUri; + beforeAll(async () => { + const pod = new MockPod(); + fileUri = await pod.polyOut.importArchive("noRealFile.zip"); + fileStorage = new FeatureFileStorage(pod); + }); + it("ignores non-existent archives", () => { + expect(fileUri).toMatch(polyProtocolRegex); + expect(fileStorage.files).toBeNull; + }); +}); diff --git a/feature-utils/poly-import/test/telemetry.test.js b/feature-utils/poly-import/test/telemetry.test.js new file mode 100644 index 0000000000..129c3167f1 --- /dev/null +++ b/feature-utils/poly-import/test/telemetry.test.js @@ -0,0 +1,14 @@ +import { Telemetry } from "../src"; + +describe("Telemetry measures performance ", () => { + let telemetry; + beforeAll(() => { + telemetry = new Telemetry(); + }); + + it("Returns increasing elapsed time", () => { + const oldTime = telemetry.elapsedTime(); + expect(oldTime).toBeGreaterThan(0); + expect(telemetry.elapsedTime()).toBeGreaterThan(oldTime); + }); +}); diff --git a/features/facebookImport/test/ministory/report-metadata.test.js b/features/facebookImport/test/ministory/report-metadata.test.js index f82f9489f4..3606229eef 100644 --- a/features/facebookImport/test/ministory/report-metadata.test.js +++ b/features/facebookImport/test/ministory/report-metadata.test.js @@ -43,6 +43,7 @@ describe("Report metadata analysis", () => { ), ], ]); + console.log(zipFile); const { facebookAccount, analysisResult } = await runAnalysisForExport( ReportMetadataAnalysis, zipFile diff --git a/platform/feature-api/api/src/pod-api/uri.ts b/platform/feature-api/api/src/pod-api/uri.ts index 21da8c1d5e..51b26b066f 100644 --- a/platform/feature-api/api/src/pod-api/uri.ts +++ b/platform/feature-api/api/src/pod-api/uri.ts @@ -9,8 +9,8 @@ export function createUUID(): string { return uuidv4(); } -const polyProtocol = "polypod://"; -const polyProtocolRegex = new RegExp(`^${polyProtocol}`); +export const polyProtocol = "polypod://"; +export const polyProtocolRegex = new RegExp(`^${polyProtocol}`); /** *