translations.spec.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. describe("Translations", function () {
  6. const cassette = new Cassettes("./test/cassettes");
  7. const lokaliseApi = new LokaliseApi({ apiKey: process.env.API_KEY });
  8. const project_id = "803826145ba90b42d5d860.46800099";
  9. const translation_id = 79607647;
  10. cassette
  11. .createTest("list", async () => {
  12. const translations = await lokaliseApi.translations().list({
  13. project_id: project_id,
  14. });
  15. expect(translations.items[0].translation_id).to.eq(translation_id);
  16. })
  17. .register(this);
  18. cassette
  19. .createTest("list_pagination", async () => {
  20. const translations = await lokaliseApi.translations().list({
  21. project_id: project_id,
  22. page: 2,
  23. limit: 1,
  24. });
  25. expect(translations.items[0].translation_id).to.eq(80015148);
  26. expect(translations.totalResults).to.eq(240);
  27. expect(translations.totalPages).to.eq(240);
  28. expect(translations.resultsPerPage).to.eq(1);
  29. expect(translations.currentPage).to.eq(2);
  30. })
  31. .register(this);
  32. cassette
  33. .createTest("list with opts", async () => {
  34. const translations = await lokaliseApi.translations().list({
  35. project_id: project_id,
  36. filter_is_reviewed: 0,
  37. filter_lang_id: 803,
  38. });
  39. expect(translations.items[0].translation_id).to.eq(304581213);
  40. expect(translations.items[0].language_iso).to.eq("sq");
  41. })
  42. .register(this);
  43. cassette
  44. .createTest("get", async () => {
  45. const translation = await lokaliseApi.translations().get(304581218, {
  46. project_id: project_id,
  47. });
  48. expect(translation.translation_id).to.eq(304581218);
  49. expect(translation.key_id).to.eq(44596059);
  50. expect(translation.language_iso).to.eq("ru");
  51. expect(translation.translation).to.eq("Сообщение");
  52. expect(translation.modified_by).to.eq(20181);
  53. expect(translation.modified_by_email).to.eq("bodrovis@protonmail.com");
  54. expect(translation.modified_at).to.eq("2020-05-15 10:44:42 (Etc/UTC)");
  55. expect(translation.modified_at_timestamp).to.eq(1589539482);
  56. expect(translation.is_reviewed).to.be.false;
  57. expect(translation.reviewed_by).to.eq(0);
  58. expect(translation.is_unverified).to.be.false;
  59. expect(translation.words).to.eq(1);
  60. expect(translation.custom_translation_statuses).to.have.lengthOf(0);
  61. expect(translation.task_id).to.eq(null);
  62. })
  63. .register(this);
  64. cassette
  65. .createTest("update", async () => {
  66. const translation = await lokaliseApi
  67. .translations()
  68. .update(
  69. translation_id,
  70. { translation: "тест" },
  71. { project_id: project_id }
  72. );
  73. expect(translation.translation_id).to.eq(translation_id);
  74. expect(translation.translation).to.eq("тест");
  75. })
  76. .register(this);
  77. });