1*8d307f52SEvan Baconimport { URLSearchParams } from 'url'; 2*8d307f52SEvan Bacon 3*8d307f52SEvan Baconimport { wrapFetchWithBaseUrl } from '../wrapFetchWithBaseUrl'; 4*8d307f52SEvan Bacon 5*8d307f52SEvan Bacondescribe(wrapFetchWithBaseUrl, () => { 6*8d307f52SEvan Bacon it(`supports relative paths`, async () => { 7*8d307f52SEvan Bacon const input = jest.fn(); 8*8d307f52SEvan Bacon const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 9*8d307f52SEvan Bacon await next('test', {}); 10*8d307f52SEvan Bacon expect(input).toBeCalledWith('https://example.com/v2/test', {}); 11*8d307f52SEvan Bacon }); 12*8d307f52SEvan Bacon it(`supports relative paths that don't begin with slash`, async () => { 13*8d307f52SEvan Bacon const input = jest.fn(); 14*8d307f52SEvan Bacon const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 15*8d307f52SEvan Bacon await next('test', {}); 16*8d307f52SEvan Bacon expect(input).toBeCalledWith('https://example.com/v2/test', {}); 17*8d307f52SEvan Bacon }); 18*8d307f52SEvan Bacon it(`supports absolute URLs`, async () => { 19*8d307f52SEvan Bacon const input = jest.fn(); 20*8d307f52SEvan Bacon const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2'); 21*8d307f52SEvan Bacon await next('https://expo.dev/', {}); 22*8d307f52SEvan Bacon expect(input).toBeCalledWith('https://expo.dev/', {}); 23*8d307f52SEvan Bacon }); 24*8d307f52SEvan Bacon it(`appends URLSearchParams to the URL`, async () => { 25*8d307f52SEvan Bacon const input = jest.fn(); 26*8d307f52SEvan Bacon const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2/'); 27*8d307f52SEvan Bacon await next('test', { 28*8d307f52SEvan Bacon searchParams: new URLSearchParams({ 29*8d307f52SEvan Bacon foo: 'bar', 30*8d307f52SEvan Bacon }), 31*8d307f52SEvan Bacon }); 32*8d307f52SEvan Bacon expect(input).toBeCalledWith('https://example.com/v2/test?foo=bar', expect.anything()); 33*8d307f52SEvan Bacon }); 34*8d307f52SEvan Bacon it(`does not support non-string URLs`, async () => { 35*8d307f52SEvan Bacon const input = jest.fn(); 36*8d307f52SEvan Bacon const next = wrapFetchWithBaseUrl(input, 'https://example.com/v2'); 37*8d307f52SEvan Bacon expect(() => next({ href: 'foo' }, {})).toThrow(/string URL/); 38*8d307f52SEvan Bacon }); 39*8d307f52SEvan Bacon}); 40