contributors.spec.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. describe("Contributors", 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 user_id = 20181;
  10. const new_user_id = 39938;
  11. cassette
  12. .createTest("list", async () => {
  13. const contributors = await lokaliseApi.contributors().list({
  14. project_id: project_id,
  15. });
  16. expect(contributors.items[0].user_id).to.eq(user_id);
  17. })
  18. .register(this);
  19. cassette
  20. .createTest("list_pagination", async () => {
  21. const contributors = await lokaliseApi.contributors().list({
  22. project_id: project_id,
  23. page: 2,
  24. limit: 3,
  25. });
  26. expect(contributors.items[0].user_id).to.eq(33599);
  27. expect(contributors.totalResults).to.eq(8);
  28. expect(contributors.totalPages).to.eq(3);
  29. expect(contributors.resultsPerPage).to.eq(3);
  30. expect(contributors.currentPage).to.eq(2);
  31. expect(contributors.isFirstPage()).to.be.false;
  32. expect(contributors.isLastPage()).to.be.false;
  33. expect(contributors.nextPage()).to.eq(3);
  34. expect(contributors.prevPage()).to.eq(1);
  35. })
  36. .register(this);
  37. cassette
  38. .createTest("get", async () => {
  39. const contributor = await lokaliseApi.contributors().get(user_id, {
  40. project_id: project_id,
  41. });
  42. expect(contributor.user_id).to.eq(user_id);
  43. expect(contributor.email).to.eq("bodrovis@protonmail.com");
  44. expect(contributor.fullname).to.eq("Ilya B");
  45. expect(contributor.created_at).to.eq("2018-08-21 15:35:25 (Etc/UTC)");
  46. expect(contributor.created_at_timestamp).to.eq(1534865725);
  47. expect(contributor.is_admin).to.be.true;
  48. expect(contributor.is_reviewer).to.be.true;
  49. expect(contributor.languages[0].lang_id).to.eq(803);
  50. expect(contributor.languages[0].lang_iso).to.eq("sq");
  51. expect(contributor.admin_rights).to.include("upload");
  52. })
  53. .register(this);
  54. cassette
  55. .createTest("create", async () => {
  56. const contributors = await lokaliseApi.contributors().create(
  57. [
  58. {
  59. email: "translator2@mycompany.com",
  60. fullname: "Mr. Translator",
  61. is_admin: false,
  62. is_reviewer: true,
  63. languages: [
  64. {
  65. lang_iso: "en",
  66. is_writable: false,
  67. },
  68. {
  69. lang_iso: "ru",
  70. is_writable: true,
  71. },
  72. ],
  73. },
  74. ],
  75. { project_id: project_id }
  76. );
  77. expect(contributors[0].email).to.eq("translator2@mycompany.com");
  78. expect(contributors[0].user_id).to.eq(new_user_id);
  79. })
  80. .register(this);
  81. cassette
  82. .createTest("create_single", async () => {
  83. const contributors = await lokaliseApi.contributors().create(
  84. {
  85. email: "translator3@mycompany.com",
  86. fullname: "Mr. Translator Single",
  87. is_admin: false,
  88. is_reviewer: true,
  89. languages: [
  90. {
  91. lang_iso: "en",
  92. is_writable: false,
  93. },
  94. ],
  95. },
  96. { project_id: project_id }
  97. );
  98. expect(contributors[0].email).to.eq("translator3@mycompany.com");
  99. })
  100. .register(this);
  101. cassette
  102. .createTest("update", async () => {
  103. const contributor = await lokaliseApi
  104. .contributors()
  105. .update(new_user_id, { is_admin: true }, { project_id: project_id });
  106. expect(contributor.user_id).to.eq(new_user_id);
  107. expect(contributor.is_admin).to.be.true;
  108. })
  109. .register(this);
  110. cassette
  111. .createTest("delete", async () => {
  112. const response = await lokaliseApi.contributors().delete(new_user_id, {
  113. project_id: project_id,
  114. });
  115. expect(response.project_id).to.eq(project_id);
  116. expect(response.contributor_deleted).to.be.true;
  117. })
  118. .register(this);
  119. });