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-1931} Move zipfile mock-up and improve coverage #1205

Merged
merged 15 commits into from
Oct 14, 2022
11 changes: 11 additions & 0 deletions feature-utils/poly-import/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ import {
import DataAccount from "./entities/data-account";
import { Status, statusTypes } from "../utils/status";
import { Telemetry } from "../utils/performance-telemetry";
import {
MINIMUM_FILE_SIZE,
ZipFileEntryMock,
ZipFileMock,
} from "../utils/zipfile-mock";
import { jsonStringifyWithUtfEscape } from "../utils/json-encoding";

export {
MINIMUM_FILE_SIZE,
jsonStringifyWithUtfEscape,
Status,
Importer,
runImporter,
runImporters,
runOutdatedImporter,
runOutdatedImporters,
ZipFile,
ZipFileMock,
Telemetry,
ZipFileEntry,
ZipFileEntryMock,
FileImportError,
RefreshFilesError,
FileSelectionError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

import { jsonStringifyWithUtfEscape } from "../src/model/importers/utils/json-encoding";
import { jsonStringifyWithUtfEscape } from "../utils/json-encoding";

const jsonData1 = "🦊";
const jsonData2 = "🦊🤗😍";
Expand All @@ -22,6 +22,11 @@ describe("JSON encode", () => {
it("Various characters", () => {
expect(jsonStringifyWithUtfEscape(jsonData3)).toBe(decodedData3);
});

it("passes through non-string data", () => {
const foo42 = { foo: 42 };
expect(jsonStringifyWithUtfEscape(foo42)).toBe(JSON.stringify(foo42));
});
});

describe("Decodes", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function jsonStringifyWithUtfEscape(jsonData) {
}
return value;
});
const escapedString = jsonStringEscapeUtfCharacters(serializedString);
return escapedString;
return jsonStringEscapeUtfCharacters(serializedString);
}

export { jsonStringEscapeUtfCharacters, jsonStringifyWithUtfEscape };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jsonStringifyWithUtfEscape } from "../../src/model/importers/utils/json-encoding";
import { jsonStringifyWithUtfEscape } from "./json-encoding";

