lokalise_api.spec.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. const cassette = new Cassettes("./test/cassettes");
  6. const project_id = "803826145ba90b42d5d860.46800099";
  7. describe("LokaliseApi", function () {
  8. it("is expected to throw an error if the API key is not provided", function () {
  9. expect(function () {
  10. new LokaliseApi({ apiKey: "" });
  11. }).to.throw(Error);
  12. });
  13. it("is expected to contain clientData", function () {
  14. const client = new LokaliseApi({ apiKey: process.env.API_KEY });
  15. expect(client.clientData.token).to.eq(process.env.API_KEY);
  16. expect(client.clientData.authHeader).to.eq("x-api-token");
  17. expect(client.clientData.enableCompression).to.be.false;
  18. });
  19. });
  20. describe("LokaliseApi host", function () {
  21. it("is expected to have empty host by default", function () {
  22. const client = new LokaliseApi({ apiKey: process.env.API_KEY });
  23. expect(client.clientData.host).to.be.undefined;
  24. });
  25. it("is expected to assign host", function () {
  26. const client = new LokaliseApi({
  27. apiKey: process.env.API_KEY,
  28. host: "http://example.com",
  29. });
  30. expect(client.clientData.host).to.eq("http://example.com");
  31. });
  32. cassette
  33. .createTest("list_with_gzip", async () => {
  34. const client = new LokaliseApi({
  35. apiKey: process.env.API_KEY,
  36. host: "https://api.lokalise.com/api2/",
  37. });
  38. const keys = await client.keys().list({ project_id: project_id });
  39. expect(keys.items[0].key_id).to.eq(44596059);
  40. })
  41. .register(this);
  42. });
  43. describe("LokaliseApi gzip", function () {
  44. cassette
  45. .createTest("list_with_gzip", async () => {
  46. const client = new LokaliseApi({
  47. apiKey: process.env.API_KEY,
  48. enableCompression: true,
  49. });
  50. const keys = await client.keys().list({ project_id: project_id });
  51. expect(keys.items[0].key_id).to.eq(44596059);
  52. })
  53. .register(this);
  54. cassette
  55. .createTest("system_languages_no_gzip", async () => {
  56. const client = new LokaliseApi({
  57. apiKey: process.env.API_KEY,
  58. enableCompression: false,
  59. });
  60. const languages = await client.languages().system_languages({
  61. page: 3,
  62. limit: 1,
  63. });
  64. expect(languages.items[0].lang_id).to.eq(790);
  65. })
  66. .register(this);
  67. cassette
  68. .createTest("system_languages_default_gzip", async () => {
  69. const client = new LokaliseApi({ apiKey: process.env.API_KEY });
  70. const languages = await client.languages().system_languages({
  71. page: 4,
  72. limit: 1,
  73. });
  74. expect(languages.items[0].lang_id).to.eq(791);
  75. })
  76. .register(this);
  77. });