Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import getAuthorizationHeader from './getAuthorizationHeader'; import user from './../user'; jest.mock('./../user.js'); describe('getAuthorizationHeader', () => { it('should return a HTTP Basic Auth when server contains requestOptions.auth', () => { const validServer = { requestOptions: { auth: 'dummy_user:dummy_password', }, }; const expectedAuthorizationHeader = { Authorization: `Basic ${btoa(validServer.requestOptions.auth)}`, }; const authentication = getAuthorizationHeader(validServer); expect(authentication).toEqual(expectedAuthorizationHeader); }); it('should return a HTTP Basic Auth when server contains requestOptions.auth even though there is no password', () => { const validServerWithoutPassword = { requestOptions: { auth: 'dummy_user', }, }; const expectedAuthorizationHeader = { Authorization: `Basic ${btoa(validServerWithoutPassword.requestOptions.auth)}`, }; const authentication = getAuthorizationHeader(validServerWithoutPassword); expect(authentication).toEqual(expectedAuthorizationHeader); }); it('should return a HTTP Basic Auth when server contains requestOptions.auth custom function', () => { const validServerCustomAuth = { requestOptions: { auth: options => `Basic ${options.token}`, token: 'ZHVtbXlfdXNlcjpkdW1teV9wYXNzd29yZA==', }, }; const expectedAuthorizationHeader = { Authorization: `Basic ${validServerCustomAuth.requestOptions.token}`, }; const authentication = getAuthorizationHeader(validServerCustomAuth); expect(authentication).toEqual(expectedAuthorizationHeader); }); it('should return an empty object when there is no either server.requestOptions.auth or accessToken', () => { const authentication = getAuthorizationHeader({}); expect(authentication).toEqual({}); }); it('should return an Authorization with accessToken when server is not defined and there is an accessToken', () => { user.getAccessToken.mockImplementationOnce(() => 'MOCKED_TOKEN'); const authentication = getAuthorizationHeader({}, user); const expectedHeaderBasedOnUserAccessToken = { Authorization: 'Bearer MOCKED_TOKEN', }; expect(authentication).toEqual(expectedHeaderBasedOnUserAccessToken); }); }); |