nodeApi.mjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* eslint no-console: 0 */
  2. /**
  3. * nodeApi.js
  4. *
  5. * Test node api utilities
  6. *
  7. * @author d98762625 [d98762625@gmail.com]
  8. * @copyright Crown Copyright 2018
  9. * @license Apache-2.0
  10. */
  11. import assert from "assert";
  12. import it from "../assertionHandler";
  13. import chef from "../../../src/node/index";
  14. import TestRegister from "../../TestRegister";
  15. TestRegister.addApiTests([
  16. it("should have some operations", () => {
  17. assert(chef);
  18. assert(chef.toBase32);
  19. assert(chef.setUnion);
  20. assert(!chef.randomFunction);
  21. }),
  22. it("should have an async/await api", async () => {
  23. try {
  24. const result = await chef.toBase32("input");
  25. assert.notEqual("something", result);
  26. } catch (e) {
  27. // shouldnt reach here
  28. assert(false);
  29. }
  30. try {
  31. const fail = chef.setUnion("1");
  32. // shouldnt get here
  33. assert(false);
  34. } catch (e) {
  35. assert(true);
  36. }
  37. }),
  38. it("should have a callback API", async () => {
  39. await chef.toBase32("something", (err, result) => {
  40. if (err) {
  41. assert(false);
  42. } else {
  43. assert.equal("ONXW2ZLUNBUW4ZY=", result);
  44. }
  45. });
  46. }),
  47. it("should handle errors in callback API", async () => {
  48. await chef.setUnion("1", (err, result) => {
  49. if (err) {
  50. assert(true);
  51. return;
  52. }
  53. assert(false);
  54. });
  55. })
  56. ]);