mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-09 13:28:02 +05:30
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
|
import expect from 'unexpected';
|
||
|
|
||
|
import bearerHeaderMiddleware from 'components/user/middlewares/bearerHeaderMiddleware';
|
||
|
|
||
|
describe('bearerHeaderMiddleware', () => {
|
||
|
it('should set Authorization header', () => {
|
||
|
const token = 'foo';
|
||
|
const middleware = bearerHeaderMiddleware({
|
||
|
getState: () => ({
|
||
|
user: {token}
|
||
|
})
|
||
|
});
|
||
|
|
||
|
const data = {
|
||
|
options: {
|
||
|
headers: {}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
middleware.before(data);
|
||
|
|
||
|
expect(data.options.headers, 'to satisfy', {
|
||
|
Authorization: `Bearer ${token}`
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should not set Authorization header if no token', () => {
|
||
|
const middleware = bearerHeaderMiddleware({
|
||
|
getState: () => ({
|
||
|
user: {}
|
||
|
})
|
||
|
});
|
||
|
|
||
|
const data = {
|
||
|
options: {
|
||
|
headers: {}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
middleware.before(data);
|
||
|
|
||
|
expect(data.options.headers.Authorization, 'to be undefined');
|
||
|
});
|
||
|
});
|