Repository URL to install this package:
|
Version:
1.7.2-rc.1 ▾
|
import { extendSetCookieHeadersForLocalDomain } from './proxyHelper';
describe('User API Middleware', () => {
describe('extendSetCookieHeadersForLocalDomain()', () => {
it('does nothing if the response does not contain "set-cookie" headers', () => {
const fakeResponse = {
headers: {
'Dummy-Header': 'FooBar',
},
};
const expectedResponse = JSON.parse(JSON.stringify(fakeResponse));
extendSetCookieHeadersForLocalDomain('localhost', fakeResponse);
expect(fakeResponse).toEqual(expectedResponse);
});
it('copies all the "set-cookie" headers and changes the domain to localhost', () => {
const fakeResponse = {
headers: {
'Dummy-Header': 'FooBar',
'set-cookie': ['MyCookie=foo; Domain=example.com; Path=/;', 'AnotherCookie=bar; Domain=example.com; Path=/;'],
},
};
const expectedResponse = {
headers: {
'Dummy-Header': 'FooBar',
'set-cookie': [
'MyCookie=foo; Domain=example.com; Path=/;',
'AnotherCookie=bar; Domain=example.com; Path=/;',
'MyCookie=foo; Domain=localhost; Path=/;',
'AnotherCookie=bar; Domain=localhost; Path=/;',
],
},
};
extendSetCookieHeadersForLocalDomain('localhost', fakeResponse);
expect(fakeResponse).toEqual(expectedResponse);
});
it('copies all the "set-cookie" headers and appends a dot to the provided domain', () => {
const fakeResponse = {
headers: {
'Dummy-Header': 'FooBar',
'set-cookie': ['MyCookie=foo; Domain=example.com; Path=/;', 'AnotherCookie=bar; Domain=example.com; Path=/;'],
},
};
const expectedResponse = {
headers: {
'Dummy-Header': 'FooBar',
'set-cookie': [
'MyCookie=foo; Domain=example.com; Path=/;',
'AnotherCookie=bar; Domain=example.com; Path=/;',
'MyCookie=foo; Domain=.doodle.com; Path=/;',
'AnotherCookie=bar; Domain=.doodle.com; Path=/;',
],
},
};
extendSetCookieHeadersForLocalDomain('doodle.com', fakeResponse);
expect(fakeResponse).toEqual(expectedResponse);
});
});
});