//The minimum size of a .ZIP file is 22 bytes
export const MINIMUM_FILE_SIZE = 22;
Expand Down
2 changes: 1 addition & 1 deletion features/facebookImport/test/datasets/messages-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { createMockedZip } from "../utils/data-creation";
export const DATASET_EXPECTED_VALUES = {
numberOfMessageThreads: 2,
Expand Down
2 changes: 1 addition & 1 deletion features/facebookImport/test/datasets/posts-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { createMockedZip } from "../utils/data-creation";

const POSTS_FILE_PATH = "posts/your_posts_X.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithAdInterests,
} from "../datasets/ad-interests-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runAdInterestsImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createEnglishDatasetWithMissingAdsCategory,
createIncompleteEnglishAdViewsData,
} from "../datasets/ad-views-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import {
runAdsImportForDataset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithComments,
} from "../datasets/comments-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runCommentsImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithConnectedAdvertisersAllTypes,
} from "../datasets/connected-advertisers-all-types-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runConnectedAdvertisersWithAllTypesImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithConnectedAdvertisers,
} from "../datasets/connected-advertisers-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runConnectedAdvertisersImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithInteractedWithAdvertisers,
} from "../datasets/interacted-with-advertisers-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runInteractedWithAdvertisersImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createLanguageSettingsData,
createLocaleData,
} from "../datasets/language-and-locale-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runLanguageAndLocaleImporter } from "../utils/data-importing";
import {
expectImportSuccess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
zipFileWithMessageThreads,
zipFileWithThreeFileErrors,
} from "../datasets/messages-data.js";
import { ZipFileMock } from "../mocks/zipfile-mock.js";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runMessagesImporter } from "../utils/data-importing.js";
import {
expectError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

import NameImporter from "../../src/model/importers/name-importer";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runNameImporter } from "../utils/data-importing";
import {
expectError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
zipFileWithOffFacebookEvents,
DATASET_EXPECTED_VALUES,
} from "../datasets/off-facebook-events-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runOffFacebookEventsImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PersonalDataImporter, {
PROFILE_INFORMATION_FILE_PATH,
} from "../../src/model/importers/personal-data-importer";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runPersonalDataImporter } from "../utils/data-importing";
import {
expectError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithPostReactions,
} from "../datasets/post-reactions-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runPostReactionsImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
zipFileWithTwoFileErrors,
zipFileWithTwoPostsFiles,
} from "../datasets/posts-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runPostsImporter } from "../utils/data-importing";
import {
expectError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithSearches,
} from "../datasets/searches-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../utils/data-creation";
import { runSearchesImporter } from "../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZipFileMock } from "../../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { zipWithWrongDatasetKey } from "../../utils/data-creation";
import { runSingleOutdatedImporter } from "../../utils/data-importing";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AboutPicturesDataAnalysis from "../../src/model/analyses/ministories/about-pictures-data-analysis";
import AboutPicturesMinistory from "../../src/views/ministories/aboutPictures";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import {
expectInactiveAnalysis,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import JSONFileNamesAnalysis from "../../src/model/analyses/report/json-file-names-analysis";
import commonStructure from "../../src/static/commonStructure";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import { expectAnalysisSuccessStatus } from "../utils/analysis-assertions";

const commonJsonFiles = commonStructure
.filter((path) => path.match(/\.json$/))
.map((jsonPath) => {
return jsonPath.substring(1);
});

async function analyzeZipWithFiles(files) {
const zipFile = new ZipFileMock();
if (files.length > 0) {
files.forEach((jsonPath) => {
zipFile.addJsonEntry(jsonPath, { foo: "bar" });
});
}
const { analysisResult } = await runAnalysisForExport(
JSONFileNamesAnalysis,
zipFile
);
return analysisResult;
}

describe("JSON files analysis for empty zip", () => {
let status;
beforeAll(async () => {
({ status } = await analyzeZipWithFiles([]));
});
it("has success status", async () => {
expectAnalysisSuccessStatus(status);
});
});

describe("JSON files analysis for non-empty zip", () => {
let status;
let analysis;

beforeAll(async () => {
({ status, analysis } = await analyzeZipWithFiles(commonJsonFiles));
});
JJ marked this conversation as resolved.
Show resolved Hide resolved

it("reports successful status", () => {
expect(status.isSuccess).toBe(true);
});

it("has the right name", () => {
expect(analysis.reportData).toStrictEqual(commonJsonFiles);
});

it("has the right title", () => {
expect(analysis.title).toBe("JSON file names");
});
});

describe("JSON files analysis with anonymized path", () => {
let analysis;
beforeAll(async () => {
commonJsonFiles.push(
"messages/archived_threads/facebookuser_gktxomrifg/message_1.json"
);
({ analysis } = await analyzeZipWithFiles(commonJsonFiles));
});

it("has anonymized file", () => {
expect(analysis.reportData).toContain(
"messages/archived_threads/uniqueid_hash/message_1.json"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DATASET_EXPECTED_VALUES,
zipFileWithMessageThreads,
} from "../datasets/messages-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import {
expectActiveAnalysis,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MissingCommonJSONFilesAnalysis from "../../src/model/analyses/report/missing-common-json-files";
import commonStructure from "../../src/static/commonStructure";
import MissingCommonJSONFilesReport from "../../src/views/ministories/missingCommonJsonFiles";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import {
expectActiveAnalysis,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PostReactionsTypesAnalysis from "../../src/model/analyses/ministories/post-reactions-types-analysis";
import PostReactionTypesMinistory from "../../src/views/ministories/postReactionsTypes";
import { zipFileWithPostReactions } from "../datasets/post-reactions-data";
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import {
expectActiveAnalysis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ReportMetadataReport from "../../src/views/ministories/reportMetadata";
import { createInteractedWithAdvertisersDataset } from "../datasets/interacted-with-advertisers-data";
import { createLanguageSettingsData } from "../datasets/language-and-locale-data";
import { createOffFacebookEventsSimpleData } from "../datasets/off-facebook-events-data";
import { MINIMUM_FILE_SIZE } from "../mocks/zipfile-mock";
import { MINIMUM_FILE_SIZE } from "@polypoly-eu/poly-import";
import { runAnalysisForExport } from "../utils/analyses-execution";
import {
expectActiveAnalysis,
Expand Down
2 changes: 1 addition & 1 deletion features/facebookImport/test/utils/data-creation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZipFileMock } from "../mocks/zipfile-mock";
import { ZipFileMock } from "@polypoly-eu/poly-import";

export function createMockedZip(datasets) {
let zipFile = new ZipFileMock();
Expand Down
2 changes: 1 addition & 1 deletion features/facebookImport/test/utils/data-importing.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import RecentlyViewedAdsImporter, {
RECENTLY_VIEWED_FILE_PATH,
} from "../../src/model/importers/recently-viewed-ads-importer.js";
import OffFacebookEventsImporter from "../../src/model/importers/off-facebook-events-importer.js";
import { ZipFileMock } from "../mocks/zipfile-mock.js";
import { ZipFileMock } from "@polypoly-eu/poly-import";
import { MockPod } from "@polypoly-eu/api/dist/mock-pod";
import LanguageAndLocaleImporter from "../../src/model/importers/language-and-locale-importer.js";
import FriendsImporter from "../../src/model/importers/friends-importer.js";
Expand Down