smartling-api-sdk-nodejs 3.3.0 → 3.4.0
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/.env.example +1 -1
- package/api/translation-memory/dto/async-action-result-dto.ts +12 -0
- package/api/translation-memory/dto/async-action-status.ts +8 -0
- package/api/translation-memory/dto/create-string-search-result-dto.ts +16 -0
- package/api/translation-memory/dto/duplicate-string-dto.ts +9 -0
- package/api/translation-memory/dto/locale-summary-dto.ts +10 -0
- package/api/translation-memory/dto/strings-export-async-action-result-dto.ts +8 -0
- package/api/translation-memory/dto/tm-dto.ts +23 -0
- package/api/translation-memory/dto/tm-locale-dto.ts +8 -0
- package/api/translation-memory/dto/tmx-import-summary-dto.ts +16 -0
- package/api/translation-memory/dto/tmx-parsing-error-dto.ts +7 -0
- package/api/translation-memory/dto/user-dto.ts +6 -0
- package/api/translation-memory/index.ts +368 -0
- package/api/translation-memory/params/bulk-export-tm-strings-parameters.ts +30 -0
- package/api/translation-memory/params/create-string-search-filter-parameters.ts +232 -0
- package/api/translation-memory/params/create-string-search-options.ts +8 -0
- package/api/translation-memory/params/create-tm-parameters.ts +28 -0
- package/api/translation-memory/params/escape-smp-unicode-parser-directive.ts +6 -0
- package/api/translation-memory/params/extended-export-metadata-type.ts +4 -0
- package/api/translation-memory/params/import-tmx-file-parameters.ts +76 -0
- package/api/translation-memory/params/keyword-search-type.ts +5 -0
- package/api/translation-memory/params/leverage-type.ts +5 -0
- package/api/translation-memory/params/search-keyword.ts +10 -0
- package/api/translation-memory/params/source-type.ts +7 -0
- package/api/translation-memory/params/string-search-tags.ts +7 -0
- package/api/translation-memory/params/translation-quality-type.ts +5 -0
- package/api/translation-memory/params/tu-translation-quality-type.ts +6 -0
- package/api/translation-memory/params/update-tm-parameters.ts +23 -0
- package/built/api/translation-memory/dto/async-action-result-dto.d.ts +10 -0
- package/built/api/translation-memory/dto/async-action-result-dto.js +3 -0
- package/built/api/translation-memory/dto/async-action-result-dto.js.map +1 -0
- package/built/api/translation-memory/dto/async-action-status.d.ts +8 -0
- package/built/api/translation-memory/dto/async-action-status.js +13 -0
- package/built/api/translation-memory/dto/async-action-status.js.map +1 -0
- package/built/api/translation-memory/dto/create-string-search-result-dto.d.ts +11 -0
- package/built/api/translation-memory/dto/create-string-search-result-dto.js +3 -0
- package/built/api/translation-memory/dto/create-string-search-result-dto.js.map +1 -0
- package/built/api/translation-memory/dto/duplicate-string-dto.d.ts +8 -0
- package/built/api/translation-memory/dto/duplicate-string-dto.js +3 -0
- package/built/api/translation-memory/dto/duplicate-string-dto.js.map +1 -0
- package/built/api/translation-memory/dto/locale-summary-dto.d.ts +8 -0
- package/built/api/translation-memory/dto/locale-summary-dto.js +3 -0
- package/built/api/translation-memory/dto/locale-summary-dto.js.map +1 -0
- package/built/api/translation-memory/dto/strings-export-async-action-result-dto.d.ts +6 -0
- package/built/api/translation-memory/dto/strings-export-async-action-result-dto.js +3 -0
- package/built/api/translation-memory/dto/strings-export-async-action-result-dto.js.map +1 -0
- package/built/api/translation-memory/dto/tm-dto.d.ts +19 -0
- package/built/api/translation-memory/dto/tm-dto.js +3 -0
- package/built/api/translation-memory/dto/tm-dto.js.map +1 -0
- package/built/api/translation-memory/dto/tm-locale-dto.d.ts +7 -0
- package/built/api/translation-memory/dto/tm-locale-dto.js +3 -0
- package/built/api/translation-memory/dto/tm-locale-dto.js.map +1 -0
- package/built/api/translation-memory/dto/tmx-import-summary-dto.d.ts +11 -0
- package/built/api/translation-memory/dto/tmx-import-summary-dto.js +3 -0
- package/built/api/translation-memory/dto/tmx-import-summary-dto.js.map +1 -0
- package/built/api/translation-memory/dto/tmx-parsing-error-dto.d.ts +6 -0
- package/built/api/translation-memory/dto/tmx-parsing-error-dto.js +3 -0
- package/built/api/translation-memory/dto/tmx-parsing-error-dto.js.map +1 -0
- package/built/api/translation-memory/dto/user-dto.d.ts +5 -0
- package/built/api/translation-memory/dto/user-dto.js +3 -0
- package/built/api/translation-memory/dto/user-dto.js.map +1 -0
- package/built/api/translation-memory/index.d.ts +27 -0
- package/built/api/translation-memory/index.js +250 -0
- package/built/api/translation-memory/index.js.map +1 -0
- package/built/api/translation-memory/params/bulk-export-tm-strings-parameters.d.ts +8 -0
- package/built/api/translation-memory/params/bulk-export-tm-strings-parameters.js +24 -0
- package/built/api/translation-memory/params/bulk-export-tm-strings-parameters.js.map +1 -0
- package/built/api/translation-memory/params/create-string-search-filter-parameters.d.ts +43 -0
- package/built/api/translation-memory/params/create-string-search-filter-parameters.js +151 -0
- package/built/api/translation-memory/params/create-string-search-filter-parameters.js.map +1 -0
- package/built/api/translation-memory/params/create-string-search-options.d.ts +7 -0
- package/built/api/translation-memory/params/create-string-search-options.js +3 -0
- package/built/api/translation-memory/params/create-string-search-options.js.map +1 -0
- package/built/api/translation-memory/params/create-tm-parameters.d.ts +8 -0
- package/built/api/translation-memory/params/create-tm-parameters.js +24 -0
- package/built/api/translation-memory/params/create-tm-parameters.js.map +1 -0
- package/built/api/translation-memory/params/escape-smp-unicode-parser-directive.d.ts +4 -0
- package/built/api/translation-memory/params/escape-smp-unicode-parser-directive.js +9 -0
- package/built/api/translation-memory/params/escape-smp-unicode-parser-directive.js.map +1 -0
- package/built/api/translation-memory/params/extended-export-metadata-type.d.ts +4 -0
- package/built/api/translation-memory/params/extended-export-metadata-type.js +9 -0
- package/built/api/translation-memory/params/extended-export-metadata-type.js.map +1 -0
- package/built/api/translation-memory/params/import-tmx-file-parameters.d.ts +17 -0
- package/built/api/translation-memory/params/import-tmx-file-parameters.js +80 -0
- package/built/api/translation-memory/params/import-tmx-file-parameters.js.map +1 -0
- package/built/api/translation-memory/params/keyword-search-type.d.ts +5 -0
- package/built/api/translation-memory/params/keyword-search-type.js +10 -0
- package/built/api/translation-memory/params/keyword-search-type.js.map +1 -0
- package/built/api/translation-memory/params/leverage-type.d.ts +5 -0
- package/built/api/translation-memory/params/leverage-type.js +10 -0
- package/built/api/translation-memory/params/leverage-type.js.map +1 -0
- package/built/api/translation-memory/params/search-keyword.d.ts +8 -0
- package/built/api/translation-memory/params/search-keyword.js +3 -0
- package/built/api/translation-memory/params/search-keyword.js.map +1 -0
- package/built/api/translation-memory/params/source-type.d.ts +7 -0
- package/built/api/translation-memory/params/source-type.js +12 -0
- package/built/api/translation-memory/params/source-type.js.map +1 -0
- package/built/api/translation-memory/params/string-search-tags.d.ts +6 -0
- package/built/api/translation-memory/params/string-search-tags.js +3 -0
- package/built/api/translation-memory/params/string-search-tags.js.map +1 -0
- package/built/api/translation-memory/params/translation-quality-type.d.ts +5 -0
- package/built/api/translation-memory/params/translation-quality-type.js +10 -0
- package/built/api/translation-memory/params/translation-quality-type.js.map +1 -0
- package/built/api/translation-memory/params/tu-translation-quality-type.d.ts +6 -0
- package/built/api/translation-memory/params/tu-translation-quality-type.js +11 -0
- package/built/api/translation-memory/params/tu-translation-quality-type.js.map +1 -0
- package/built/api/translation-memory/params/update-tm-parameters.d.ts +6 -0
- package/built/api/translation-memory/params/update-tm-parameters.js +20 -0
- package/built/api/translation-memory/params/update-tm-parameters.js.map +1 -0
- package/built/index.d.ts +27 -0
- package/built/index.js +27 -0
- package/built/index.js.map +1 -1
- package/built/package.json +1 -1
- package/built/test/integration/translation-memory.spec.d.ts +1 -0
- package/built/test/integration/translation-memory.spec.js +138 -0
- package/built/test/integration/translation-memory.spec.js.map +1 -0
- package/built/test/translation-memory.spec.d.ts +1 -0
- package/built/test/translation-memory.spec.js +712 -0
- package/built/test/translation-memory.spec.js.map +1 -0
- package/index.ts +27 -0
- package/package.json +1 -1
- package/test/data/sample.tmx +12 -0
- package/test/integration/translation-memory.spec.ts +182 -0
- package/test/translation-memory.spec.ts +868 -0
|
@@ -0,0 +1,712 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
40
|
+
const assert_1 = __importDefault(require("assert"));
|
|
41
|
+
const mock_1 = require("./mock");
|
|
42
|
+
const index_1 = require("../api/translation-memory/index");
|
|
43
|
+
const import_tmx_file_parameters_1 = require("../api/translation-memory/params/import-tmx-file-parameters");
|
|
44
|
+
const escape_smp_unicode_parser_directive_1 = require("../api/translation-memory/params/escape-smp-unicode-parser-directive");
|
|
45
|
+
const create_string_search_filter_parameters_1 = require("../api/translation-memory/params/create-string-search-filter-parameters");
|
|
46
|
+
const bulk_export_tm_strings_parameters_1 = require("../api/translation-memory/params/bulk-export-tm-strings-parameters");
|
|
47
|
+
const extended_export_metadata_type_1 = require("../api/translation-memory/params/extended-export-metadata-type");
|
|
48
|
+
const create_tm_parameters_1 = require("../api/translation-memory/params/create-tm-parameters");
|
|
49
|
+
const update_tm_parameters_1 = require("../api/translation-memory/params/update-tm-parameters");
|
|
50
|
+
const translation_quality_type_1 = require("../api/translation-memory/params/translation-quality-type");
|
|
51
|
+
const leverage_type_1 = require("../api/translation-memory/params/leverage-type");
|
|
52
|
+
const source_type_1 = require("../api/translation-memory/params/source-type");
|
|
53
|
+
const tu_translation_quality_type_1 = require("../api/translation-memory/params/tu-translation-quality-type");
|
|
54
|
+
const keyword_search_type_1 = require("../api/translation-memory/params/keyword-search-type");
|
|
55
|
+
const index_2 = require("../api/exception/index");
|
|
56
|
+
const stream_to_string_1 = require("./stream-to-string");
|
|
57
|
+
function formDataText(formData) {
|
|
58
|
+
return formData._streams.filter((entry) => typeof entry === "string").join("");
|
|
59
|
+
}
|
|
60
|
+
const noRequestIdHeaders = { get: () => null };
|
|
61
|
+
function tmGraphQlResponseMock(operationName, tm) {
|
|
62
|
+
return {
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: noRequestIdHeaders,
|
|
65
|
+
text: () => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return JSON.stringify({
|
|
67
|
+
data: {
|
|
68
|
+
[operationName]: tm
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const sampleTm = {
|
|
75
|
+
tmUid: "j45v1uvsi3tx",
|
|
76
|
+
name: "Integration test TM",
|
|
77
|
+
description: "Created by the SDK test suite",
|
|
78
|
+
sourceLocaleId: "en-US",
|
|
79
|
+
sourceLocale: {
|
|
80
|
+
localeId: "en-US",
|
|
81
|
+
localeDescription: "English (United States)",
|
|
82
|
+
rtlLanguage: false,
|
|
83
|
+
wordSpacing: true
|
|
84
|
+
},
|
|
85
|
+
creator: { userUid: "creatorUid", name: "Creator Name" },
|
|
86
|
+
created: "2026-06-17T00:09:44Z",
|
|
87
|
+
lastModifier: { userUid: "modifierUid", name: "Modifier Name" },
|
|
88
|
+
lastModified: "2026-06-17T00:09:44Z",
|
|
89
|
+
localeSummary: [],
|
|
90
|
+
translationQuality: "TRANSLATION",
|
|
91
|
+
managedWordsEnabled: false
|
|
92
|
+
};
|
|
93
|
+
describe("SmartlingTranslationMemoryApi class tests.", () => {
|
|
94
|
+
const accountUid = "testAccountUid";
|
|
95
|
+
let translationMemoryApi;
|
|
96
|
+
let fetchStub;
|
|
97
|
+
let uaStub;
|
|
98
|
+
let responseMockJsonStub;
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
translationMemoryApi = new index_1.SmartlingTranslationMemoryApi("https://test.com", mock_1.authMock, mock_1.loggerMock);
|
|
101
|
+
fetchStub = sinon_1.default.stub(translationMemoryApi, "fetch");
|
|
102
|
+
uaStub = sinon_1.default.stub(translationMemoryApi, "ua");
|
|
103
|
+
responseMockJsonStub = sinon_1.default.stub(mock_1.responseMock, "json");
|
|
104
|
+
uaStub.returns("test_user_agent");
|
|
105
|
+
fetchStub.returns(mock_1.responseMock);
|
|
106
|
+
responseMockJsonStub.returns({ response: {} });
|
|
107
|
+
});
|
|
108
|
+
afterEach(() => {
|
|
109
|
+
fetchStub.restore();
|
|
110
|
+
responseMockJsonStub.restore();
|
|
111
|
+
uaStub.restore();
|
|
112
|
+
});
|
|
113
|
+
describe("Methods", () => {
|
|
114
|
+
it("Import TMX file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
116
|
+
.setFileFromLocalFilePath("./test/data/file.xml")
|
|
117
|
+
.setFileUri("test/file.tmx")
|
|
118
|
+
.setTmUid("j45v1uvsi3tx")
|
|
119
|
+
.setDescription("Integration test import")
|
|
120
|
+
.setTranslatorNameLocation("@tu.changeid")
|
|
121
|
+
.setTranslationDateLocation("@tu.creationdate")
|
|
122
|
+
.setVariantLocation("@prop.type.x-SID:SingleString")
|
|
123
|
+
.setFileUriLocation("@prop.type.x-idiom-source-ipath")
|
|
124
|
+
.setEscapeSmpUnicodeParserDirective(escape_smp_unicode_parser_directive_1.EscapeSmpUnicodeParserDirective.ON);
|
|
125
|
+
yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
126
|
+
sinon_1.default.assert.calledOnce(fetchStub);
|
|
127
|
+
assert_1.default.equal(fetchStub.getCall(0).args[0], `https://test.com/tm-tmx-api/v2/accounts/${accountUid}/tmx/file`);
|
|
128
|
+
assert_1.default.equal(fetchStub.getCall(0).args[1].method, "post");
|
|
129
|
+
assert_1.default.equal(fetchStub.getCall(0).args[1].headers.Authorization, "test_token_type test_access_token");
|
|
130
|
+
assert_1.default.equal(yield (0, stream_to_string_1.streamToString)(fetchStub.getCall(0).args[1].body._streams[1]), fs.readFileSync(fs.realpathSync("./test/data/file.xml"), "utf8"));
|
|
131
|
+
const fields = formDataText(fetchStub.getCall(0).args[1].body);
|
|
132
|
+
assert_1.default.ok(fields.includes("name=\"file\""));
|
|
133
|
+
assert_1.default.ok(fields.includes("name=\"fileUri\"") && fields.includes("test/file.tmx"));
|
|
134
|
+
assert_1.default.ok(fields.includes("name=\"tmUid\"") && fields.includes("j45v1uvsi3tx"));
|
|
135
|
+
assert_1.default.ok(fields.includes("name=\"description\"") && fields.includes("Integration test import"));
|
|
136
|
+
assert_1.default.ok(fields.includes("name=\"translatorNameLocation\"") && fields.includes("@tu.changeid"));
|
|
137
|
+
assert_1.default.ok(fields.includes("name=\"translationDateLocation\"") && fields.includes("@tu.creationdate"));
|
|
138
|
+
assert_1.default.ok(fields.includes("name=\"variantLocation\"") && fields.includes("@prop.type.x-SID:SingleString"));
|
|
139
|
+
assert_1.default.ok(fields.includes("name=\"fileUriLocation\"") && fields.includes("@prop.type.x-idiom-source-ipath"));
|
|
140
|
+
assert_1.default.ok(fields.includes("name=\"escapeSmpUnicodeParserDirective\"") && fields.includes("on"));
|
|
141
|
+
}));
|
|
142
|
+
it("Import TMX file: as string", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
144
|
+
.setFileContent(fs.readFileSync(fs.realpathSync("./test/data/file.xml"), "utf8"))
|
|
145
|
+
.setFileUri("test/file.tmx")
|
|
146
|
+
.setTmUid("j45v1uvsi3tx");
|
|
147
|
+
yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
148
|
+
sinon_1.default.assert.calledOnce(fetchStub);
|
|
149
|
+
assert_1.default.equal(yield (0, stream_to_string_1.streamToString)(fetchStub.getCall(0).args[1].body._streams[1]), fs.readFileSync(fs.realpathSync("./test/data/file.xml"), "utf8"));
|
|
150
|
+
}));
|
|
151
|
+
it("Import TMX file: from buffer", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
const fileBuffer = fs.readFileSync(fs.realpathSync("./test/data/file.xml"));
|
|
153
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
154
|
+
.setFileContentFromBuffer(fileBuffer)
|
|
155
|
+
.setFileUri("test/file.tmx")
|
|
156
|
+
.setTmUid("j45v1uvsi3tx");
|
|
157
|
+
yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
158
|
+
sinon_1.default.assert.calledOnce(fetchStub);
|
|
159
|
+
assert_1.default.ok(fetchStub.getCall(0).args[1].body._streams[1].equals(fileBuffer));
|
|
160
|
+
}));
|
|
161
|
+
it("Import TMX file: FormData body is not reconverted on a 401 retry", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
163
|
+
.setFileFromLocalFilePath("./test/data/file.xml")
|
|
164
|
+
.setFileUri("test/file.tmx")
|
|
165
|
+
.setTmUid("j45v1uvsi3tx");
|
|
166
|
+
fetchStub.onCall(0).returns({ status: 401 });
|
|
167
|
+
fetchStub.onCall(1).returns(mock_1.responseMock);
|
|
168
|
+
yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
169
|
+
sinon_1.default.assert.calledTwice(fetchStub);
|
|
170
|
+
assert_1.default.strictEqual(fetchStub.getCall(0).args[1].body, fetchStub.getCall(1).args[1].body);
|
|
171
|
+
assert_1.default.equal(yield (0, stream_to_string_1.streamToString)(fetchStub.getCall(1).args[1].body._streams[1]), fs.readFileSync(fs.realpathSync("./test/data/file.xml"), "utf8"));
|
|
172
|
+
}));
|
|
173
|
+
it("Import TMX file: warns when the response has partial import errors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
const warnStub = sinon_1.default.stub(mock_1.loggerMock, "warn");
|
|
175
|
+
fetchStub.returns({
|
|
176
|
+
status: 200,
|
|
177
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
178
|
+
return JSON.stringify({
|
|
179
|
+
response: {
|
|
180
|
+
data: {
|
|
181
|
+
message: null,
|
|
182
|
+
wordCount: 10,
|
|
183
|
+
stringCount: 5,
|
|
184
|
+
translationMemoryImportErrors: [
|
|
185
|
+
{ messages: ["bad string"], line: 3, column: 1 }
|
|
186
|
+
],
|
|
187
|
+
parsingErrors: null,
|
|
188
|
+
jobUid: "job-1",
|
|
189
|
+
tmxUid: "tmx-1"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
196
|
+
.setFileContentFromBuffer(Buffer.from("<tmx/>"))
|
|
197
|
+
.setFileUri("test/file.tmx")
|
|
198
|
+
.setTmUid("j45v1uvsi3tx");
|
|
199
|
+
const result = yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
200
|
+
assert_1.default.equal(result.jobUid, "job-1");
|
|
201
|
+
assert_1.default.equal(result.tmxUid, "tmx-1");
|
|
202
|
+
assert_1.default.equal(result.wordCount, 10);
|
|
203
|
+
assert_1.default.equal(result.stringCount, 5);
|
|
204
|
+
sinon_1.default.assert.calledOnce(warnStub);
|
|
205
|
+
assert_1.default.ok(warnStub.getCall(0).args[0].includes("bad string"));
|
|
206
|
+
warnStub.restore();
|
|
207
|
+
}));
|
|
208
|
+
it("Import TMX file: does not warn when error arrays are merely empty", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
const warnStub = sinon_1.default.stub(mock_1.loggerMock, "warn");
|
|
210
|
+
fetchStub.returns({
|
|
211
|
+
status: 200,
|
|
212
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
213
|
+
return JSON.stringify({
|
|
214
|
+
response: {
|
|
215
|
+
data: {
|
|
216
|
+
message: null,
|
|
217
|
+
wordCount: 10,
|
|
218
|
+
stringCount: 5,
|
|
219
|
+
translationMemoryImportErrors: [],
|
|
220
|
+
parsingErrors: [],
|
|
221
|
+
jobUid: "job-1",
|
|
222
|
+
tmxUid: "tmx-1"
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
const params = new import_tmx_file_parameters_1.ImportTmxFileParameters()
|
|
229
|
+
.setFileContentFromBuffer(Buffer.from("<tmx/>"))
|
|
230
|
+
.setFileUri("test/file.tmx")
|
|
231
|
+
.setTmUid("j45v1uvsi3tx");
|
|
232
|
+
yield translationMemoryApi.importTmxFile(accountUid, params);
|
|
233
|
+
sinon_1.default.assert.notCalled(warnStub);
|
|
234
|
+
warnStub.restore();
|
|
235
|
+
}));
|
|
236
|
+
it("Download TMX file", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
237
|
+
const downloadResponseMock = {
|
|
238
|
+
status: 200,
|
|
239
|
+
headers: {
|
|
240
|
+
get: (name) => {
|
|
241
|
+
if (name === "content-type") {
|
|
242
|
+
return "application/xml";
|
|
243
|
+
}
|
|
244
|
+
if (name === "content-disposition") {
|
|
245
|
+
return "attachment; filename=\"export.tmx\"";
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
arrayBuffer: () => __awaiter(void 0, void 0, void 0, function* () { return new ArrayBuffer(8); })
|
|
251
|
+
};
|
|
252
|
+
fetchStub.returns(downloadResponseMock);
|
|
253
|
+
const result = yield translationMemoryApi.downloadTmxFile(accountUid, "a+b/c==");
|
|
254
|
+
sinon_1.default.assert.calledOnceWithExactly(fetchStub, `https://test.com/tm-tmx-api/v2/accounts/${accountUid}/tmx/file/a%2Bb%2Fc%3D%3D`, {
|
|
255
|
+
method: "get",
|
|
256
|
+
headers: {
|
|
257
|
+
Authorization: "test_token_type test_access_token",
|
|
258
|
+
"Content-Type": "application/json",
|
|
259
|
+
"User-Agent": "test_user_agent"
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
assert_1.default.equal(result.fileName, "export.tmx");
|
|
263
|
+
assert_1.default.equal(result.contentType, "application/xml");
|
|
264
|
+
}));
|
|
265
|
+
it("Create string search", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
266
|
+
const graphQlResponseMock = {
|
|
267
|
+
status: 200,
|
|
268
|
+
headers: noRequestIdHeaders,
|
|
269
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
270
|
+
return JSON.stringify({
|
|
271
|
+
data: {
|
|
272
|
+
createStringSearch: {
|
|
273
|
+
searchUid: "2z68632hdvw2",
|
|
274
|
+
stringCount: 10,
|
|
275
|
+
wordCount: 20,
|
|
276
|
+
duplicateStrings: [],
|
|
277
|
+
duplicateSearch: false,
|
|
278
|
+
actionUid: "d23eb702-7358-11ea-bc55-0242ac130003",
|
|
279
|
+
offlineReportUid: "6a2f41a3-c54c-fce8-32d2-0324e1c32e22"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
})
|
|
284
|
+
};
|
|
285
|
+
fetchStub.returns(graphQlResponseMock);
|
|
286
|
+
const filter = new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()
|
|
287
|
+
.setTmUids(["j45v1uvsi3tx"])
|
|
288
|
+
.setSourceLocaleIds(["en-US"]);
|
|
289
|
+
const result = yield translationMemoryApi.createStringSearch(accountUid, filter);
|
|
290
|
+
sinon_1.default.assert.calledOnce(fetchStub);
|
|
291
|
+
assert_1.default.equal(fetchStub.getCall(0).args[0], `https://test.com/tm-graphql-api/v2/accounts/${accountUid}/graphql`);
|
|
292
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
293
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
294
|
+
createStringSearchFilter: {
|
|
295
|
+
tmUids: ["j45v1uvsi3tx"],
|
|
296
|
+
sourceLocaleIds: ["en-US"]
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
assert_1.default.ok(sentBody.query.includes("createStringSearch"));
|
|
300
|
+
[
|
|
301
|
+
"searchUid", "stringCount", "wordCount", "duplicateStrings", "duplicateKey",
|
|
302
|
+
"count", "srcText", "srcLocale", "translationLocale", "duplicateSearch",
|
|
303
|
+
"actionUid", "offlineReportUid"
|
|
304
|
+
].forEach((field) => {
|
|
305
|
+
assert_1.default.ok(sentBody.query.includes(field), `query is missing field "${field}"`);
|
|
306
|
+
});
|
|
307
|
+
assert_1.default.equal(result.searchUid, "2z68632hdvw2");
|
|
308
|
+
assert_1.default.equal(result.stringCount, 10);
|
|
309
|
+
}));
|
|
310
|
+
it("Create string search: GraphQL error is thrown", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
311
|
+
const graphQlResponseMock = {
|
|
312
|
+
status: 200,
|
|
313
|
+
headers: noRequestIdHeaders,
|
|
314
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
315
|
+
return JSON.stringify({
|
|
316
|
+
errors: [{ message: "tmUids is required" }]
|
|
317
|
+
});
|
|
318
|
+
})
|
|
319
|
+
};
|
|
320
|
+
fetchStub.returns(graphQlResponseMock);
|
|
321
|
+
yield assert_1.default.rejects(translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()), (e) => {
|
|
322
|
+
assert_1.default.ok(e instanceof index_2.SmartlingException);
|
|
323
|
+
assert_1.default.ok(e.message.includes("tmUids is required"));
|
|
324
|
+
assert_1.default.deepEqual(e.getPayload().errors, [{ message: "tmUids is required" }]);
|
|
325
|
+
return true;
|
|
326
|
+
});
|
|
327
|
+
}));
|
|
328
|
+
it("Create string search: an empty errors array does not throw", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
|
+
fetchStub.returns({
|
|
330
|
+
status: 200,
|
|
331
|
+
headers: noRequestIdHeaders,
|
|
332
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
333
|
+
return JSON.stringify({
|
|
334
|
+
errors: [],
|
|
335
|
+
data: { createStringSearch: { searchUid: "2z68632hdvw2" } }
|
|
336
|
+
});
|
|
337
|
+
})
|
|
338
|
+
});
|
|
339
|
+
const result = yield translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters());
|
|
340
|
+
assert_1.default.equal(result.searchUid, "2z68632hdvw2");
|
|
341
|
+
}));
|
|
342
|
+
it("Create string search: a null result is returned as null, not thrown", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
343
|
+
fetchStub.returns({
|
|
344
|
+
status: 200,
|
|
345
|
+
headers: noRequestIdHeaders,
|
|
346
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
return JSON.stringify({
|
|
348
|
+
data: { createStringSearch: null }
|
|
349
|
+
});
|
|
350
|
+
})
|
|
351
|
+
});
|
|
352
|
+
const result = yield translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters());
|
|
353
|
+
assert_1.default.equal(result, null);
|
|
354
|
+
}));
|
|
355
|
+
it("Create string search: requestId is propagated into the thrown exception", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
356
|
+
fetchStub.returns({
|
|
357
|
+
status: 200,
|
|
358
|
+
headers: { get: (name) => (name === "x-sl-requestid" ? "test-request-id" : null) },
|
|
359
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
360
|
+
return JSON.stringify({
|
|
361
|
+
errors: [{ message: "tmUids is required" }]
|
|
362
|
+
});
|
|
363
|
+
})
|
|
364
|
+
});
|
|
365
|
+
yield assert_1.default.rejects(translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()), (e) => {
|
|
366
|
+
assert_1.default.equal(e.getPayload().requestId, "test-request-id");
|
|
367
|
+
return true;
|
|
368
|
+
});
|
|
369
|
+
}));
|
|
370
|
+
it("Create string search: malformed JSON response throws", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
+
fetchStub.returns({
|
|
372
|
+
status: 200,
|
|
373
|
+
headers: noRequestIdHeaders,
|
|
374
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return "not json"; })
|
|
375
|
+
});
|
|
376
|
+
yield assert_1.default.rejects(translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()), (e) => {
|
|
377
|
+
assert_1.default.ok(e instanceof index_2.SmartlingException);
|
|
378
|
+
assert_1.default.ok(e.message.includes("Couldn't parse GraphQL response json"));
|
|
379
|
+
assert_1.default.ok(e.getNestedException() instanceof Error);
|
|
380
|
+
return true;
|
|
381
|
+
});
|
|
382
|
+
}));
|
|
383
|
+
it("Create string search: response missing data entirely throws", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
384
|
+
fetchStub.returns({
|
|
385
|
+
status: 200,
|
|
386
|
+
headers: noRequestIdHeaders,
|
|
387
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify({}); })
|
|
388
|
+
});
|
|
389
|
+
yield assert_1.default.rejects(translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()), (e) => {
|
|
390
|
+
assert_1.default.ok(e instanceof index_2.SmartlingException);
|
|
391
|
+
assert_1.default.ok(e.message.includes("is missing the expected field"));
|
|
392
|
+
return true;
|
|
393
|
+
});
|
|
394
|
+
}));
|
|
395
|
+
it("Create string search: data present but missing the operation's own key throws", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
396
|
+
fetchStub.returns({
|
|
397
|
+
status: 200,
|
|
398
|
+
headers: noRequestIdHeaders,
|
|
399
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
400
|
+
return JSON.stringify({
|
|
401
|
+
data: { someOtherOperation: { searchUid: "abc" } }
|
|
402
|
+
});
|
|
403
|
+
})
|
|
404
|
+
});
|
|
405
|
+
yield assert_1.default.rejects(translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()), (e) => {
|
|
406
|
+
assert_1.default.ok(e instanceof index_2.SmartlingException);
|
|
407
|
+
assert_1.default.ok(e.message.includes("is missing the expected field"));
|
|
408
|
+
return true;
|
|
409
|
+
});
|
|
410
|
+
}));
|
|
411
|
+
it("Create string search: a non-array errors field logs a warning and does not throw", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
412
|
+
const warnStub = sinon_1.default.stub(mock_1.loggerMock, "warn");
|
|
413
|
+
fetchStub.returns({
|
|
414
|
+
status: 200,
|
|
415
|
+
headers: noRequestIdHeaders,
|
|
416
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
417
|
+
return JSON.stringify({
|
|
418
|
+
errors: { message: "unexpected shape" },
|
|
419
|
+
data: { createStringSearch: { searchUid: "2z68632hdvw2" } }
|
|
420
|
+
});
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
const result = yield translationMemoryApi.createStringSearch(accountUid, new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters());
|
|
424
|
+
assert_1.default.ok(result);
|
|
425
|
+
assert_1.default.equal(result.searchUid, "2z68632hdvw2");
|
|
426
|
+
sinon_1.default.assert.calledOnce(warnStub);
|
|
427
|
+
assert_1.default.ok(warnStub.getCall(0).args[0].includes("unexpected"));
|
|
428
|
+
warnStub.restore();
|
|
429
|
+
}));
|
|
430
|
+
it("Bulk export TM strings", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
431
|
+
const graphQlResponseMock = {
|
|
432
|
+
status: 200,
|
|
433
|
+
headers: noRequestIdHeaders,
|
|
434
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
435
|
+
return JSON.stringify({
|
|
436
|
+
data: {
|
|
437
|
+
bulkExportTmStrings: {
|
|
438
|
+
actionUid: "d23eb702-7358-11ea-bc55-0242ac130003",
|
|
439
|
+
totalCount: 123,
|
|
440
|
+
processedCount: 0,
|
|
441
|
+
errorCount: 0,
|
|
442
|
+
executionComplete: false,
|
|
443
|
+
actionStatus: "QUEUEING"
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
})
|
|
448
|
+
};
|
|
449
|
+
fetchStub.returns(graphQlResponseMock);
|
|
450
|
+
const params = new bulk_export_tm_strings_parameters_1.BulkExportTmStringsParameters()
|
|
451
|
+
.setSearchUid("2z68632hdvw2")
|
|
452
|
+
.setExtendedMetadata(true)
|
|
453
|
+
.setExtendedMetadataType(extended_export_metadata_type_1.ExtendedExportMetadataType.FIRST_TRANSLATED_STRINGS)
|
|
454
|
+
.setIncludeAllVariants(true);
|
|
455
|
+
const result = yield translationMemoryApi.bulkExportTmStrings(accountUid, params);
|
|
456
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
457
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
458
|
+
bulkExportTmStrings: {
|
|
459
|
+
searchUid: "2z68632hdvw2",
|
|
460
|
+
extendedMetadata: true,
|
|
461
|
+
extendedMetadataType: "FIRST_TRANSLATED_STRINGS",
|
|
462
|
+
includeAllVariants: true
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
assert_1.default.ok(sentBody.query.includes("bulkExportTmStrings"));
|
|
466
|
+
assert_1.default.ok(sentBody.query.includes("executionComplete"));
|
|
467
|
+
assert_1.default.ok(sentBody.query.includes("actionStatus"));
|
|
468
|
+
assert_1.default.ok(result);
|
|
469
|
+
assert_1.default.equal(result.actionUid, "d23eb702-7358-11ea-bc55-0242ac130003");
|
|
470
|
+
assert_1.default.equal(result.actionStatus, "QUEUEING");
|
|
471
|
+
}));
|
|
472
|
+
it("Get bulk export TM strings status", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
473
|
+
const debugStub = sinon_1.default.stub(mock_1.loggerMock, "debug");
|
|
474
|
+
const graphQlResponseMock = {
|
|
475
|
+
status: 200,
|
|
476
|
+
headers: noRequestIdHeaders,
|
|
477
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
478
|
+
return JSON.stringify({
|
|
479
|
+
data: {
|
|
480
|
+
bulkExportTmStringsStatus: {
|
|
481
|
+
actionUid: "d23eb702-7358-11ea-bc55-0242ac130003",
|
|
482
|
+
totalCount: 123,
|
|
483
|
+
processedCount: 123,
|
|
484
|
+
errorCount: 0,
|
|
485
|
+
executionComplete: true,
|
|
486
|
+
tmxDownloadKey: "ZGpoaDczaGRqc2o6MA==",
|
|
487
|
+
expired: false,
|
|
488
|
+
actionStatus: "SUCCESS"
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
})
|
|
493
|
+
};
|
|
494
|
+
fetchStub.returns(graphQlResponseMock);
|
|
495
|
+
const result = yield translationMemoryApi.getBulkExportTmStringsStatus(accountUid, "d23eb702-7358-11ea-bc55-0242ac130003");
|
|
496
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
497
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
498
|
+
actionUid: "d23eb702-7358-11ea-bc55-0242ac130003"
|
|
499
|
+
});
|
|
500
|
+
assert_1.default.ok(sentBody.query.includes("bulkExportTmStringsStatus"));
|
|
501
|
+
assert_1.default.ok(sentBody.query.includes("tmxDownloadKey"));
|
|
502
|
+
assert_1.default.ok(sentBody.query.includes("expired"));
|
|
503
|
+
assert_1.default.ok(result);
|
|
504
|
+
assert_1.default.equal(result.tmxDownloadKey, "ZGpoaDczaGRqc2o6MA==");
|
|
505
|
+
assert_1.default.equal(result.executionComplete, true);
|
|
506
|
+
sinon_1.default.assert.calledOnce(debugStub);
|
|
507
|
+
const loggedText = debugStub.getCall(0).args[0];
|
|
508
|
+
assert_1.default.ok(loggedText.includes("[REDACTED]"));
|
|
509
|
+
assert_1.default.ok(!loggedText.includes("ZGpoaDczaGRqc2o6MA=="));
|
|
510
|
+
debugStub.restore();
|
|
511
|
+
}));
|
|
512
|
+
it("Get bulk export TM strings status: tmxDownloadKey is redacted in a thrown exception's payload too", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
513
|
+
fetchStub.returns({
|
|
514
|
+
status: 200,
|
|
515
|
+
headers: noRequestIdHeaders,
|
|
516
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
517
|
+
return JSON.stringify({
|
|
518
|
+
errors: [{ message: "partial failure" }],
|
|
519
|
+
data: {
|
|
520
|
+
bulkExportTmStringsStatus: {
|
|
521
|
+
actionUid: "d23eb702-7358-11ea-bc55-0242ac130003",
|
|
522
|
+
tmxDownloadKey: "ZGpoaDczaGRqc2o6MA=="
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
})
|
|
527
|
+
});
|
|
528
|
+
yield assert_1.default.rejects(translationMemoryApi.getBulkExportTmStringsStatus(accountUid, "d23eb702-7358-11ea-bc55-0242ac130003"), (e) => {
|
|
529
|
+
const payloadText = JSON.stringify(e.getPayload());
|
|
530
|
+
assert_1.default.ok(payloadText.includes("[REDACTED]"));
|
|
531
|
+
assert_1.default.ok(!payloadText.includes("ZGpoaDczaGRqc2o6MA=="));
|
|
532
|
+
return true;
|
|
533
|
+
});
|
|
534
|
+
}));
|
|
535
|
+
it("Create TM", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
536
|
+
fetchStub.returns(tmGraphQlResponseMock("createTm", sampleTm));
|
|
537
|
+
const params = new create_tm_parameters_1.CreateTmParameters()
|
|
538
|
+
.setName("Integration test TM")
|
|
539
|
+
.setDescription("Created by the SDK test suite")
|
|
540
|
+
.setSourceLocaleId("en-US")
|
|
541
|
+
.setTranslationQuality(translation_quality_type_1.TranslationQualityType.TRANSLATION);
|
|
542
|
+
const result = yield translationMemoryApi.createTm(accountUid, params);
|
|
543
|
+
sinon_1.default.assert.calledOnce(fetchStub);
|
|
544
|
+
assert_1.default.equal(fetchStub.getCall(0).args[0], `https://test.com/tm-graphql-api/v2/accounts/${accountUid}/graphql`);
|
|
545
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
546
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
547
|
+
createTm: {
|
|
548
|
+
name: "Integration test TM",
|
|
549
|
+
description: "Created by the SDK test suite",
|
|
550
|
+
sourceLocaleId: "en-US",
|
|
551
|
+
translationQuality: "TRANSLATION"
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
assert_1.default.ok(sentBody.query.includes("createTm"));
|
|
555
|
+
[
|
|
556
|
+
"tmUid", "name", "description", "sourceLocaleId", "sourceLocale", "localeId",
|
|
557
|
+
"localeDescription", "rtlLanguage", "wordSpacing", "creator", "userUid", "created",
|
|
558
|
+
"lastModifier", "lastModified", "localeSummary", "translationLocaleId",
|
|
559
|
+
"translationLocale", "stringCount", "wordCount", "translationQuality",
|
|
560
|
+
"managedWordsEnabled"
|
|
561
|
+
].forEach((field) => {
|
|
562
|
+
assert_1.default.ok(sentBody.query.includes(field), `query is missing field "${field}"`);
|
|
563
|
+
});
|
|
564
|
+
assert_1.default.ok(result);
|
|
565
|
+
assert_1.default.equal(result.tmUid, "j45v1uvsi3tx");
|
|
566
|
+
assert_1.default.ok(result.created instanceof Date);
|
|
567
|
+
assert_1.default.ok(result.lastModified instanceof Date);
|
|
568
|
+
}));
|
|
569
|
+
it("Create TM: a null result is returned as null, not thrown", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
570
|
+
fetchStub.returns({
|
|
571
|
+
status: 200,
|
|
572
|
+
headers: noRequestIdHeaders,
|
|
573
|
+
text: () => __awaiter(void 0, void 0, void 0, function* () { return JSON.stringify({ data: { createTm: null } }); })
|
|
574
|
+
});
|
|
575
|
+
const result = yield translationMemoryApi.createTm(accountUid, new create_tm_parameters_1.CreateTmParameters());
|
|
576
|
+
assert_1.default.equal(result, null);
|
|
577
|
+
}));
|
|
578
|
+
it("Update TM", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
579
|
+
fetchStub.returns(tmGraphQlResponseMock("updateTm", sampleTm));
|
|
580
|
+
const params = new update_tm_parameters_1.UpdateTmParameters()
|
|
581
|
+
.setTmUid("j45v1uvsi3tx")
|
|
582
|
+
.setName("Renamed TM")
|
|
583
|
+
.setDescription("Updated description");
|
|
584
|
+
const result = yield translationMemoryApi.updateTm(accountUid, params);
|
|
585
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
586
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
587
|
+
updateTm: {
|
|
588
|
+
tmUid: "j45v1uvsi3tx",
|
|
589
|
+
name: "Renamed TM",
|
|
590
|
+
description: "Updated description"
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
assert_1.default.ok(result);
|
|
594
|
+
assert_1.default.equal(result.tmUid, "j45v1uvsi3tx");
|
|
595
|
+
}));
|
|
596
|
+
it("Delete TM", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
597
|
+
fetchStub.returns(tmGraphQlResponseMock("deleteTm", sampleTm));
|
|
598
|
+
const result = yield translationMemoryApi.deleteTm(accountUid, "j45v1uvsi3tx");
|
|
599
|
+
const sentBody = JSON.parse(fetchStub.getCall(0).args[1].body);
|
|
600
|
+
assert_1.default.deepEqual(sentBody.variables, {
|
|
601
|
+
deleteTm: { tmUid: "j45v1uvsi3tx" }
|
|
602
|
+
});
|
|
603
|
+
assert_1.default.ok(result);
|
|
604
|
+
assert_1.default.equal(result.tmUid, "j45v1uvsi3tx");
|
|
605
|
+
}));
|
|
606
|
+
it("Create string search: exercises every CreateStringSearchFilterParameters setter", () => {
|
|
607
|
+
const translationDateRangeStart = new Date("2026-01-01T00:00:00Z");
|
|
608
|
+
const translationDateRangeEnd = new Date("2026-02-01T00:00:00Z");
|
|
609
|
+
const editDateRangeStart = new Date("2026-01-02T00:00:00Z");
|
|
610
|
+
const editDateRangeEnd = new Date("2026-02-02T00:00:00Z");
|
|
611
|
+
const reviewDateRangeStart = new Date("2026-01-03T00:00:00Z");
|
|
612
|
+
const reviewDateRangeEnd = new Date("2026-02-03T00:00:00Z");
|
|
613
|
+
const authorizationDateRangeStart = new Date("2026-01-04T00:00:00Z");
|
|
614
|
+
const authorizationDateRangeEnd = new Date("2026-02-04T00:00:00Z");
|
|
615
|
+
const ingestedDateRangeStart = new Date("2026-01-05T00:00:00Z");
|
|
616
|
+
const ingestedDateRangeEnd = new Date("2026-02-05T00:00:00Z");
|
|
617
|
+
const lastTranslatedAfter = new Date("2026-01-06T00:00:00Z");
|
|
618
|
+
const lastTranslatedBefore = new Date("2026-02-06T00:00:00Z");
|
|
619
|
+
const firstTranslatedAfter = new Date("2026-01-07T00:00:00Z");
|
|
620
|
+
const firstTranslatedBefore = new Date("2026-02-07T00:00:00Z");
|
|
621
|
+
const keyword = { searchText: "year", caseSensitive: true, entireStringMatch: false, searchType: keyword_search_type_1.KeywordSearchType.BASIC };
|
|
622
|
+
const sourceKeyword = { searchText: "src", searchType: keyword_search_type_1.KeywordSearchType.EXACT_MATCH };
|
|
623
|
+
const translationKeyword = { searchText: "tgt", searchType: keyword_search_type_1.KeywordSearchType.REGEX };
|
|
624
|
+
const tags = { tags: ["tag1"], matchAllTags: true, noTags: false };
|
|
625
|
+
const searchOptions = {
|
|
626
|
+
highlightMatches: false,
|
|
627
|
+
searchDuplicates: true,
|
|
628
|
+
translationEqSource: false,
|
|
629
|
+
requestedResultsCount: 500
|
|
630
|
+
};
|
|
631
|
+
const filter = new create_string_search_filter_parameters_1.CreateStringSearchFilterParameters()
|
|
632
|
+
.setTmUids(["tm1"])
|
|
633
|
+
.setSourceLocaleIds(["en-US"])
|
|
634
|
+
.setTranslationLocaleIds(["fr-FR"])
|
|
635
|
+
.setKeyword(keyword)
|
|
636
|
+
.setSourceKeyword(sourceKeyword)
|
|
637
|
+
.setTranslationKeyword(translationKeyword)
|
|
638
|
+
.setLeverageType(leverage_type_1.LeverageType.PUBLISHED)
|
|
639
|
+
.setHashcodes(["hash1"])
|
|
640
|
+
.setSmtHashcodes(["smt1"])
|
|
641
|
+
.setTranslatorUids(["translator1"])
|
|
642
|
+
.setTranslationDateRange(translationDateRangeStart, translationDateRangeEnd)
|
|
643
|
+
.setEditorUids(["editor1"])
|
|
644
|
+
.setEditDateRange(editDateRangeStart, editDateRangeEnd)
|
|
645
|
+
.setReviewerUids(["reviewer1"])
|
|
646
|
+
.setReviewDateRange(reviewDateRangeStart, reviewDateRangeEnd)
|
|
647
|
+
.setAuthorizerUids(["authorizer1"])
|
|
648
|
+
.setAuthorizationDateRange(authorizationDateRangeStart, authorizationDateRangeEnd)
|
|
649
|
+
.setIngestedDateRange(ingestedDateRangeStart, ingestedDateRangeEnd)
|
|
650
|
+
.setVariants(["variant1"])
|
|
651
|
+
.setProjectUids(["project1"])
|
|
652
|
+
.setExternalStep(true)
|
|
653
|
+
.setUrls(["https://example.com"])
|
|
654
|
+
.setFileNames(["file1.xml"])
|
|
655
|
+
.setKeys(["key1"])
|
|
656
|
+
.setDomains(["domain1"])
|
|
657
|
+
.setTmxFileNames(["tmx1.tmx"])
|
|
658
|
+
.setSources([source_type_1.SourceType.TMX])
|
|
659
|
+
.setTranslationQualities([tu_translation_quality_type_1.TuTranslationQualityType.HUMAN])
|
|
660
|
+
.setFirstTranslatorUids(["firstTranslator1"])
|
|
661
|
+
.setLastTranslatedRange(lastTranslatedAfter, lastTranslatedBefore)
|
|
662
|
+
.setFirstTranslatedRange(firstTranslatedAfter, firstTranslatedBefore)
|
|
663
|
+
.setTags(tags)
|
|
664
|
+
.setOfflineReportUids(["offlineReport1"])
|
|
665
|
+
.setSearchOptions(searchOptions);
|
|
666
|
+
assert_1.default.deepEqual(filter.export(), {
|
|
667
|
+
tmUids: ["tm1"],
|
|
668
|
+
sourceLocaleIds: ["en-US"],
|
|
669
|
+
translationLocaleIds: ["fr-FR"],
|
|
670
|
+
keyword,
|
|
671
|
+
sourceKeyword,
|
|
672
|
+
translationKeyword,
|
|
673
|
+
leverageType: "PUBLISHED",
|
|
674
|
+
hashcodes: ["hash1"],
|
|
675
|
+
smtHashcodes: ["smt1"],
|
|
676
|
+
translatorUids: ["translator1"],
|
|
677
|
+
translationDateRangeStart,
|
|
678
|
+
translationDateRangeEnd,
|
|
679
|
+
editorUids: ["editor1"],
|
|
680
|
+
editDateRangeStart,
|
|
681
|
+
editDateRangeEnd,
|
|
682
|
+
reviewerUids: ["reviewer1"],
|
|
683
|
+
reviewDateRangeStart,
|
|
684
|
+
reviewDateRangeEnd,
|
|
685
|
+
authorizerUids: ["authorizer1"],
|
|
686
|
+
authorizationDateRangeStart,
|
|
687
|
+
authorizationDateRangeEnd,
|
|
688
|
+
ingestedDateRangeStart,
|
|
689
|
+
ingestedDateRangeEnd,
|
|
690
|
+
variants: ["variant1"],
|
|
691
|
+
projectUids: ["project1"],
|
|
692
|
+
externalStep: true,
|
|
693
|
+
urls: ["https://example.com"],
|
|
694
|
+
fileNames: ["file1.xml"],
|
|
695
|
+
keys: ["key1"],
|
|
696
|
+
domains: ["domain1"],
|
|
697
|
+
tmxFileNames: ["tmx1.tmx"],
|
|
698
|
+
sources: ["TMX"],
|
|
699
|
+
translationQualities: ["HUMAN"],
|
|
700
|
+
firstTranslatorUids: ["firstTranslator1"],
|
|
701
|
+
lastTranslatedAfter,
|
|
702
|
+
lastTranslatedBefore,
|
|
703
|
+
firstTranslatedAfter,
|
|
704
|
+
firstTranslatedBefore,
|
|
705
|
+
tags,
|
|
706
|
+
offlineReportUids: ["offlineReport1"],
|
|
707
|
+
searchOptions
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
//# sourceMappingURL=translation-memory.spec.js.map
|