smartling-api-sdk-nodejs 3.2.3 → 3.3.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.
Files changed (144) hide show
  1. package/.env.example +13 -0
  2. package/api/base/base-api.ts +2 -1
  3. package/api/glossaries/dto/custom-field-value-dto.ts +6 -0
  4. package/api/glossaries/dto/entry-request-translation-status-dto.ts +7 -0
  5. package/api/glossaries/dto/glossary-entries-count-dto.ts +5 -0
  6. package/api/glossaries/dto/glossary-entry-dto.ts +23 -0
  7. package/api/glossaries/dto/glossary-import-result-dto.ts +11 -0
  8. package/api/glossaries/dto/glossary-import-status-dto.ts +7 -0
  9. package/api/glossaries/dto/glossary-uids-dto.ts +3 -0
  10. package/api/glossaries/dto/import-entry-changes-dto.ts +6 -0
  11. package/api/glossaries/dto/import-entry-translation-changes-dto.ts +6 -0
  12. package/api/glossaries/dto/import-warning-dto.ts +4 -0
  13. package/api/glossaries/dto/label-dto.ts +4 -0
  14. package/api/glossaries/dto/locale-workflow-dto.ts +4 -0
  15. package/api/glossaries/dto/operation-dto.ts +3 -0
  16. package/api/glossaries/dto/translation-dto.ts +20 -0
  17. package/api/glossaries/dto/translation-request-status-dto.ts +5 -0
  18. package/api/glossaries/enums/import-file-media-type.ts +5 -0
  19. package/api/glossaries/enums/import-status.ts +6 -0
  20. package/api/glossaries/enums/index.ts +4 -0
  21. package/api/glossaries/enums/part-of-speech.ts +11 -0
  22. package/api/glossaries/enums/suggestion-status.ts +5 -0
  23. package/api/glossaries/index.ts +281 -0
  24. package/api/glossaries/params/archive-glossaries-parameters.ts +9 -0
  25. package/api/glossaries/params/authorize-entries-parameters.ts +37 -0
  26. package/api/glossaries/params/create-glossary-entry-parameters.ts +50 -0
  27. package/api/glossaries/params/create-glossary-parameters.ts +40 -0
  28. package/api/glossaries/params/create-label-parameters.ts +9 -0
  29. package/api/glossaries/params/entries-bulk-action-parameters.ts +149 -0
  30. package/api/glossaries/params/entries-bulk-labels-parameters.ts +123 -0
  31. package/api/glossaries/params/export-entries-parameters.ts +16 -48
  32. package/api/glossaries/params/initialize-import-parameters.ts +42 -0
  33. package/api/glossaries/params/search-glossary-counts-parameters.ts +41 -0
  34. package/api/glossaries/params/search-glossary-entries-parameters.ts +105 -0
  35. package/built/api/base/base-api.js +2 -1
  36. package/built/api/base/base-api.js.map +1 -1
  37. package/built/api/glossaries/dto/custom-field-value-dto.d.ts +6 -0
  38. package/built/api/glossaries/dto/custom-field-value-dto.js +3 -0
  39. package/built/api/glossaries/dto/custom-field-value-dto.js.map +1 -0
  40. package/built/api/glossaries/dto/entry-request-translation-status-dto.d.ts +6 -0
  41. package/built/api/glossaries/dto/entry-request-translation-status-dto.js +3 -0
  42. package/built/api/glossaries/dto/entry-request-translation-status-dto.js.map +1 -0
  43. package/built/api/glossaries/dto/glossary-entries-count-dto.d.ts +5 -0
  44. package/built/api/glossaries/dto/glossary-entries-count-dto.js +3 -0
  45. package/built/api/glossaries/dto/glossary-entries-count-dto.js.map +1 -0
  46. package/built/api/glossaries/dto/glossary-entry-dto.d.ts +22 -0
  47. package/built/api/glossaries/dto/glossary-entry-dto.js +3 -0
  48. package/built/api/glossaries/dto/glossary-entry-dto.js.map +1 -0
  49. package/built/api/glossaries/dto/glossary-import-result-dto.d.ts +10 -0
  50. package/built/api/glossaries/dto/glossary-import-result-dto.js +3 -0
  51. package/built/api/glossaries/dto/glossary-import-result-dto.js.map +1 -0
  52. package/built/api/glossaries/dto/glossary-import-status-dto.d.ts +6 -0
  53. package/built/api/glossaries/dto/glossary-import-status-dto.js +3 -0
  54. package/built/api/glossaries/dto/glossary-import-status-dto.js.map +1 -0
  55. package/built/api/glossaries/dto/glossary-uids-dto.d.ts +3 -0
  56. package/built/api/glossaries/dto/glossary-uids-dto.js +3 -0
  57. package/built/api/glossaries/dto/glossary-uids-dto.js.map +1 -0
  58. package/built/api/glossaries/dto/import-entry-changes-dto.d.ts +6 -0
  59. package/built/api/glossaries/dto/import-entry-changes-dto.js +3 -0
  60. package/built/api/glossaries/dto/import-entry-changes-dto.js.map +1 -0
  61. package/built/api/glossaries/dto/import-entry-translation-changes-dto.d.ts +6 -0
  62. package/built/api/glossaries/dto/import-entry-translation-changes-dto.js +3 -0
  63. package/built/api/glossaries/dto/import-entry-translation-changes-dto.js.map +1 -0
  64. package/built/api/glossaries/dto/import-warning-dto.d.ts +4 -0
  65. package/built/api/glossaries/dto/import-warning-dto.js +3 -0
  66. package/built/api/glossaries/dto/import-warning-dto.js.map +1 -0
  67. package/built/api/glossaries/dto/label-dto.d.ts +4 -0
  68. package/built/api/glossaries/dto/label-dto.js +3 -0
  69. package/built/api/glossaries/dto/label-dto.js.map +1 -0
  70. package/built/api/glossaries/dto/locale-workflow-dto.d.ts +4 -0
  71. package/built/api/glossaries/dto/locale-workflow-dto.js +3 -0
  72. package/built/api/glossaries/dto/locale-workflow-dto.js.map +1 -0
  73. package/built/api/glossaries/dto/operation-dto.d.ts +3 -0
  74. package/built/api/glossaries/dto/operation-dto.js +3 -0
  75. package/built/api/glossaries/dto/operation-dto.js.map +1 -0
  76. package/built/api/glossaries/dto/translation-dto.d.ts +19 -0
  77. package/built/api/glossaries/dto/translation-dto.js +3 -0
  78. package/built/api/glossaries/dto/translation-dto.js.map +1 -0
  79. package/built/api/glossaries/dto/translation-request-status-dto.d.ts +5 -0
  80. package/built/api/glossaries/dto/translation-request-status-dto.js +3 -0
  81. package/built/api/glossaries/dto/translation-request-status-dto.js.map +1 -0
  82. package/built/api/glossaries/enums/import-file-media-type.d.ts +5 -0
  83. package/built/api/glossaries/enums/import-file-media-type.js +10 -0
  84. package/built/api/glossaries/enums/import-file-media-type.js.map +1 -0
  85. package/built/api/glossaries/enums/import-status.d.ts +6 -0
  86. package/built/api/glossaries/enums/import-status.js +11 -0
  87. package/built/api/glossaries/enums/import-status.js.map +1 -0
  88. package/built/api/glossaries/enums/index.d.ts +4 -0
  89. package/built/api/glossaries/enums/index.js +9 -1
  90. package/built/api/glossaries/enums/index.js.map +1 -1
  91. package/built/api/glossaries/enums/part-of-speech.d.ts +11 -0
  92. package/built/api/glossaries/enums/part-of-speech.js +16 -0
  93. package/built/api/glossaries/enums/part-of-speech.js.map +1 -0
  94. package/built/api/glossaries/enums/suggestion-status.d.ts +5 -0
  95. package/built/api/glossaries/enums/suggestion-status.js +10 -0
  96. package/built/api/glossaries/enums/suggestion-status.js.map +1 -0
  97. package/built/api/glossaries/index.d.ts +39 -0
  98. package/built/api/glossaries/index.js +127 -0
  99. package/built/api/glossaries/index.js.map +1 -1
  100. package/built/api/glossaries/params/archive-glossaries-parameters.d.ts +4 -0
  101. package/built/api/glossaries/params/archive-glossaries-parameters.js +12 -0
  102. package/built/api/glossaries/params/archive-glossaries-parameters.js.map +1 -0
  103. package/built/api/glossaries/params/authorize-entries-parameters.d.ts +10 -0
  104. package/built/api/glossaries/params/authorize-entries-parameters.js +28 -0
  105. package/built/api/glossaries/params/authorize-entries-parameters.js.map +1 -0
  106. package/built/api/glossaries/params/create-glossary-entry-parameters.d.ts +13 -0
  107. package/built/api/glossaries/params/create-glossary-entry-parameters.js +36 -0
  108. package/built/api/glossaries/params/create-glossary-entry-parameters.js.map +1 -0
  109. package/built/api/glossaries/params/create-glossary-parameters.d.ts +10 -0
  110. package/built/api/glossaries/params/create-glossary-parameters.js +32 -0
  111. package/built/api/glossaries/params/create-glossary-parameters.js.map +1 -0
  112. package/built/api/glossaries/params/create-label-parameters.d.ts +4 -0
  113. package/built/api/glossaries/params/create-label-parameters.js +12 -0
  114. package/built/api/glossaries/params/create-label-parameters.js.map +1 -0
  115. package/built/api/glossaries/params/entries-bulk-action-parameters.d.ts +28 -0
  116. package/built/api/glossaries/params/entries-bulk-action-parameters.js +112 -0
  117. package/built/api/glossaries/params/entries-bulk-action-parameters.js.map +1 -0
  118. package/built/api/glossaries/params/entries-bulk-labels-parameters.d.ts +29 -0
  119. package/built/api/glossaries/params/entries-bulk-labels-parameters.js +84 -0
  120. package/built/api/glossaries/params/entries-bulk-labels-parameters.js.map +1 -0
  121. package/built/api/glossaries/params/export-entries-parameters.js +16 -48
  122. package/built/api/glossaries/params/export-entries-parameters.js.map +1 -1
  123. package/built/api/glossaries/params/initialize-import-parameters.d.ts +12 -0
  124. package/built/api/glossaries/params/initialize-import-parameters.js +60 -0
  125. package/built/api/glossaries/params/initialize-import-parameters.js.map +1 -0
  126. package/built/api/glossaries/params/search-glossary-counts-parameters.d.ts +11 -0
  127. package/built/api/glossaries/params/search-glossary-counts-parameters.js +32 -0
  128. package/built/api/glossaries/params/search-glossary-counts-parameters.js.map +1 -0
  129. package/built/api/glossaries/params/search-glossary-entries-parameters.d.ts +25 -0
  130. package/built/api/glossaries/params/search-glossary-entries-parameters.js +72 -0
  131. package/built/api/glossaries/params/search-glossary-entries-parameters.js.map +1 -0
  132. package/built/index.d.ts +29 -0
  133. package/built/index.js +29 -0
  134. package/built/index.js.map +1 -1
  135. package/built/package.json +5 -3
  136. package/built/test/glossaries.spec.js +404 -0
  137. package/built/test/glossaries.spec.js.map +1 -1
  138. package/built/test/integration/glossaries.spec.d.ts +1 -0
  139. package/built/test/integration/glossaries.spec.js +222 -0
  140. package/built/test/integration/glossaries.spec.js.map +1 -0
  141. package/index.ts +29 -0
  142. package/package.json +5 -3
  143. package/test/glossaries.spec.ts +559 -0
  144. package/test/integration/glossaries.spec.ts +358 -0
