|
@@ -14,13 +14,21 @@ function AuthFactory(token, localStorage = new LocalStorageMock()) { |
|
|
test('request token', t => { |
|
|
test('request token', t => { |
|
|
const token = '5e0651'; |
|
|
const token = '5e0651'; |
|
|
const user = {email: 'test@example.org', password: 'password'}; |
|
|
const user = {email: 'test@example.org', password: 'password'}; |
|
|
|
|
|
|
|
|
nock('https://lesspass.com').post('/api/tokens/auth/', user).reply(201, {token}); |
|
|
nock('https://lesspass.com').post('/api/tokens/auth/', user).reply(201, {token}); |
|
|
return Auth._requestToken(user, {baseURL: 'https://lesspass.com'}).then(requestedToken => { |
|
|
return Auth._requestToken(user, {baseURL: 'https://lesspass.com'}).then(requestedToken => { |
|
|
t.is(requestedToken, token); |
|
|
t.is(requestedToken, token); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('request new token', t => { |
|
|
|
|
|
const token = '3e3231'; |
|
|
|
|
|
const newToken = 'wibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9eyJzdWIiOiIxMjM0NTY3ODkwIi'; |
|
|
|
|
|
nock('https://lesspass.com').post('/api/tokens/refresh/', {token}).reply(200, {token: newToken}); |
|
|
|
|
|
return Auth._requestNewToken({token}, {baseURL: 'https://lesspass.com'}).then(refreshedToken => { |
|
|
|
|
|
t.is(refreshedToken, newToken); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
test('user first connection is guest', t => { |
|
|
test('user first connection is guest', t => { |
|
|
const storage = new Storage(new LocalStorageMock()); |
|
|
const storage = new Storage(new LocalStorageMock()); |
|
|
const auth = new Auth(storage); |
|
|
const auth = new Auth(storage); |
|
|