works with the Request input as well
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
+28
@@ -90,4 +90,32 @@ describe('PluginProtocolResolverFetchMiddleware', () => {
|
||||
expect(resolve).toHaveBeenLastCalledWith(host);
|
||||
},
|
||||
);
|
||||
|
||||
it('properly supports transferring request bodies too', async () => {
|
||||
const resolve = jest.fn();
|
||||
const discoveryApi = { getBaseUrl: resolve } as unknown as DiscoveryApi;
|
||||
const middleware = new PluginProtocolResolverFetchMiddleware(discoveryApi);
|
||||
const inner = jest.fn();
|
||||
const outer = middleware.apply(inner);
|
||||
|
||||
resolve.mockResolvedValue('https://elsewhere.com');
|
||||
|
||||
await outer('plugin://a', {
|
||||
method: 'POST',
|
||||
body: '123',
|
||||
});
|
||||
|
||||
expect(inner.mock.calls[0][0]).toBe('https://elsewhere.com');
|
||||
expect(inner.mock.calls[0][1].body).toBe('123');
|
||||
|
||||
await outer(
|
||||
new Request('plugin://a', {
|
||||
method: 'POST',
|
||||
body: '123',
|
||||
}),
|
||||
);
|
||||
|
||||
expect(inner.mock.calls[1][0]).toBe('https://elsewhere.com');
|
||||
expect(inner.mock.calls[1][1].body).toEqual(Buffer.from('123', 'utf8'));
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ export class PluginProtocolResolverFetchMiddleware implements FetchMiddleware {
|
||||
}
|
||||
|
||||
const target = `${join(base, pathname)}${search}${hash}`;
|
||||
return next(target, init);
|
||||
return next(target, typeof input === 'string' ? init : input);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user