2023-03-31 09:31:03 -07:00
|
|
|
import { prepareRequestBody } from '../../GenericFunctions';
|
|
|
|
import type { BodyParameter, BodyParametersReducer } from '../../GenericFunctions';
|
|
|
|
|
|
|
|
describe('HTTP Node Utils, prepareRequestBody', () => {
|
2023-09-25 07:59:45 -07:00
|
|
|
it('should call default reducer', async () => {
|
2023-03-31 09:31:03 -07:00
|
|
|
const bodyParameters: BodyParameter[] = [
|
|
|
|
{
|
|
|
|
name: 'foo.bar',
|
|
|
|
value: 'baz',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const defaultReducer: BodyParametersReducer = jest.fn();
|
|
|
|
|
2023-09-25 07:59:45 -07:00
|
|
|
await prepareRequestBody(bodyParameters, 'json', 3, defaultReducer);
|
2023-03-31 09:31:03 -07:00
|
|
|
|
|
|
|
expect(defaultReducer).toBeCalledTimes(1);
|
2023-09-25 07:59:45 -07:00
|
|
|
expect(defaultReducer).toBeCalledWith({}, { name: 'foo.bar', value: 'baz' });
|
2023-03-31 09:31:03 -07:00
|
|
|
});
|
|
|
|
|
2023-09-25 07:59:45 -07:00
|
|
|
it('should call process dot notations', async () => {
|
2023-03-31 09:31:03 -07:00
|
|
|
const bodyParameters: BodyParameter[] = [
|
|
|
|
{
|
|
|
|
name: 'foo.bar.spam',
|
|
|
|
value: 'baz',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const defaultReducer: BodyParametersReducer = jest.fn();
|
|
|
|
|
2023-09-25 07:59:45 -07:00
|
|
|
const result = await prepareRequestBody(bodyParameters, 'json', 4, defaultReducer);
|
2023-03-31 09:31:03 -07:00
|
|
|
|
|
|
|
expect(defaultReducer).toBeCalledTimes(0);
|
|
|
|
expect(result).toBeDefined();
|
|
|
|
expect(result).toEqual({ foo: { bar: { spam: 'baz' } } });
|
|
|
|
});
|
|
|
|
});
|