Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[✨] {PROD4POD-635} Mock archive-related methods #1222

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion feature-utils/poly-import/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions feature-utils/poly-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 1 addition & 3 deletions feature-utils/poly-import/src/errors/polyIn-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
2 changes: 1 addition & 1 deletion feature-utils/poly-import/src/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
Expand Down
11 changes: 11 additions & 0 deletions feature-utils/poly-import/test/importer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Importer } from "../src";

describe("Importer can't be instantiated ", () => {
it("throws", async () => {
try {
await new Importer().import({ zipFile: null, dataAccount: null });
} catch (e) {
expect(e).toBeInstanceOf(TypeError);
}
});
});
23 changes: 23 additions & 0 deletions feature-utils/poly-import/test/polyIn-errors.test.js
Original file line number Diff line number Diff line change
@@ -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("throws correctly", () => {
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);
}
});
});
});
28 changes: 28 additions & 0 deletions feature-utils/poly-import/test/storage.test.js
Original file line number Diff line number Diff line change
@@ -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("can be instantiated", () => {
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;
});
});
14 changes: 14 additions & 0 deletions feature-utils/poly-import/test/telemetry.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe("Report metadata analysis", () => {
),
],
]);
console.log(zipFile);
const { facebookAccount, analysisResult } = await runAnalysisForExport(
ReportMetadataAnalysis,
zipFile
Expand Down
Loading