Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

api.user.js 1.7 KiB

7 år sedan
7 år sedan
7 år sedan
7 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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').post('/api/tokens/auth/', user).reply(201, {token});
  8. return User.login(user, {baseURL: 'https://lesspass.com'}).then(response => {
  9. t.is(response.token, token);
  10. });
  11. });
  12. test('register', t => {
  13. const user = {email: 'test@example.org', password: 'password'};
  14. nock('https://lesspass.com').post('/api/auth/register/', user).reply(201, {email: user.email, pk: 1});
  15. return User.register(user, {baseURL: 'https://lesspass.com'}).then(response => {
  16. t.is(response.email, user.email);
  17. });
  18. });
  19. test('resetPassword', t => {
  20. var email = 'test@lesspass.com';
  21. nock('https://lesspass.com').post('/api/auth/password/reset/', {email}).reply(204);
  22. return User.resetPassword({email}, {baseURL: 'https://lesspass.com'}).then(data => {
  23. t.is(data.status, 204)
  24. });
  25. });
  26. test('confirmResetPassword', t => {
  27. var newPassword = {
  28. uid: 'MQ',
  29. token: '5g1-2bd69bd6f6dcd73f8124',
  30. new_password: 'password1'
  31. };
  32. nock('https://lesspass.com').post('/api/auth/password/reset/confirm/', newPassword).reply(204);
  33. return User.confirmResetPassword(newPassword, {baseURL: 'https://lesspass.com'}).then(data => {
  34. t.is(data.status, 204)
  35. });
  36. });
  37. test('refresh token', t => {
  38. const token = '3e3231';
  39. const newToken = 'wibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIi';
  40. nock('https://lesspass.com').post('/api/tokens/refresh/', {token}).reply(200, {token: newToken});
  41. return User.requestNewToken({token}, {baseURL: 'https://lesspass.com'}).then(refreshedToken => {
  42. t.is(refreshedToken, newToken);
  43. });
  44. });