瀏覽代碼

add request new token method in auth service

pull/342/head
Guillaume Vincent 8 年之前
父節點
當前提交
0615e0f72c
共有 2 個文件被更改,包括 15 次插入1 次删除
  1. +6
    -0
      src/api/auth.js
  2. +9
    -1
      test/auth.js

+ 6
- 0
src/api/auth.js 查看文件

@@ -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 查看文件

@@ -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);


Loading…
取消
儲存