UNPKG

@crowdin/app-project-module

Version:

Module that generates for you all common endpoints for serving standalone Crowdin App

83 lines (82 loc) 4.34 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateIntegrationTest = exports.getUpdateIntegrationRequest = void 0; const globals_1 = require("@jest/globals"); const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client")); const types_1 = require("../../modules/integration/util/types"); const index_1 = require("./index"); const crowdin_storage_1 = require("./mocks/crowdin-storage"); const util_1 = require("../util"); const getUpdateIntegrationRequest = () => { const request = {}; index_1.mockFiles.forEach((file) => { request[file.id] = ['es']; }); return request; }; exports.getUpdateIntegrationRequest = getUpdateIntegrationRequest; const updateIntegrationTest = ({ 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 { updateIntegration, appSettings, integrationCredentials } = integrationTestConfig; const client = new crowdin_api_client_1.default({ token: 'fakeToken' }); const updateProgressMock = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () { return { isCanceled: false }; })); const request = (0, exports.getUpdateIntegrationRequest)(); const result = yield (0, util_1.assert)(() => { var _a; return (_a = appConfig.projectIntegration) === null || _a === void 0 ? void 0 : _a.updateIntegration({ projectId: index_1.mockProjectId, client, credentials: integrationCredentials, request, rootFolder: (0, crowdin_storage_1.getRootFolder)(appConfig), appSettings, job: { get: function getJob() { return __awaiter(this, void 0, void 0, function* () { return { id: 'jobId1', integrationId: 'string', crowdinId: 'string', type: types_1.JobType.UPDATE_TO_INTEGRATION, title: 'Sync files to ' + appConfig.name, progress: 0, status: types_1.JobStatus.CREATED, createdAt: 0, }; }); }, update: updateProgressMock, type: types_1.JobClientType.MANUAL, fetchTranslation: jest.fn(), translationUploaded: jest.fn(), markFilesAsUnsynced: jest.fn(), unmarkFilesAsUnsynced: jest.fn(), }, }); }, 'Fail to run method updateIntegration()'); if (!(updateIntegration === null || updateIntegration === void 0 ? void 0 : updateIntegration.updateProgressDisabled)) { yield (0, util_1.assert)(() => (0, globals_1.expect)(updateProgressMock.mock.calls.length).toBeGreaterThanOrEqual(Object.keys(request).length), 'The sync progress should be updated at least once for each file in request'); } if (updateIntegration === null || updateIntegration === void 0 ? void 0 : updateIntegration.extraChecks) { yield (0, util_1.assert)( // @ts-ignore () => updateIntegration.extraChecks({ request, result }), 'ExtraChecks for updateIntegration() fails'); } }); exports.updateIntegrationTest = updateIntegrationTest;