orders.spec.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. require("../setup");
  2. import { expect } from "chai";
  3. import { Cassettes } from "mocha-cassettes";
  4. import { LokaliseApi } from "../../src/lokalise/lokalise_api";
  5. describe("Orders", function () {
  6. const cassette = new Cassettes("./test/cassettes");
  7. const lokaliseApi = new LokaliseApi({ apiKey: process.env.API_KEY });
  8. const team_id = 176692;
  9. const order_id = "201903198B2";
  10. cassette
  11. .createTest("list", async () => {
  12. const orders = await lokaliseApi.orders().list({ team_id: team_id });
  13. expect(orders.items[0].order_id).to.eq(order_id);
  14. })
  15. .register(this);
  16. cassette
  17. .createTest("list_pagination", async () => {
  18. const orders = await lokaliseApi.orders().list({
  19. team_id: team_id,
  20. page: 2,
  21. limit: 1,
  22. });
  23. expect(orders.items[0].order_id).to.eq("20190611AC2");
  24. expect(orders.totalResults).to.eq(2);
  25. expect(orders.totalPages).to.eq(2);
  26. expect(orders.resultsPerPage).to.eq(1);
  27. expect(orders.currentPage).to.eq(2);
  28. expect(orders.hasNextPage()).to.be.false;
  29. expect(orders.nextPage()).to.eq(2);
  30. })
  31. .register(this);
  32. cassette
  33. .createTest("get", async () => {
  34. const order = await lokaliseApi.orders().get(order_id, {
  35. team_id: team_id,
  36. });
  37. expect(order.order_id).to.eq(order_id);
  38. expect(order.project_id).to.eq("803826145ba90b42d5d860.46800099");
  39. expect(order.card_id).to.eq(1774);
  40. expect(order.status).to.eq("completed");
  41. expect(order.created_at).to.eq("2019-03-19 18:18:21 (Etc/UTC)");
  42. expect(order.created_at_timestamp).to.eq(1553019501);
  43. expect(order.created_by).to.eq(20181);
  44. expect(order.created_by_email).to.eq("bodrovis@protonmail.com");
  45. expect(order.source_language_iso).to.eq("en");
  46. expect(order.target_language_isos).to.include("ru");
  47. expect(order.keys).to.include(15519786);
  48. expect(order.source_words["ru"]).to.eq(1);
  49. expect(order.provider_slug).to.eq("gengo");
  50. expect(order.translation_style).to.eq("friendly");
  51. expect(order.translation_tier).to.eq(1);
  52. expect(order.translation_tier_name).to.eq("Professional translator");
  53. expect(order.briefing).to.eq("Some briefing");
  54. expect(order.total).to.eq(0.07);
  55. expect(order.payment_method).to.eq(null);
  56. })
  57. .register(this);
  58. cassette
  59. .createTest("create", async () => {
  60. const order = await lokaliseApi.orders().create(
  61. {
  62. project_id: "803826145ba90b42d5d860.46800099",
  63. card_id: "1774",
  64. briefing: "Nothing specific",
  65. source_language_iso: "en",
  66. target_language_isos: ["nl"],
  67. keys: [15519786],
  68. provider_slug: "gengo",
  69. translation_tier: "1",
  70. },
  71. { team_id: team_id }
  72. );
  73. expect(order.status).to.eq("in progress");
  74. expect(order.created_by).to.eq("20181");
  75. })
  76. .register(this);
  77. });