您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

api.user.js 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import test from "ava";
  2. import nock from "nock";
  3. import User from "../../src/api/user";
  4. test("login", t => {
  5. const token = "5e0651";
  6. const user = { email: "test@example.org", password: "password" };
  7. nock("https://lesspass.com")
  8. .post("/api/tokens/auth/", user)
  9. .reply(201, { token });
  10. return User.login(user, {
  11. baseURL: "https://lesspass.com"
  12. }).then(response => {
  13. t.is(response.token, token);
  14. });
  15. });
  16. test("register", t => {
  17. const user = { email: "test@example.org", password: "password" };
  18. nock("https://lesspass.com")
  19. .post("/api/auth/register/", user)
  20. .reply(201, { email: user.email, pk: 1 });
  21. return User.register(user, {
  22. baseURL: "https://lesspass.com"
  23. }).then(response => {
  24. t.is(response.email, user.email);
  25. });
  26. });
  27. test("resetPassword", t => {
  28. var email = "test@lesspass.com";
  29. nock("https://lesspass.com")
  30. .post("/api/auth/password/reset/", { email })
  31. .reply(204);
  32. return User.resetPassword(
  33. { email },
  34. { baseURL: "https://lesspass.com" }
  35. ).then(data => {
  36. t.is(data.status, 204);
  37. });
  38. });
  39. test("confirmResetPassword", t => {
  40. var newPassword = {
  41. uid: "MQ",
  42. token: "5g1-2bd69bd6f6dcd73f8124",
  43. new_password: "password1"
  44. };
  45. nock("https://lesspass.com")
  46. .post("/api/auth/password/reset/confirm/", newPassword)
  47. .reply(204);
  48. return User.confirmResetPassword(newPassword, {
  49. baseURL: "https://lesspass.com"
  50. }).then(data => {
  51. t.is(data.status, 204);
  52. });
  53. });
  54. test("refresh token", t => {
  55. const token = "3e3231";
  56. const newToken =
  57. "wibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIi";
  58. nock("https://lesspass.com")
  59. .post("/api/tokens/refresh/", { token })
  60. .reply(200, { token: newToken });
  61. return User.requestNewToken(
  62. { token },
  63. { baseURL: "https://lesspass.com" }
  64. ).then(refreshedToken => {
  65. t.is(refreshedToken, newToken);
  66. });
  67. });