Skip to content

Commit 643f174

Browse files
authored
[♻] Add test for bubbles, refactor to avoid content error (#1220)
# ✍️ Description This code was the only one using the construction `zipFile.getContent`, which apparently disappeared a some point in time. It's been refactored to work as intended, getting the content of a single `ZipEntry`. Adds a tests which fails if the original content was used. ### 🏗️ Fixes PROD4POD-1940 This was found while doing #1219, so it's a blocker for that one. ## ℹ️ Other information Deep tests have not really been performed; they're mainly sanity tests. Rendering tests are not checked either. Better mocks would probably be needed for better tests. (Unrelated) coupling with `zipFile` has been eliminated from the function, since it's no longer needed. The function was returning a data structure which included it, not doing that does not seem to affect the outcome.
1 parent 8b938ed commit 643f174

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

features/facebookImport/src/model/analyses/ministories/json-files-bubbles.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis {
88
return "Files Bubbles";
99
}
1010

11-
async _contentLinesForEntry(zipFile, jsonEntry) {
11+
async _contentLinesForEntry(jsonEntry) {
1212
const fileContent = new TextDecoder("utf-8").decode(
13-
await zipFile.getContent(jsonEntry)
13+
await jsonEntry.getContent()
1414
);
1515
const linesCount = fileContent
1616
.split("\n")
@@ -19,7 +19,7 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis {
1919
linesCount + (line.trim().length >= 2 ? 1 : 0),
2020
0
2121
);
22-
return { zipFile, zipEntry: jsonEntry, count: linesCount };
22+
return { zipEntry: jsonEntry, count: linesCount };
2323
}
2424

2525
async analyze({ zipFile, dataAccount }) {
@@ -31,7 +31,7 @@ export default class JsonFilesBubblesAnalysis extends RootAnalysis {
3131
const relevantEntries = await jsonDataEntities(zipFile);
3232
this._filesMessagesCount = await Promise.all(
3333
relevantEntries.map((jsonEntry) =>
34-
this._contentLinesForEntry(zipFile, jsonEntry)
34+
this._contentLinesForEntry(jsonEntry)
3535
)
3636
);
3737
this.active = true;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import JSONFilesBubblesAnalysis from "../../src/model/analyses/ministories/json-files-bubbles";
2+
import commonStructure from "../../src/static/commonStructure";
3+
import { ZipFileMock } from "@polypoly-eu/poly-import";
4+
import { runAnalysisForExport } from "../utils/analyses-execution";
5+
6+
const commonJsonFiles = commonStructure
7+
.filter((path) => path.match(/\.json$/))
8+
.map((jsonPath) => {
9+
return jsonPath.substring(1);
10+
});
11+
12+
async function analyzeZipWithFiles(files) {
13+
const zipFile = new ZipFileMock();
14+
if (files.length > 0) {
15+
files.forEach((jsonPath) => {
16+
zipFile.addJsonEntry(jsonPath, { foo: "bar" });
17+
});
18+
}
19+
const { analysisResult } = await runAnalysisForExport(
20+
JSONFilesBubblesAnalysis,
21+
zipFile
22+
);
23+
return analysisResult;
24+
}
25+
26+
describe("JSON files analysis for non-empty zip", () => {
27+
let status;
28+
let analysis;
29+
30+
beforeAll(async () => {
31+
({ status, analysis } = await analyzeZipWithFiles(commonJsonFiles));
32+
});
33+
34+
it("reports successful status", () => {
35+
expect(status.isSuccess).toBe(true);
36+
});
37+
38+
it("has the right type and title", () => {
39+
expect(analysis).toBeInstanceOf(JSONFilesBubblesAnalysis);
40+
expect(analysis.title).toBe("Files Bubbles");
41+
});
42+
43+
it("has the right message count", () => {
44+
expect(analysis._filesMessagesCount).toHaveLength(10);
45+
});
46+
});

0 commit comments

Comments
 (0)