@@ -1,10 +1,25 @@
1
1
  import sinon from "sinon";
2
+ import * as fs from "fs";
3
+ import assert from "assert";
2
4
  import { SmartlingGlossariesApi } from "../api/glossaries/index";
3
5
  import { loggerMock, authMock, responseMock } from "./mock";
4
6
  import { SmartlingAuthApi } from "../api/auth/index";
5
7
  import { SearchGlossariesParameters } from "../api/glossaries/params/search-glossaries-parameters";
6
8
  import { ExportEntriesParameters } from "../api/glossaries/params/export-entries-parameters";
7
9
  import { ExportFormat, TbxVersion, EntryState, FilterLevel, SortField, SortDirection, LabelType, DateFilterType } from "../api/glossaries/enums";
10
+ import { CreateGlossaryParameters } from "../api/glossaries/params/create-glossary-parameters";
11
+ import { ArchiveGlossariesParameters } from "../api/glossaries/params/archive-glossaries-parameters";
12
+ import { SearchGlossaryCountsParameters } from "../api/glossaries/params/search-glossary-counts-parameters";
13
+ import { CreateGlossaryEntryParameters } from "../api/glossaries/params/create-glossary-entry-parameters";
14
+ import { SearchGlossaryEntriesParameters } from "../api/glossaries/params/search-glossary-entries-parameters";
15
+ import { PartOfSpeech } from "../api/glossaries/enums/part-of-speech";
16
+ import { EntriesBulkActionParameters } from "../api/glossaries/params/entries-bulk-action-parameters";
17
+ import { EntriesBulkLabelsParameters } from "../api/glossaries/params/entries-bulk-labels-parameters";
18
+ import { AuthorizeEntriesParameters } from "../api/glossaries/params/authorize-entries-parameters";
19
+ import { streamToString } from "./stream-to-string";
20
+ import { InitializeImportParameters } from "../api/glossaries/params/initialize-import-parameters";
21
+ import { ImportFileMediaType } from "../api/glossaries/enums/import-file-media-type";
22
+ import { CreateLabelParameters } from "../api/glossaries/params/create-label-parameters";
8
23
 
