You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 line
2.4 KiB

  1. import test from "ava";
  2. import nock from "nock";
  3. import Passwords from "../../src/api/password";
  4. const token =
  5. "ZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFt";
  6. const config = { baseURL: "https://lesspass.com", token: token };
  7. const headers = { reqheaders: { Authorization: `JWT ${token}` } };
  8. test("Passwords.create", t => {
  9. const password = { login: "text@example.org" };
  10. nock("https://lesspass.com")
  11. .post("/api/passwords/", password)
  12. .reply(201, { ...password, id: "1" });
  13. return Passwords.create(password, config).then(response => {
  14. const passwordCreated = response.data;
  15. t.is(passwordCreated.id, "1");
  16. t.is(passwordCreated.login, password.login);
  17. });
  18. });
  19. test("Passwords.create set Authorization header", t => {
  20. const password = { login: "text@example.org" };
  21. nock("https://lesspass.com", headers)
  22. .post("/api/passwords/", password)
  23. .query(true)
  24. .reply(201, {
  25. id: "1",
  26. ...password
  27. });
  28. return Passwords.create(password, config).then(response => {
  29. const passwordCreated = response.data;
  30. t.is(passwordCreated.id, "1");
  31. t.is(passwordCreated.login, password.login);
  32. });
  33. });
  34. test("Passwords.all", t => {
  35. nock("https://lesspass.com", headers)
  36. .get("/api/passwords/")
  37. .query(true)
  38. .reply(200, {});
  39. return Passwords.all(config).then(response => {
  40. t.is(response.status, 200);
  41. });
  42. });
  43. test("Passwords.get", t => {
  44. nock("https://lesspass.com", headers)
  45. .get("/api/passwords/c8e4f983-8ffe-b705-4064-d3b7aa4a4782/")
  46. .query(true)
  47. .reply(200, {});
  48. return Passwords.read(
  49. { id: "c8e4f983-8ffe-b705-4064-d3b7aa4a4782" },
  50. config
  51. ).then(response => {
  52. t.is(response.status, 200);
  53. });
  54. });
  55. test("Passwords.update", t => {
  56. const password = {
  57. id: "c8e4f983-4064-8ffe-b705-d3b7aa4a4782",
  58. login: "test@example.org"
  59. };
  60. nock("https://lesspass.com", headers)
  61. .put("/api/passwords/c8e4f983-4064-8ffe-b705-d3b7aa4a4782/", password)
  62. .query(true)
  63. .reply(200, {});
  64. return Passwords.update(password, config).then(response => {
  65. t.is(response.status, 200);
  66. });
  67. });
  68. test("Passwords.delete", t => {
  69. nock("https://lesspass.com", headers)
  70. .delete("/api/passwords/c8e4f983-8ffe-4064-b705-d3b7aa4a4782/")
  71. .query(true)
  72. .reply(204);
  73. return Passwords.delete(
  74. { id: "c8e4f983-8ffe-4064-b705-d3b7aa4a4782" },
  75. config
  76. ).then(response => {
  77. t.is(response.status, 204);
  78. });
  79. });