Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/users-api-connector / src / middlewares / proxyHelper.spec.js
Size: Mime:
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);
    });
  });
});