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.

api.user.js 1.7 KiB

7 vuotta sitten
7 vuotta sitten
7 vuotta sitten
7 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. t.notThrows(User.resetPassword({email}, {baseURL: 'https://lesspass.com'}));
  23. });
  24. test('confirmResetPassword', t => {
  25. var newPassword = {
  26. uid: 'MQ',
  27. token: '5g1-2bd69bd6f6dcd73f8124',
  28. new_password: 'password1'
  29. };
  30. nock('https://lesspass.com').post('/api/auth/password/reset/confirm/', newPassword).reply(204);
  31. t.notThrows(User.confirmResetPassword(newPassword, {baseURL: 'https://lesspass.com'}));
  32. });
  33. test('refresh token', t => {
  34. const token = '3e3231';
  35. const newToken = 'wibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIi';
  36. nock('https://lesspass.com').post('/api/tokens/refresh/', {token}).reply(200, {token: newToken});
  37. return User.requestNewToken({token}, {baseURL: 'https://lesspass.com'}).then(refreshedToken => {
  38. t.is(refreshedToken, newToken);
  39. });
  40. });