@crowdin/app-project-module
Version:
Module that generates for you all common endpoints for serving standalone Crowdin App
70 lines (69 loc) • 4.17 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIntegrationFilesTest = void 0;
const globals_1 = require("@jest/globals");
const util_1 = require("../util");
const getIntegrationFilesTest = ({ appConfig, integrationTestConfig, }) => __awaiter(void 0, void 0, void 0, function* () {
if (!appConfig.projectIntegration) {
throw new Error('The app configuration is missing the projectIntegration module.');
}
const integration = appConfig.projectIntegration;
const { getIntegrationFiles } = integrationTestConfig;
const expectedTree = getIntegrationFiles.expected;
const allFiles = [];
const params = {
apiCredentials: {},
config: {},
parentId: '',
search: '',
page: '0',
};
const result = yield (0, util_1.assert)(() => integration.getIntegrationFiles(params.apiCredentials, params.config, params.parentId, params.search, params.page), `Fail to run method getIntegrationFiles(), with params ${JSON.stringify(params)}`);
if (integration.integrationOneLevelFetching) {
const rootLevel = result;
const rootLevelExpected = expectedTree.filter((node) => !node.parentId || node.parentId === '0');
yield (0, util_1.assert)(() => (0, globals_1.expect)(rootLevel).toHaveLength(rootLevelExpected.length), `Received root files length: ${rootLevel.length}, but expected root tree length: ${rootLevelExpected.length}`);
yield (0, util_1.assert)(() => (0, globals_1.expect)(rootLevel).toEqual(globals_1.expect.arrayContaining(rootLevelExpected.map((node) => globals_1.expect.objectContaining(node)))), 'Received root files properties do not match to the expected properties');
const isFolder = (node) => {
return !('type' in node) || !node.type;
};
const getAll = (node) => __awaiter(void 0, void 0, void 0, function* () {
params.parentId = node.id;
const data = (yield (0, util_1.assert)(() => integration.getIntegrationFiles(params.apiCredentials, params.config, params.parentId, params.search, params.page), `Fail to run method getIntegrationFiles(), with params ${JSON.stringify(params)}`));
for (const node of data) {
if (isFolder(node)) {
yield getAll(node);
}
allFiles.push(node);
}
});
for (const node of rootLevel) {
if (isFolder(node)) {
yield getAll(node);
}
allFiles.push(node);
}
}
else if (integration.integrationPagination) {
// Todo. Should be implemented
}
else {
allFiles.push(...result);
}
yield (0, util_1.assert)(() => (0, globals_1.expect)(allFiles).toHaveLength(expectedTree.length), `Received files length: ${allFiles.length}, but expected tree length ${expectedTree.length}`);
yield (0, util_1.assert)(() => (0, globals_1.expect)(allFiles).toEqual(globals_1.expect.arrayContaining(expectedTree.map((node) => globals_1.expect.objectContaining(node)))), 'Received files properties do not match to the expected properties');
if (getIntegrationFiles === null || getIntegrationFiles === void 0 ? void 0 : getIntegrationFiles.extraChecks) {
// @ts-ignore
yield (0, util_1.assert)(() => getIntegrationFiles.extraChecks(), 'ExtraChecks for getIntegrationFiles() fails');
}
});
exports.getIntegrationFilesTest = getIntegrationFilesTest;