mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-13 08:49:01 +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');
|
|
});
|
|
});
|