9
24
  describe("SmartlingGlossariesApi class tests.", () => {
10
25
  const accountUid = "testAccountUid";
@@ -192,5 +207,549 @@ describe("SmartlingGlossariesApi class tests.", () => {
192
207
  }
193
208
  });
194
209
  });
210
+
211
+ it("Create glossary", async () => {
212
+ const parameters = new CreateGlossaryParameters()
213
+ .setGlossaryName("Test glossary")
214
+ .setDescription("Test description")
215
+ .setVerificationMode(true)
216
+ .setLocaleIds(["en-US", "fr-FR"])
217
+ .setFallbackLocales([{ fallbackLocaleId: "fr-FR", localeIds: ["fr-CA"] }])
218
+ .setMtOptimized(true);
219
+
220
+ await glossariesApi.createGlossary(accountUid, parameters);
221
+
222
+ sinon.assert.calledOnce(glossariesApiFetchStub);
223
+ sinon.assert.calledWithExactly(
224
+ glossariesApiFetchStub,
225
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries`,
226
+ {
227
+ headers: {
228
+ Authorization: "test_token_type test_access_token",
229
+ "Content-Type": "application/json",
230
+ "User-Agent": "test_user_agent"
231
+ },
232
+ method: "post",
233
+ body: JSON.stringify({
234
+ glossaryName: "Test glossary",
235
+ description: "Test description",
236
+ verificationMode: true,
237
+ localeIds: ["en-US", "fr-FR"],
238
+ fallbackLocales: [{ fallbackLocaleId: "fr-FR", localeIds: ["fr-CA"] }],
239
+ mtOptimized: true
240
+ })
241
+ }
242
+ );
243
+ });
244
+
245
+ it("Update glossary", async () => {
246
+ const parameters = new CreateGlossaryParameters()
247
+ .setGlossaryName("Updated glossary")
248
+ .setLocaleIds(["en-US"]);
249
+
250
+ await glossariesApi.updateGlossary(accountUid, glossaryUid, parameters);
251
+
252
+ sinon.assert.calledOnce(glossariesApiFetchStub);
253
+ sinon.assert.calledWithExactly(
254
+ glossariesApiFetchStub,
255
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}`,
256
+ {
257
+ headers: {
258
+ Authorization: "test_token_type test_access_token",
259
+ "Content-Type": "application/json",
260
+ "User-Agent": "test_user_agent"
261
+ },
262
+ method: "put",
263
+ body: JSON.stringify({
264
+ glossaryName: "Updated glossary",
265
+ localeIds: ["en-US"]
266
+ })
267
+ }
268
+ );
269
+ });
270
+
271
+ it("Archive glossaries", async () => {
272
+ const parameters = new ArchiveGlossariesParameters().setGlossaryUids(["uid1", "uid2"]);
273
+
274
+ await glossariesApi.archiveGlossaries(accountUid, parameters);
275
+
276
+ sinon.assert.calledOnce(glossariesApiFetchStub);
277
+ sinon.assert.calledWithExactly(
278
+ glossariesApiFetchStub,
279
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/archive`,
280
+ {
281
+ headers: {
282
+ Authorization: "test_token_type test_access_token",
283
+ "Content-Type": "application/json",
284
+ "User-Agent": "test_user_agent"
285
+ },
286
+ method: "post",
287
+ body: JSON.stringify({ glossaryUids: ["uid1", "uid2"] })
288
+ }
289
+ );
290
+ });
291
+
292
+ it("Restore glossaries", async () => {
293
+ const parameters = new ArchiveGlossariesParameters().setGlossaryUids(["uid1"]);
294
+
295
+ await glossariesApi.restoreGlossaries(accountUid, parameters);
296
+
297
+ sinon.assert.calledOnce(glossariesApiFetchStub);
298
+ sinon.assert.calledWithExactly(
299
+ glossariesApiFetchStub,
300
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/unarchive`,
301
+ {
302
+ headers: {
303
+ Authorization: "test_token_type test_access_token",
304
+ "Content-Type": "application/json",
305
+ "User-Agent": "test_user_agent"
306
+ },
307
+ method: "post",
308
+ body: JSON.stringify({ glossaryUids: ["uid1"] })
309
+ }
310
+ );
311
+ });
312
+
313
+ it("Search glossaries with entries counts", async () => {
314
+ const parameters = new SearchGlossaryCountsParameters()
315
+ .setQuery("test")
316
+ .setGlossaryState("ACTIVE")
317
+ .setPaging({ offset: 0, limit: 10 });
318
+
319
+ await glossariesApi.searchGlossariesWithEntriesCounts(accountUid, parameters);
320
+
321
+ sinon.assert.calledOnce(glossariesApiFetchStub);
322
+ sinon.assert.calledWithExactly(
323
+ glossariesApiFetchStub,
324
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/search/count`,
325
+ {
326
+ headers: {
327
+ Authorization: "test_token_type test_access_token",
328
+ "Content-Type": "application/json",
329
+ "User-Agent": "test_user_agent"
330
+ },
331
+ method: "post",
332
+ body: JSON.stringify({
333
+ query: "test",
334
+ glossaryState: "ACTIVE",
335
+ paging: { offset: 0, limit: 10 }
336
+ })
337
+ }
338
+ );
339
+ });
340
+
341
+ it("Create glossary entry", async () => {
342
+ const parameters = new CreateGlossaryEntryParameters()
343
+ .setDefinition("A test term")
344
+ .setPartOfSpeech(PartOfSpeech.NOUN)
345
+ .setLabelUids(["label1"])
346
+ .setSkipMissingTranslations(false)
347
+ .setSuggestion(true);
348
+
349
+ await glossariesApi.createGlossaryEntry(accountUid, glossaryUid, parameters);
350
+
351
+ sinon.assert.calledOnce(glossariesApiFetchStub);
352
+ sinon.assert.calledWithExactly(
353
+ glossariesApiFetchStub,
354
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries`,
355
+ {
356
+ headers: {
357
+ Authorization: "test_token_type test_access_token",
358
+ "Content-Type": "application/json",
359
+ "User-Agent": "test_user_agent"
360
+ },
361
+ method: "post",
362
+ body: JSON.stringify({
363
+ definition: "A test term",
364
+ partOfSpeech: "NOUN",
365
+ labelUids: ["label1"],
366
+ skipMissingTranslations: false,
367
+ suggestion: true
368
+ })
369
+ }
370
+ );
371
+ });
372
+
373
+ it("Read glossary entry", async () => {
374
+ await glossariesApi.readGlossaryEntry(accountUid, glossaryUid, "testEntryUid");
375
+
376
+ sinon.assert.calledOnce(glossariesApiFetchStub);
377
+ sinon.assert.calledWithExactly(
378
+ glossariesApiFetchStub,
379
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/testEntryUid`,
380
+ {
381
+ headers: {
382
+ Authorization: "test_token_type test_access_token",
383
+ "Content-Type": "application/json",
384
+ "User-Agent": "test_user_agent"
385
+ },
386
+ method: "get"
387
+ }
388
+ );
389
+ });
390
+
391
+ it("Update glossary entry", async () => {
392
+ const parameters = new CreateGlossaryEntryParameters().setDefinition("Updated term");
393
+
394
+ await glossariesApi.updateGlossaryEntry(accountUid, glossaryUid, "testEntryUid", parameters);
395
+
396
+ sinon.assert.calledOnce(glossariesApiFetchStub);
397
+ sinon.assert.calledWithExactly(
398
+ glossariesApiFetchStub,
399
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/testEntryUid`,
400
+ {
401
+ headers: {
402
+ Authorization: "test_token_type test_access_token",
403
+ "Content-Type": "application/json",
404
+ "User-Agent": "test_user_agent"
405
+ },
406
+ method: "put",
407
+ body: JSON.stringify({ definition: "Updated term" })
408
+ }
409
+ );
410
+ });
411
+
412
+ it("Search glossary entries", async () => {
413
+ const parameters = new SearchGlossaryEntriesParameters()
414
+ .setQuery("test")
415
+ .setEntryState(EntryState.ACTIVE)
416
+ .setPaging({ offset: 0, limit: 10 });
417
+
418
+ await glossariesApi.searchGlossaryEntries(accountUid, glossaryUid, parameters);
419
+
420
+ sinon.assert.calledOnce(glossariesApiFetchStub);
421
+ sinon.assert.calledWithExactly(
422
+ glossariesApiFetchStub,
423
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/search`,
424
+ {
425
+ headers: {
426
+ Authorization: "test_token_type test_access_token",
427
+ "Content-Type": "application/json",
428
+ "User-Agent": "test_user_agent"
429
+ },
430
+ method: "post",
431
+ body: JSON.stringify({
432
+ query: "test",
433
+ entryState: "ACTIVE",
434
+ paging: { offset: 0, limit: 10 }
435
+ })
436
+ }
437
+ );
438
+ });
439
+
440
+ it("Archive glossary entries", async () => {
441
+ const parameters = new EntriesBulkActionParameters().setFilterEntryUids(["entry1", "entry2"]);
442
+
443
+ await glossariesApi.archiveGlossaryEntries(accountUid, glossaryUid, parameters);
444
+
445
+ sinon.assert.calledOnce(glossariesApiFetchStub);
446
+ sinon.assert.calledWithExactly(
447
+ glossariesApiFetchStub,
448
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/archive`,
449
+ {
450
+ headers: {
451
+ Authorization: "test_token_type test_access_token",
452
+ "Content-Type": "application/json",
453
+ "User-Agent": "test_user_agent"
454
+ },
455
+ method: "post",
456
+ body: JSON.stringify({ filter: { entryUids: ["entry1", "entry2"] } })
457
+ }
458
+ );
459
+ });
460
+
461
+ it("Restore glossary entries", async () => {
462
+ const parameters = new EntriesBulkActionParameters().setFilterEntryUids(["entry1"]);
463
+
464
+ await glossariesApi.restoreGlossaryEntries(accountUid, glossaryUid, parameters);
465
+
466
+ sinon.assert.calledOnce(glossariesApiFetchStub);
467
+ sinon.assert.calledWithExactly(
468
+ glossariesApiFetchStub,
469
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/unarchive`,
470
+ {
471
+ headers: {
472
+ Authorization: "test_token_type test_access_token",
473
+ "Content-Type": "application/json",
474
+ "User-Agent": "test_user_agent"
475
+ },
476
+ method: "post",
477
+ body: JSON.stringify({ filter: { entryUids: ["entry1"] } })
478
+ }
479
+ );
480
+ });
481
+
482
+ it("Remove glossary entries", async () => {
483
+ const parameters = new EntriesBulkActionParameters().setFilterEntryUids(["entry1"]);
484
+
485
+ await glossariesApi.removeGlossaryEntries(accountUid, glossaryUid, parameters);
486
+
487
+ sinon.assert.calledOnce(glossariesApiFetchStub);
488
+ sinon.assert.calledWithExactly(
489
+ glossariesApiFetchStub,
490
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/delete`,
491
+ {
492
+ headers: {
493
+ Authorization: "test_token_type test_access_token",
494
+ "Content-Type": "application/json",
495
+ "User-Agent": "test_user_agent"
496
+ },
497
+ method: "post",
498
+ body: JSON.stringify({ filter: { entryUids: ["entry1"] } })
499
+ }
500
+ );
501
+ });
502
+
503
+ it("Add labels to glossary entries", async () => {
504
+ const parameters = new EntriesBulkLabelsParameters()
505
+ .setFilterEntryUids(["entry1"])
506
+ .setLabelUids(["label1", "label2"]);
507
+
508
+ await glossariesApi.addLabelsToGlossaryEntries(accountUid, glossaryUid, parameters);
509
+
510
+ sinon.assert.calledOnce(glossariesApiFetchStub);
511
+ sinon.assert.calledWithExactly(
512
+ glossariesApiFetchStub,
513
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/add-labels`,
514
+ {
515
+ headers: {
516
+ Authorization: "test_token_type test_access_token",
517
+ "Content-Type": "application/json",
518
+ "User-Agent": "test_user_agent"
519
+ },
520
+ method: "post",
521
+ body: JSON.stringify({
522
+ filter: { entryUids: ["entry1"] },
523
+ labelUids: ["label1", "label2"]
524
+ })
525
+ }
526
+ );
527
+ });
528
+
529
+ it("Remove labels from glossary entries", async () => {
530
+ const parameters = new EntriesBulkLabelsParameters()
531
+ .setFilterEntryUids(["entry1"])
532
+ .setLabelUids(["label1"]);
533
+
534
+ await glossariesApi.removeLabelsFromGlossaryEntries(
535
+ accountUid,
536
+ glossaryUid,
537
+ parameters
538
+ );
539
+
540
+ sinon.assert.calledOnce(glossariesApiFetchStub);
541
+ sinon.assert.calledWithExactly(
542
+ glossariesApiFetchStub,
543
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/remove-labels`,
544
+ {
545
+ headers: {
546
+ Authorization: "test_token_type test_access_token",
547
+ "Content-Type": "application/json",
548
+ "User-Agent": "test_user_agent"
549
+ },
550
+ method: "post",
551
+ body: JSON.stringify({
552
+ filter: { entryUids: ["entry1"] },
553
+ labelUids: ["label1"]
554
+ })
555
+ }
556
+ );
557
+ });
558
+
559
+ it("Authorize glossary entries for translation", async () => {
560
+ const parameters = new AuthorizeEntriesParameters()
561
+ .setSourceLocale("en-US")
562
+ .setProjectId("testProjectId")
563
+ .setFilter({ entryUids: ["entry1"] })
564
+ .setLocaleWorkflows([{ localeId: "fr-FR", workflowUid: "workflow1" }])
565
+ .setMissingTranslationsOnly(true);
566
+
567
+ await glossariesApi.authorizeEntriesForTranslation(accountUid, glossaryUid, parameters);
568
+
569
+ sinon.assert.calledOnce(glossariesApiFetchStub);
570
+ sinon.assert.calledWithExactly(
571
+ glossariesApiFetchStub,
572
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/entries/authorization`,
573
+ {
574
+ headers: {
575
+ Authorization: "test_token_type test_access_token",
576
+ "Content-Type": "application/json",
577
+ "User-Agent": "test_user_agent"
578
+ },
579
+ method: "post",
580
+ body: JSON.stringify({
581
+ sourceLocale: "en-US",
582
+ projectId: "testProjectId",
583
+ filter: { entryUids: ["entry1"] },
584
+ localeWorkflows: [{ localeId: "fr-FR", workflowUid: "workflow1" }],
585
+ missingTranslationsOnly: true
586
+ })
587
+ }
588
+ );
589
+ });
590
+
591
+ it("Initialize glossary import", async () => {
592
+ const parameters = new InitializeImportParameters()
593
+ .setImportFileContent(fs.readFileSync(
594
+ fs.realpathSync("./test/data/file.xml"),
595
+ "utf8"
596
+ ))
597
+ .setImportFileName("terms.csv")
598
+ .setImportFileMediaType(ImportFileMediaType.CSV)
599
+ .setArchiveMode(false);
600
+
601
+ await glossariesApi.initializeGlossaryImport(accountUid, glossaryUid, parameters);
602
+
603
+ sinon.assert.calledOnce(glossariesApiFetchStub);
604
+
605
+ assert.equal(
606
+ glossariesApiFetchStub.getCall(0).args[0],
607
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/import`
608
+ );
609
+
610
+ assert.equal(
611
+ glossariesApiFetchStub.getCall(0).args[1].method,
612
+ "post"
613
+ );
614
+
615
+ assert.equal(
616
+ glossariesApiFetchStub.getCall(0).args[1].headers.Authorization,
617
+ "test_token_type test_access_token"
618
+ );
619
+
620
+ assert.equal(
621
+ glossariesApiFetchStub.getCall(0).args[1].headers["User-Agent"],
622
+ "test_user_agent"
623
+ );
624
+
625
+ assert.equal(
626
+ // eslint-disable-next-line no-underscore-dangle
627
+ await streamToString(glossariesApiFetchStub.getCall(0).args[1].body._streams[1]),
628
+ fs.readFileSync(
629
+ fs.realpathSync("./test/data/file.xml"),
630
+ "utf8"
631
+ )
632
+ );
633
+
634
+ const stringified = JSON.stringify(glossariesApiFetchStub.getCall(0).args[1].body);
635
+
636
+ assert.ok(stringified.includes("Content-Disposition: form-data; name=\\\"importFileName\\\"\\r\\n\\r\\n\",\"terms.csv\""));
637
+ assert.ok(stringified.includes("Content-Disposition: form-data; name=\\\"importFileMediaType\\\"\\r\\n\\r\\n\",\"text/csv\""));
638
+ assert.ok(stringified.includes("Content-Disposition: form-data; name=\\\"archiveMode\\\"\\r\\n\\r\\n\",false"));
639
+ });
640
+
641
+ it("Get glossary import status", async () => {
642
+ await glossariesApi.importStatus(accountUid, glossaryUid, "testImportUid");
643
+
644
+ sinon.assert.calledOnce(glossariesApiFetchStub);
645
+ sinon.assert.calledWithExactly(
646
+ glossariesApiFetchStub,
647
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/import/testImportUid`,
648
+ {
649
+ headers: {
650
+ Authorization: "test_token_type test_access_token",
651
+ "Content-Type": "application/json",
652
+ "User-Agent": "test_user_agent"
653
+ },
654
+ method: "get"
655
+ }
656
+ );
657
+ });
658
+
659
+ it("Confirm glossary import", async () => {
660
+ await glossariesApi.confirmGlossaryImport(accountUid, glossaryUid, "testImportUid");
661
+
662
+ sinon.assert.calledOnce(glossariesApiFetchStub);
663
+ sinon.assert.calledWithExactly(
664
+ glossariesApiFetchStub,
665
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/glossaries/${glossaryUid}/import/testImportUid/confirm`,
666
+ {
667
+ headers: {
668
+ Authorization: "test_token_type test_access_token",
669
+ "Content-Type": "application/json",
670
+ "User-Agent": "test_user_agent"
671
+ },
672
+ method: "post"
673
+ }
674
+ );
675
+ });
676
+
677
+ it("Read all glossary labels", async () => {
678
+ await glossariesApi.readAllGlossaryLabels(accountUid);
679
+
680
+ sinon.assert.calledOnce(glossariesApiFetchStub);
681
+ sinon.assert.calledWithExactly(
682
+ glossariesApiFetchStub,
683
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/labels`,
684
+ {
685
+ headers: {
686
+ Authorization: "test_token_type test_access_token",
687
+ "Content-Type": "application/json",
688
+ "User-Agent": "test_user_agent"
689
+ },
690
+ method: "get"
691
+ }
692
+ );
693
+ });
694
+
695
+ it("Create glossary label", async () => {
696
+ const parameters = new CreateLabelParameters().setLabelText("Important");
697
+
698
+ await glossariesApi.createGlossaryLabel(accountUid, parameters);
699
+
700
+ sinon.assert.calledOnce(glossariesApiFetchStub);
701
+ sinon.assert.calledWithExactly(
702
+ glossariesApiFetchStub,
703
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/labels`,
704
+ {
705
+ headers: {
706
+ Authorization: "test_token_type test_access_token",
707
+ "Content-Type": "application/json",
708
+ "User-Agent": "test_user_agent"
709
+ },
710
+ method: "post",
711
+ body: JSON.stringify({ labelText: "Important" })
712
+ }
713
+ );
714
+ });
715
+
716
+ it("Update glossary label", async () => {
717
+ const parameters = new CreateLabelParameters().setLabelText("Renamed");
718
+
719
+ await glossariesApi.updateGlossaryLabel(accountUid, "testLabelUid", parameters);
720
+
721
+ sinon.assert.calledOnce(glossariesApiFetchStub);
722
+ sinon.assert.calledWithExactly(
723
+ glossariesApiFetchStub,
724
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/labels/testLabelUid`,
725
+ {
726
+ headers: {
727
+ Authorization: "test_token_type test_access_token",
728
+ "Content-Type": "application/json",
729
+ "User-Agent": "test_user_agent"
730
+ },
731
+ method: "put",
732
+ body: JSON.stringify({ labelText: "Renamed" })
733
+ }
734
+ );
735
+ });
736
+
737
+ it("Delete glossary label", async () => {
738
+ await glossariesApi.deleteGlossaryLabel(accountUid, "testLabelUid");
739
+
740
+ sinon.assert.calledOnce(glossariesApiFetchStub);
741
+ sinon.assert.calledWithExactly(
742
+ glossariesApiFetchStub,
743
+ `https://test.com/glossary-api/v3/accounts/${accountUid}/labels/testLabelUid`,
744
+ {
745
+ headers: {
746
+ Authorization: "test_token_type test_access_token",
747
+ "Content-Type": "application/json",
748
+ "User-Agent": "test_user_agent"
749
+ },
750
+ method: "delete"
751
+ }
752
+ );
753
+ });
195
754
  });
196
755
  });