webhooks.spec.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. describe("Webhooks", 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 webhook_id = "795565582e5ab15a59bb68156c7e2e9eaa1e8d1a";
  10. const new_webhook_id = "fb60b95ff86631c9f4df2fb8f5e77ba879cf9156";
  11. cassette
  12. .createTest("list", async () => {
  13. const webhooks = await lokaliseApi.webhooks().list({
  14. project_id: project_id,
  15. });
  16. expect(webhooks.items[0].url).to.eq("https://serios.webhook");
  17. })
  18. .register(this);
  19. cassette
  20. .createTest("list_pagination", async () => {
  21. const webhooks = await lokaliseApi.webhooks().list({
  22. project_id: project_id,
  23. page: 2,
  24. limit: 1,
  25. });
  26. expect(webhooks.items[0].url).to.eq("https://canihaz.hook");
  27. expect(webhooks.totalResults).to.eq(2);
  28. expect(webhooks.totalPages).to.eq(2);
  29. expect(webhooks.resultsPerPage).to.eq(1);
  30. expect(webhooks.currentPage).to.eq(2);
  31. })
  32. .register(this);
  33. cassette
  34. .createTest("get", async () => {
  35. const webhook = await lokaliseApi.webhooks().get(webhook_id, {
  36. project_id: project_id,
  37. });
  38. expect(webhook.webhook_id).to.eq(webhook_id);
  39. expect(webhook.url).to.eq("https://serios.webhook");
  40. expect(webhook.secret).to.eq("5efb67362d6408c43e2cc541729e07925cf636d1");
  41. expect(webhook.webhook_id).to.eq(webhook_id);
  42. expect(webhook.events[0]).to.eq("project.imported");
  43. expect(webhook.event_lang_map[0].event).to.eq(
  44. "project.translation.updated"
  45. );
  46. })
  47. .register(this);
  48. cassette
  49. .createTest("create", async () => {
  50. const webhook = await lokaliseApi
  51. .webhooks()
  52. .create(
  53. { url: "http://node.hook", events: ["project.exported"] },
  54. { project_id: project_id }
  55. );
  56. expect(webhook.webhook_id).to.eq(new_webhook_id);
  57. expect(webhook.url).to.eq("http://node.hook");
  58. expect(webhook.events[0]).to.eq("project.exported");
  59. })
  60. .register(this);
  61. cassette
  62. .createTest("update", async () => {
  63. const webhook = await lokaliseApi
  64. .webhooks()
  65. .update(
  66. new_webhook_id,
  67. { url: "http://hook.node", events: ["project.snapshot"] },
  68. { project_id: project_id }
  69. );
  70. expect(webhook.webhook_id).to.eq(new_webhook_id);
  71. expect(webhook.url).to.eq("http://hook.node");
  72. expect(webhook.events[0]).to.eq("project.snapshot");
  73. })
  74. .register(this);
  75. cassette
  76. .createTest("delete", async () => {
  77. const response = await lokaliseApi.webhooks().delete(new_webhook_id, {
  78. project_id: project_id,
  79. });
  80. expect(response.project_id).to.eq(project_id);
  81. expect(response.webhook_deleted).to.eq(true);
  82. })
  83. .register(this);
  84. cassette
  85. .createTest("regenerate_secret", async () => {
  86. const response = await lokaliseApi
  87. .webhooks()
  88. .regenerate_secret("795565582e5ab15a59bb68156c7e2e9eaa1e8d1a", {
  89. project_id: project_id,
  90. });
  91. expect(response.project_id).to.eq(project_id);
  92. expect(response.secret).to.eq("8c91d28b46a8874c7ef0064494587b83944675ab");
  93. })
  94. .register(this);
  95. });