tasks.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. describe("Tasks", 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 task_id = 11925;
  10. const new_task_id = 15526;
  11. cassette
  12. .createTest("list", async () => {
  13. const tasks = await lokaliseApi.tasks().list({ project_id: project_id });
  14. expect(tasks.items[0].task_id).to.eq(task_id);
  15. })
  16. .register(this);
  17. cassette
  18. .createTest("list_pagination", async () => {
  19. const tasks = await lokaliseApi.tasks().list({
  20. project_id: project_id,
  21. page: 2,
  22. limit: 1,
  23. });
  24. expect(tasks.items[0].task_id).to.eq(10001);
  25. expect(tasks.totalResults).to.eq(3);
  26. expect(tasks.totalPages).to.eq(3);
  27. expect(tasks.resultsPerPage).to.eq(1);
  28. expect(tasks.currentPage).to.eq(2);
  29. })
  30. .register(this);
  31. cassette
  32. .createTest("get", async () => {
  33. const task = await lokaliseApi.tasks().get(task_id, {
  34. project_id: project_id,
  35. });
  36. expect(task.task_id).to.eq(task_id);
  37. expect(task.title).to.eq("node updated");
  38. expect(task.can_be_parent).be.false;
  39. expect(task.task_type).to.eq("review");
  40. expect(task.parent_task_id).to.be.null;
  41. expect(task.closing_tags).to.have.lengthOf(0);
  42. expect(task.description).to.eq("");
  43. expect(task.status).to.eq("completed");
  44. expect(task.progress).to.eq(0);
  45. expect(task.due_date).to.be.null;
  46. expect(task.due_date_timestamp).to.be.null;
  47. expect(task.keys_count).to.eq(16);
  48. expect(task.words_count).to.eq(275);
  49. expect(task.created_at).to.eq("2019-05-13 16:15:26 (Etc/UTC)");
  50. expect(task.created_at_timestamp).to.eq(1557764126);
  51. expect(task.created_by).to.eq(20181);
  52. expect(task.created_by_email).to.eq("bodrovis@protonmail.com");
  53. expect(task.source_language_iso).to.eq("en");
  54. expect(task.languages[0].language_iso).to.eq("sq");
  55. expect(task.auto_close_languages).to.be.true;
  56. expect(task.auto_close_task).to.be.true;
  57. expect(task.auto_close_items).to.be.true;
  58. expect(task.completed_at).to.eq("2019-10-01 11:09:12 (Etc/UTC)");
  59. expect(task.completed_at_timestamp).to.eq(1569928152);
  60. expect(task.completed_by).to.eq(20181);
  61. expect(task.completed_by_email).to.eq("bodrovis@protonmail.com");
  62. expect(task.do_lock_translations).to.be.false;
  63. expect(task.custom_translation_status_ids).to.have.lengthOf(0);
  64. })
  65. .register(this);
  66. cassette
  67. .createTest("create", async () => {
  68. const task = await lokaliseApi.tasks().create(
  69. {
  70. title: "node task",
  71. keys: [15519786],
  72. languages: [
  73. {
  74. language_iso: "en",
  75. users: [20181],
  76. },
  77. ],
  78. },
  79. { project_id: project_id }
  80. );
  81. expect(task.task_id).to.eq(new_task_id);
  82. expect(task.title).to.eq("node task");
  83. expect(task.languages[0].language_iso).to.eq("en");
  84. })
  85. .register(this);
  86. cassette
  87. .createTest("update", async () => {
  88. const task = await lokaliseApi
  89. .tasks()
  90. .update(task_id, { title: "node updated" }, { project_id: project_id });
  91. expect(task.title).to.eq("node updated");
  92. })
  93. .register(this);
  94. cassette
  95. .createTest("delete", async () => {
  96. const response = await lokaliseApi.tasks().delete(new_task_id, {
  97. project_id: project_id,
  98. });
  99. expect(response.project_id).to.eq(project_id);
  100. expect(response.task_deleted).to.be.true;
  101. })
  102. .register(this);
  103. });