Explorar el Código

add request new token method in auth service

pull/342/head
Guillaume Vincent hace 8 años
padre
commit
0615e0f72c
Se han modificado 2 ficheros con 15 adiciones y 1 borrados
  1. +6
    -0
      src/api/auth.js
  2. +9
    -1
      test/auth.js

+ 6
- 0
src/api/auth.js Ver fichero

@@ -45,4 +45,10 @@ export default class Auth {
return response.data.token;
});
}

static _requestNewToken(token, config = {}) {
return axios.post('/api/tokens/refresh/', token, config).then(response => {
return response.data.token;
});
}
}

+ 9
- 1
test/auth.js Ver fichero

@@ -14,13 +14,21 @@ function AuthFactory(token, localStorage = new LocalStorageMock()) {
test('request token', t => {
const token = '5e0651';
const user = {email: 'test@example.org', password: 'password'};

nock('https://lesspass.com').post('/api/tokens/auth/', user).reply(201, {token});
return Auth._requestToken(user, {baseURL: 'https://lesspass.com'}).then(requestedToken => {
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 => {
const storage = new Storage(new LocalStorageMock());
const auth = new Auth(storage);


Cargando…
Cancelar
Guardar