@crowdin/app-project-module 0.45.1 → 0.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/app-test/crowdin-responses/mock-get-project.json +202 -0
- package/out/app-test/crowdin-responses/mock-list-supported-languages.json +7368 -0
- package/out/app-test/index.d.ts +6 -0
- package/out/app-test/index.js +13 -0
- package/out/app-test/integration/get-integration-files.d.ts +6 -0
- package/out/app-test/integration/get-integration-files.js +70 -0
- package/out/app-test/integration/index.d.ts +15 -0
- package/out/app-test/integration/index.js +73 -0
- package/out/app-test/integration/mocks/crowdin-storage.d.ts +35 -0
- package/out/app-test/integration/mocks/crowdin-storage.js +47 -0
- package/out/app-test/integration/mocks/mock-axios.d.ts +1 -0
- package/out/app-test/integration/mocks/mock-axios.js +18 -0
- package/out/app-test/integration/mocks/mock-crowdin-api-client.d.ts +1 -0
- package/out/app-test/integration/mocks/mock-crowdin-api-client.js +132 -0
- package/out/app-test/integration/types.d.ts +41 -0
- package/out/app-test/integration/types.js +2 -0
- package/out/app-test/integration/update-crowdin.d.ts +6 -0
- package/out/app-test/integration/update-crowdin.js +137 -0
- package/out/app-test/integration/update-integration.d.ts +8 -0
- package/out/app-test/integration/update-integration.js +78 -0
- package/out/app-test/types.d.ts +4 -0
- package/out/app-test/types.js +2 -0
- package/out/app-test/util/index.d.ts +1 -0
- package/out/app-test/util/index.js +24 -0
- package/out/index.js +1 -1
- package/out/modules/custom-spell-check/handlers/get-languages-list.js +3 -1
- package/out/modules/custom-spell-check/types.d.ts +2 -2
- package/out/modules/integration/util/job.js +1 -0
- package/out/views/main.handlebars +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClientConfig, Config } from '../types';
|
|
2
|
+
import { TestSuiteConfig } from './types';
|
|
3
|
+
export declare const runAllTests: ({ getAppConfig, testSuiteConfig, }: {
|
|
4
|
+
getAppConfig: () => Promise<Config | ClientConfig>;
|
|
5
|
+
testSuiteConfig: TestSuiteConfig;
|
|
6
|
+
}) => void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAllTests = void 0;
|
|
4
|
+
const integration_1 = require("./integration");
|
|
5
|
+
const runAllTests = ({ getAppConfig, testSuiteConfig, }) => {
|
|
6
|
+
if (!testSuiteConfig) {
|
|
7
|
+
throw new Error('Please provide a valid tests configuration');
|
|
8
|
+
}
|
|
9
|
+
if (testSuiteConfig.projectIntegration) {
|
|
10
|
+
(0, integration_1.runProjectIntegrationTests)({ getAppConfig, integrationTestConfig: testSuiteConfig.projectIntegration });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.runAllTests = runAllTests;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClientConfig, Config } from '../../types';
|
|
2
|
+
import { IntegrationTestConfig } from './types';
|
|
3
|
+
export declare const getIntegrationFilesTest: ({ appConfig, integrationTestConfig, }: {
|
|
4
|
+
appConfig: Config | ClientConfig;
|
|
5
|
+
integrationTestConfig: IntegrationTestConfig;
|
|
6
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getIntegrationFilesTest = void 0;
|
|
13
|
+
const globals_1 = require("@jest/globals");
|
|
14
|
+
const util_1 = require("../util");
|
|
15
|
+
const getIntegrationFilesTest = ({ appConfig, integrationTestConfig, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
if (!appConfig.projectIntegration) {
|
|
17
|
+
throw new Error('The app configuration is missing the projectIntegration module.');
|
|
18
|
+
}
|
|
19
|
+
const integration = appConfig.projectIntegration;
|
|
20
|
+
const { getIntegrationFiles } = integrationTestConfig;
|
|
21
|
+
const expectedTree = getIntegrationFiles.expected;
|
|
22
|
+
const allFiles = [];
|
|
23
|
+
const params = {
|
|
24
|
+
apiCredentials: {},
|
|
25
|
+
config: {},
|
|
26
|
+
parentId: '',
|
|
27
|
+
search: '',
|
|
28
|
+
page: '0',
|
|
29
|
+
};
|
|
30
|
+
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)}`);
|
|
31
|
+
if (integration.integrationOneLevelFetching) {
|
|
32
|
+
const rootLevel = result;
|
|
33
|
+
const rootLevelExpected = expectedTree.filter((node) => !node.parentId || node.parentId === '0');
|
|
34
|
+
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}`);
|
|
35
|
+
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');
|
|
36
|
+
const isFolder = (node) => {
|
|
37
|
+
return !('type' in node) || !node.type;
|
|
38
|
+
};
|
|
39
|
+
const getAll = (node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
params.parentId = node.id;
|
|
41
|
+
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)}`));
|
|
42
|
+
for (const node of data) {
|
|
43
|
+
if (isFolder(node)) {
|
|
44
|
+
yield getAll(node);
|
|
45
|
+
}
|
|
46
|
+
allFiles.push(node);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
for (const node of rootLevel) {
|
|
50
|
+
if (isFolder(node)) {
|
|
51
|
+
yield getAll(node);
|
|
52
|
+
}
|
|
53
|
+
allFiles.push(node);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (integration.integrationPagination) {
|
|
57
|
+
// Todo. Should be implemented
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
allFiles.push(...result);
|
|
61
|
+
}
|
|
62
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(allFiles).toHaveLength(expectedTree.length), `Received files length: ${allFiles.length}, but expected tree length ${expectedTree.length}`);
|
|
63
|
+
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');
|
|
64
|
+
if (getIntegrationFiles === null || getIntegrationFiles === void 0 ? void 0 : getIntegrationFiles.extraChecks) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
yield (0, util_1.assert)(() => getIntegrationFiles.extraChecks(), 'ExtraChecks for getIntegrationFiles() fails');
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
exports.getIntegrationFilesTest = getIntegrationFilesTest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClientConfig, Config } from '../../types';
|
|
2
|
+
import { IntegrationTestConfig } from './types';
|
|
3
|
+
export declare const mockProjectId = 1;
|
|
4
|
+
export declare const mockStoragesById: {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
name: string;
|
|
7
|
+
data: unknown;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const mockFiles: any[];
|
|
11
|
+
export declare const mockDirectories: any[];
|
|
12
|
+
export declare const runProjectIntegrationTests: ({ getAppConfig, integrationTestConfig, }: {
|
|
13
|
+
getAppConfig: () => Promise<Config | ClientConfig>;
|
|
14
|
+
integrationTestConfig: IntegrationTestConfig;
|
|
15
|
+
}) => void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runProjectIntegrationTests = exports.mockDirectories = exports.mockFiles = exports.mockStoragesById = exports.mockProjectId = void 0;
|
|
13
|
+
const globals_1 = require("@jest/globals");
|
|
14
|
+
const mock_axios_1 = require("./mocks/mock-axios");
|
|
15
|
+
const mock_crowdin_api_client_1 = require("./mocks/mock-crowdin-api-client");
|
|
16
|
+
const get_integration_files_1 = require("./get-integration-files");
|
|
17
|
+
const update_crowdin_1 = require("./update-crowdin");
|
|
18
|
+
const update_integration_1 = require("./update-integration");
|
|
19
|
+
// CommonData
|
|
20
|
+
exports.mockProjectId = 1;
|
|
21
|
+
exports.mockStoragesById = {};
|
|
22
|
+
exports.mockFiles = [];
|
|
23
|
+
exports.mockDirectories = [];
|
|
24
|
+
jest.mock('axios', () => mock_axios_1.mockAxios);
|
|
25
|
+
jest.mock('@crowdin/crowdin-api-client', () => jest.fn().mockImplementation(() => mock_crowdin_api_client_1.mockCrowdinApiClient));
|
|
26
|
+
const runProjectIntegrationTests = ({ getAppConfig, integrationTestConfig, }) => {
|
|
27
|
+
(0, globals_1.describe)('Run integration module tests', () => {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
if (!((_a = integrationTestConfig.getIntegrationFiles) === null || _a === void 0 ? void 0 : _a.expected.length)) {
|
|
30
|
+
throw new Error('Please provide a valid expected files');
|
|
31
|
+
}
|
|
32
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
if (integrationTestConfig === null || integrationTestConfig === void 0 ? void 0 : integrationTestConfig.beforeAll) {
|
|
34
|
+
yield integrationTestConfig.beforeAll();
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
(0, globals_1.test)('getIntegrationFiles()', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
var _d;
|
|
39
|
+
if ((_d = integrationTestConfig.getIntegrationFiles) === null || _d === void 0 ? void 0 : _d.setup) {
|
|
40
|
+
yield integrationTestConfig.getIntegrationFiles.setup();
|
|
41
|
+
}
|
|
42
|
+
const appConfig = yield getAppConfig();
|
|
43
|
+
yield (0, get_integration_files_1.getIntegrationFilesTest)({ appConfig, integrationTestConfig });
|
|
44
|
+
}));
|
|
45
|
+
if (!((_b = integrationTestConfig.updateCrowdin) === null || _b === void 0 ? void 0 : _b.disabled)) {
|
|
46
|
+
(0, globals_1.test)('updateCrowdin()', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _e;
|
|
48
|
+
if ((_e = integrationTestConfig.updateCrowdin) === null || _e === void 0 ? void 0 : _e.setup) {
|
|
49
|
+
yield integrationTestConfig.updateCrowdin.setup();
|
|
50
|
+
}
|
|
51
|
+
const appConfig = yield getAppConfig();
|
|
52
|
+
yield (0, update_crowdin_1.updateCrowdinTest)({
|
|
53
|
+
appConfig,
|
|
54
|
+
integrationTestConfig,
|
|
55
|
+
});
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
if (!((_c = integrationTestConfig.updateIntegration) === null || _c === void 0 ? void 0 : _c.disabled)) {
|
|
59
|
+
(0, globals_1.test)('updateIntegration()', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
var _f;
|
|
61
|
+
if ((_f = integrationTestConfig.updateIntegration) === null || _f === void 0 ? void 0 : _f.setup) {
|
|
62
|
+
yield integrationTestConfig.updateIntegration.setup();
|
|
63
|
+
}
|
|
64
|
+
const appConfig = yield getAppConfig();
|
|
65
|
+
yield (0, update_integration_1.updateIntegrationTest)({
|
|
66
|
+
appConfig,
|
|
67
|
+
integrationTestConfig,
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.runProjectIntegrationTests = runProjectIntegrationTests;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SourceFilesModel } from '@crowdin/crowdin-api-client';
|
|
2
|
+
import { ClientConfig, Config } from '../../../types';
|
|
3
|
+
export declare const crowdinFolders: {
|
|
4
|
+
create: (params: SourceFilesModel.CreateDirectoryRequest) => {
|
|
5
|
+
data: {
|
|
6
|
+
id: number;
|
|
7
|
+
path: string;
|
|
8
|
+
branchId?: number | undefined;
|
|
9
|
+
directoryId?: number | undefined;
|
|
10
|
+
name: string;
|
|
11
|
+
title?: string | undefined;
|
|
12
|
+
exportPattern?: string | undefined;
|
|
13
|
+
priority?: SourceFilesModel.Priority | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const crowdinFiles: {
|
|
18
|
+
create: (params: SourceFilesModel.CreateFileRequest) => {
|
|
19
|
+
data: {
|
|
20
|
+
id: number;
|
|
21
|
+
path: string;
|
|
22
|
+
storageId: number;
|
|
23
|
+
name: string;
|
|
24
|
+
branchId?: number | undefined;
|
|
25
|
+
directoryId?: number | undefined;
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
type?: SourceFilesModel.FileType | undefined;
|
|
28
|
+
importOptions?: SourceFilesModel.SpreadsheetImportOptions | SourceFilesModel.XmlImportOptions | SourceFilesModel.OtherImportOptions | SourceFilesModel.DocxFileImportOptions | undefined;
|
|
29
|
+
exportOptions?: SourceFilesModel.GeneralExportOptions | SourceFilesModel.PropertyExportOptions | undefined;
|
|
30
|
+
attachLabelIds?: number[] | undefined;
|
|
31
|
+
excludedTargetLanguages?: string[] | undefined;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare const getRootFolder: (appConfig: Config | ClientConfig) => SourceFilesModel.Directory | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRootFolder = exports.crowdinFiles = exports.crowdinFolders = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const getNewFileOrFolderId = () => index_1.mockFiles.length + index_1.mockDirectories.length + 1;
|
|
6
|
+
const getFullPath = (parentId) => {
|
|
7
|
+
const folder = index_1.mockDirectories.find(({ id }) => id === parentId);
|
|
8
|
+
return (folder === null || folder === void 0 ? void 0 : folder.path) ? folder.path : '';
|
|
9
|
+
};
|
|
10
|
+
exports.crowdinFolders = {
|
|
11
|
+
create: (params) => {
|
|
12
|
+
const parentPath = params.directoryId ? getFullPath(params.directoryId) : '';
|
|
13
|
+
const data = Object.assign(Object.assign({}, params), { id: getNewFileOrFolderId(), path: `${parentPath}/${params.name}` });
|
|
14
|
+
index_1.mockDirectories.push(data);
|
|
15
|
+
return {
|
|
16
|
+
data,
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
exports.crowdinFiles = {
|
|
21
|
+
create: (params) => {
|
|
22
|
+
const parentPath = params.directoryId ? getFullPath(params.directoryId) : '';
|
|
23
|
+
const data = Object.assign(Object.assign({}, params), { id: getNewFileOrFolderId(), path: `${parentPath}/${params.name}` });
|
|
24
|
+
index_1.mockFiles.push(data);
|
|
25
|
+
return {
|
|
26
|
+
data,
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const getRootFolder = (appConfig) => {
|
|
31
|
+
var _a;
|
|
32
|
+
return ((_a = appConfig.projectIntegration) === null || _a === void 0 ? void 0 : _a.withRootFolder)
|
|
33
|
+
? {
|
|
34
|
+
id: 1,
|
|
35
|
+
projectId: index_1.mockProjectId,
|
|
36
|
+
branchId: 1,
|
|
37
|
+
directoryId: 0,
|
|
38
|
+
name: appConfig.name,
|
|
39
|
+
title: '',
|
|
40
|
+
exportPattern: '',
|
|
41
|
+
priority: 'normal',
|
|
42
|
+
createdAt: '',
|
|
43
|
+
updatedAt: '',
|
|
44
|
+
}
|
|
45
|
+
: undefined;
|
|
46
|
+
};
|
|
47
|
+
exports.getRootFolder = getRootFolder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mockAxios: any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockAxios = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const mockOriginalAxios = jest.requireActual('axios');
|
|
6
|
+
const mock = Object.assign(Object.assign({}, mockOriginalAxios), { get: jest.fn((url) => {
|
|
7
|
+
expect(url).toMatch(/^file-id:(\d+)$/);
|
|
8
|
+
const fileId = Number(url.replace('file-id:', ''));
|
|
9
|
+
const file = index_1.mockFiles.find(({ id }) => id === fileId);
|
|
10
|
+
const storageId = file === null || file === void 0 ? void 0 : file.storageId;
|
|
11
|
+
expect(storageId).not.toBeUndefined();
|
|
12
|
+
return {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
data: index_1.mockStoragesById[storageId].data,
|
|
16
|
+
};
|
|
17
|
+
}) });
|
|
18
|
+
exports.mockAxios = Object.assign(Object.assign({}, mock), { default: Object.assign({ create: () => (Object.assign({}, mock)) }, mock) });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mockCrowdinApiClient: any;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.mockCrowdinApiClient = void 0;
|
|
36
|
+
const globals_1 = require("@jest/globals");
|
|
37
|
+
const index_1 = require("../index");
|
|
38
|
+
const listSupportedLanguagesResponse = __importStar(require("../../crowdin-responses/mock-list-supported-languages.json"));
|
|
39
|
+
const getProjectResponse = __importStar(require("../../crowdin-responses/mock-get-project.json"));
|
|
40
|
+
const crowdin_storage_1 = require("./crowdin-storage");
|
|
41
|
+
const sleep = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const min = 10;
|
|
43
|
+
const max = 50;
|
|
44
|
+
return new Promise((resovle) => {
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
resovle();
|
|
47
|
+
}, Math.floor(Math.random() * (max - min) + min));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const mockBuildProjectFileTranslation = jest.fn((projectId, fileId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
(0, globals_1.expect)(projectId).toBe(index_1.mockProjectId);
|
|
52
|
+
yield sleep();
|
|
53
|
+
return {
|
|
54
|
+
data: {
|
|
55
|
+
url: `file-id:${fileId}`,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}));
|
|
59
|
+
const mockTranslationsApi = {
|
|
60
|
+
buildProjectFileTranslation: mockBuildProjectFileTranslation,
|
|
61
|
+
};
|
|
62
|
+
const mockUploadStorageApi = {
|
|
63
|
+
addStorage: (fileName, request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const id = Object.keys(index_1.mockStoragesById).length + 1; // 1
|
|
65
|
+
index_1.mockStoragesById[id] = {
|
|
66
|
+
name: fileName,
|
|
67
|
+
data: request,
|
|
68
|
+
};
|
|
69
|
+
yield sleep();
|
|
70
|
+
return {
|
|
71
|
+
data: {
|
|
72
|
+
id,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
const mockLanguagesApi = {
|
|
78
|
+
withFetchAll: () => {
|
|
79
|
+
return {
|
|
80
|
+
listSupportedLanguages: () => {
|
|
81
|
+
return listSupportedLanguagesResponse;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
const mockProjectsGroupsApi = {
|
|
87
|
+
getProject: function mockResponse() {
|
|
88
|
+
return getProjectResponse;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const mockCreateDirectory = jest.fn((projectId, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
(0, globals_1.expect)(projectId).toBe(index_1.mockProjectId);
|
|
93
|
+
yield sleep();
|
|
94
|
+
return crowdin_storage_1.crowdinFolders.create(params);
|
|
95
|
+
}));
|
|
96
|
+
const mockCreateFile = jest.fn((projectId, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
(0, globals_1.expect)(projectId).toBe(index_1.mockProjectId);
|
|
98
|
+
yield sleep();
|
|
99
|
+
return crowdin_storage_1.crowdinFiles.create(params);
|
|
100
|
+
}));
|
|
101
|
+
const mockListProjectDirectories = jest.fn((projectId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
(0, globals_1.expect)(projectId).toBe(index_1.mockProjectId);
|
|
103
|
+
return {
|
|
104
|
+
// data: options ? [] : mockDirectories.map((d: SourceFilesModel.Directory) => ({ data: d })),
|
|
105
|
+
data: index_1.mockDirectories.map((d) => ({ data: d })),
|
|
106
|
+
pagination: {
|
|
107
|
+
offset: 0,
|
|
108
|
+
limit: 0,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}));
|
|
112
|
+
const mockListProjectFiles = jest.fn((projectId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
(0, globals_1.expect)(projectId).toBe(index_1.mockProjectId);
|
|
114
|
+
return {
|
|
115
|
+
data: index_1.mockFiles.map((d) => ({ data: d })),
|
|
116
|
+
pagination: {
|
|
117
|
+
offset: 0,
|
|
118
|
+
limit: 0,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}));
|
|
122
|
+
const mockOriginalClient = jest.requireActual('@crowdin/crowdin-api-client');
|
|
123
|
+
exports.mockCrowdinApiClient = Object.assign(Object.assign({}, mockOriginalClient), { sourceFilesApi: {
|
|
124
|
+
withFetchAll: () => {
|
|
125
|
+
return {
|
|
126
|
+
listProjectDirectories: mockListProjectDirectories,
|
|
127
|
+
listProjectFiles: mockListProjectFiles,
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
createDirectory: mockCreateDirectory,
|
|
131
|
+
createFile: mockCreateFile,
|
|
132
|
+
}, projectsGroupsApi: mockProjectsGroupsApi, languagesApi: mockLanguagesApi, translationsApi: mockTranslationsApi, uploadStorageApi: mockUploadStorageApi });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IntegrationFile, TreeItem, UpdateIntegrationRequest } from '../../modules/integration/types';
|
|
2
|
+
export interface ExpectedObject {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface ExpectedUpdateCrowdin {
|
|
6
|
+
files?: ExpectedObject[];
|
|
7
|
+
folders?: ExpectedObject[];
|
|
8
|
+
}
|
|
9
|
+
export interface BaseMethodTestConfig {
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
setup?: () => Promise<void>;
|
|
12
|
+
extraChecks?: (params?: any) => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface GetIntegrationFilesConfig extends Omit<BaseMethodTestConfig, 'disabled'> {
|
|
15
|
+
expected: TreeItem[];
|
|
16
|
+
}
|
|
17
|
+
export interface UpdateCrowdinConfig extends Partial<BaseMethodTestConfig> {
|
|
18
|
+
updateProgressDisabled?: boolean;
|
|
19
|
+
expected?: ExpectedUpdateCrowdin;
|
|
20
|
+
updateRequest?: IntegrationFile[];
|
|
21
|
+
extraChecks?: (params: {
|
|
22
|
+
request: IntegrationFile[];
|
|
23
|
+
result?: unknown;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface UpdateIntegrationConfig extends BaseMethodTestConfig {
|
|
27
|
+
updateProgressDisabled?: boolean;
|
|
28
|
+
updateRequest?: UpdateIntegrationRequest;
|
|
29
|
+
extraChecks?: (params: {
|
|
30
|
+
request: UpdateIntegrationRequest;
|
|
31
|
+
result?: unknown;
|
|
32
|
+
}) => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export interface IntegrationTestConfig {
|
|
35
|
+
getIntegrationFiles: GetIntegrationFilesConfig;
|
|
36
|
+
updateCrowdin?: UpdateCrowdinConfig;
|
|
37
|
+
updateIntegration?: UpdateIntegrationConfig;
|
|
38
|
+
appSettings?: object;
|
|
39
|
+
integrationCredentials?: object;
|
|
40
|
+
beforeAll?: () => Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClientConfig, Config } from '../../types';
|
|
2
|
+
import { IntegrationTestConfig } from './types';
|
|
3
|
+
export declare const updateCrowdinTest: ({ appConfig, integrationTestConfig, }: {
|
|
4
|
+
appConfig: Config | ClientConfig;
|
|
5
|
+
integrationTestConfig: IntegrationTestConfig;
|
|
6
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.updateCrowdinTest = void 0;
|
|
16
|
+
const globals_1 = require("@jest/globals");
|
|
17
|
+
const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
|
|
18
|
+
const types_1 = require("../../modules/integration/util/types");
|
|
19
|
+
const index_1 = require("./index");
|
|
20
|
+
const crowdin_storage_1 = require("./mocks/crowdin-storage");
|
|
21
|
+
const util_1 = require("../util");
|
|
22
|
+
const getParents = (node, expectedTree, parentNames = []) => {
|
|
23
|
+
if (node.parentId) {
|
|
24
|
+
const parent = expectedTree.find(({ id }) => id === node.parentId);
|
|
25
|
+
if (parent) {
|
|
26
|
+
parentNames.unshift(parent.name);
|
|
27
|
+
return getParents(parent, expectedTree, parentNames);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return parentNames;
|
|
31
|
+
};
|
|
32
|
+
const getExpectedFolders = ({ integrationTestConfig, expectedTree, updateRequest, }) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if ((_b = (_a = integrationTestConfig.updateCrowdin) === null || _a === void 0 ? void 0 : _a.expected) === null || _b === void 0 ? void 0 : _b.folders) {
|
|
35
|
+
return integrationTestConfig.updateCrowdin.expected.folders;
|
|
36
|
+
}
|
|
37
|
+
const expectedDirectoriesByPath = {};
|
|
38
|
+
updateRequest.forEach((node) => {
|
|
39
|
+
const parentNames = getParents(node, expectedTree);
|
|
40
|
+
if (parentNames.length) {
|
|
41
|
+
const fullPath = `/${parentNames.join('/')}`;
|
|
42
|
+
expectedDirectoriesByPath[fullPath] = { path: fullPath, name: parentNames.pop() || '' };
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return Object.values(expectedDirectoriesByPath);
|
|
46
|
+
};
|
|
47
|
+
const getExpectedFiles = ({ integrationTestConfig, expectedTree, updateRequest, }) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if ((_b = (_a = integrationTestConfig.updateCrowdin) === null || _a === void 0 ? void 0 : _a.expected) === null || _b === void 0 ? void 0 : _b.files) {
|
|
50
|
+
return integrationTestConfig.updateCrowdin.expected.files;
|
|
51
|
+
}
|
|
52
|
+
const expectedFilesByPath = {};
|
|
53
|
+
updateRequest.forEach((node) => {
|
|
54
|
+
const parentNames = getParents(node, expectedTree);
|
|
55
|
+
parentNames.push(`${node.name}.${node.type}`);
|
|
56
|
+
const fullPath = `/${parentNames.join('/')}`;
|
|
57
|
+
expectedFilesByPath[fullPath] = { path: fullPath, name: parentNames.pop() || '' };
|
|
58
|
+
});
|
|
59
|
+
return Object.values(expectedFilesByPath);
|
|
60
|
+
};
|
|
61
|
+
const getFilesFromTree = (tree) => {
|
|
62
|
+
return tree
|
|
63
|
+
.filter((item) => 'type' in item)
|
|
64
|
+
.filter(({ type }) => type)
|
|
65
|
+
.map((file) => file);
|
|
66
|
+
};
|
|
67
|
+
const updateCrowdinTest = ({ appConfig, integrationTestConfig, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const { updateCrowdin, appSettings, integrationCredentials: credentials } = integrationTestConfig;
|
|
69
|
+
const expectedTree = integrationTestConfig.getIntegrationFiles.expected;
|
|
70
|
+
if (!appConfig.projectIntegration) {
|
|
71
|
+
throw new Error('The app configuration is missing the projectIntegration module.');
|
|
72
|
+
}
|
|
73
|
+
const client = new crowdin_api_client_1.default({ token: 'fakeToken' });
|
|
74
|
+
const request = getFilesFromTree(expectedTree);
|
|
75
|
+
const updateProgressMock = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
return { isCanceled: false };
|
|
77
|
+
}));
|
|
78
|
+
const rootFolder = (0, crowdin_storage_1.getRootFolder)(appConfig);
|
|
79
|
+
if (rootFolder) {
|
|
80
|
+
index_1.mockDirectories.push(rootFolder);
|
|
81
|
+
}
|
|
82
|
+
const result = yield (0, util_1.assert)(() => {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = appConfig.projectIntegration) === null || _a === void 0 ? void 0 : _a.updateCrowdin({
|
|
85
|
+
projectId: index_1.mockProjectId,
|
|
86
|
+
client,
|
|
87
|
+
credentials,
|
|
88
|
+
request,
|
|
89
|
+
rootFolder,
|
|
90
|
+
appSettings,
|
|
91
|
+
uploadTranslations: false,
|
|
92
|
+
job: {
|
|
93
|
+
get: function getJob() {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
return {
|
|
96
|
+
id: 'jobId1',
|
|
97
|
+
integrationId: 'string',
|
|
98
|
+
crowdinId: 'string',
|
|
99
|
+
type: types_1.JobType.UPDATE_TO_CROWDIN,
|
|
100
|
+
title: 'Sync files to Crowdin',
|
|
101
|
+
progress: 0,
|
|
102
|
+
status: types_1.JobStatus.CREATED,
|
|
103
|
+
createdAt: 0,
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
update: updateProgressMock,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}, 'Fail to run method updateCrowdin()');
|
|
111
|
+
if (!(updateCrowdin === null || updateCrowdin === void 0 ? void 0 : updateCrowdin.updateProgressDisabled)) {
|
|
112
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(updateProgressMock.mock.calls.length).toBeGreaterThanOrEqual(request.length), 'The sync progress should be updated at least once for each file in request');
|
|
113
|
+
}
|
|
114
|
+
const expectedFiles = getExpectedFiles({
|
|
115
|
+
integrationTestConfig,
|
|
116
|
+
expectedTree,
|
|
117
|
+
updateRequest: request,
|
|
118
|
+
});
|
|
119
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(index_1.mockFiles).toHaveLength(expectedFiles.length), `Files created: ${index_1.mockFiles.length}, but expected: ${expectedFiles.length}`);
|
|
120
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(index_1.mockFiles).toEqual(globals_1.expect.arrayContaining(expectedFiles.map((f) => globals_1.expect.objectContaining(f)))), 'The properties of the created files do not match to the expected');
|
|
121
|
+
const expectedDirectories = getExpectedFolders({
|
|
122
|
+
integrationTestConfig,
|
|
123
|
+
expectedTree,
|
|
124
|
+
updateRequest: request,
|
|
125
|
+
});
|
|
126
|
+
const createdDirectories = rootFolder
|
|
127
|
+
? index_1.mockDirectories.filter(({ id }) => rootFolder && id !== rootFolder.id)
|
|
128
|
+
: index_1.mockDirectories;
|
|
129
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(createdDirectories).toHaveLength(expectedDirectories.length), `Directories created: ${createdDirectories.length}, but expected: ${expectedDirectories.length}`);
|
|
130
|
+
yield (0, util_1.assert)(() => (0, globals_1.expect)(createdDirectories).toEqual(globals_1.expect.arrayContaining(expectedDirectories.map((f) => globals_1.expect.objectContaining(f)))), 'The properties of the created directories do not match to the expected');
|
|
131
|
+
if (updateCrowdin === null || updateCrowdin === void 0 ? void 0 : updateCrowdin.extraChecks) {
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
yield (0, util_1.assert)(() => updateCrowdin.extraChecks({ request, result }), 'ExtraChecks for updateCrowdin() fails');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
exports.updateCrowdinTest = updateCrowdinTest;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ClientConfig, Config } from '../../types';
|
|
2
|
+
import { UpdateIntegrationRequest } from '../../modules/integration/types';
|
|
3
|
+
import { IntegrationTestConfig } from './types';
|
|
4
|
+
export declare const getUpdateIntegrationRequest: () => UpdateIntegrationRequest;
|
|
5
|
+
export declare const updateIntegrationTest: ({ appConfig, integrationTestConfig, }: {
|
|
6
|
+
appConfig: Config | ClientConfig;
|
|
7
|
+
integrationTestConfig: IntegrationTestConfig;
|
|
8
|
+
}) => Promise<void>;
|