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.
 
 
 
 
 
 

60 lines
2.3 KiB

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