branches.spec.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { ApiError } from "../../src/main";
  2. require("../setup");
  3. import { expect } from "chai";
  4. import { Cassettes } from "mocha-cassettes";
  5. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  6. describe("Branches", function () {
  7. const cassette = new Cassettes("./test/cassettes");
  8. const lokaliseApi = new LokaliseApi({ apiKey: process.env.API_KEY });
  9. const project_id = "803826145ba90b42d5d860.46800099";
  10. const branch_id = 41284;
  11. cassette
  12. .createTest("error", async () => {
  13. await lokaliseApi
  14. .branches()
  15. .create(
  16. {
  17. name: "hotfix/really-important",
  18. },
  19. { project_id: "803" }
  20. )
  21. .catch((e: ApiError) => {
  22. expect(e.code).to.equal(401);
  23. });
  24. })
  25. .register(this);
  26. cassette
  27. .createTest("error plain", async () => {
  28. await lokaliseApi
  29. .branches()
  30. .create(
  31. {
  32. name: "hotfix/really-important",
  33. },
  34. { project_id: "803" }
  35. )
  36. .catch((e: ApiError) => {
  37. expect(e.code).to.equal(401);
  38. });
  39. })
  40. .register(this);
  41. cassette
  42. .createTest("error 500", async () => {
  43. await lokaliseApi
  44. .branches()
  45. .create(
  46. {
  47. name: "hotfix/really-important",
  48. },
  49. { project_id: "803" }
  50. )
  51. .catch((e: ApiError) => {
  52. expect(e.message).to.include("Something very bad has happened");
  53. });
  54. })
  55. .register(this);
  56. cassette
  57. .createTest("list", async () => {
  58. const branches = await lokaliseApi.branches().list({
  59. project_id: project_id,
  60. });
  61. expect(branches.items[0].branch_id).to.eq(14699);
  62. })
  63. .register(this);
  64. cassette
  65. .createTest("list_pagination", async () => {
  66. const branches = await lokaliseApi.branches().list({
  67. project_id: project_id,
  68. page: 3,
  69. limit: 1,
  70. });
  71. expect(branches.items[0].name).to.eq("merge-me");
  72. expect(branches.totalResults).to.eq(3);
  73. expect(branches.totalPages).to.eq(3);
  74. expect(branches.resultsPerPage).to.eq(1);
  75. expect(branches.currentPage).to.eq(3);
  76. expect(branches.hasNextPage()).to.be.false;
  77. expect(branches.hasPrevPage()).to.be.true;
  78. expect(branches.prevPage()).to.eq(2);
  79. })
  80. .register(this);
  81. cassette
  82. .createTest("get", async () => {
  83. const branch = await lokaliseApi.branches().get(branch_id, {
  84. project_id: project_id,
  85. });
  86. expect(branch.branch_id).to.eq(branch_id);
  87. expect(branch.name).to.eq("hotfix/really-important");
  88. expect(branch.created_at).to.eq("2019-10-30 13:11:47 (Etc/UTC)");
  89. expect(branch.created_at_timestamp).to.eq(1572441107);
  90. expect(branch.created_by).to.eq(20181);
  91. expect(branch.created_by_email).to.eq("bodrovis@protonmail.com");
  92. })
  93. .register(this);
  94. cassette
  95. .createTest("create", async () => {
  96. const branch = await lokaliseApi.branches().create(
  97. {
  98. name: "hotfix/really-important",
  99. },
  100. { project_id: project_id }
  101. );
  102. expect(branch.name).to.eq("hotfix/really-important");
  103. })
  104. .register(this);
  105. cassette
  106. .createTest("update", async () => {
  107. const branch = await lokaliseApi.branches().update(
  108. branch_id,
  109. {
  110. name: "hotfix/not-really-important",
  111. },
  112. { project_id: project_id }
  113. );
  114. expect(branch.name).to.eq("hotfix/not-really-important");
  115. })
  116. .register(this);
  117. cassette
  118. .createTest("delete", async () => {
  119. const response = await lokaliseApi.branches().delete(branch_id, {
  120. project_id: project_id,
  121. });
  122. expect(response.project_id).to.eq(project_id);
  123. expect(response.branch_deleted).to.be.true;
  124. })
  125. .register(this);
  126. cassette
  127. .createTest("merge", async () => {
  128. const branch_id_merge = 42303;
  129. const response = await lokaliseApi.branches().merge(
  130. branch_id_merge,
  131. { project_id: project_id },
  132. {
  133. force_conflict_resolve_using: "master",
  134. }
  135. );
  136. expect(response.project_id).to.eq(project_id);
  137. expect(response.branch_merged).to.eq(true);
  138. expect(response.branch.branch_id).to.eq(branch_id_merge);
  139. })
  140. .register(this);
  141. cassette
  142. .createTest("merge with defaults", async () => {
  143. const branch_id_merge = 68628;
  144. const response = await lokaliseApi.branches().merge(branch_id_merge, {
  145. project_id: project_id,
  146. });
  147. expect(response.project_id).to.eq(project_id);
  148. expect(response.branch_merged).to.eq(true);
  149. expect(response.branch["branch_id"]).to.eq(branch_id_merge);
  150. })
  151. .register(this);
  152. });