fix(curl): properly export get requests with body payload (#25)

This commit is contained in:
Mazen Touati
2025-12-26 22:39:27 +01:00
committed by GitHub
parent 8e05ce4978
commit 4adb5a1bbf
3 changed files with 196 additions and 60 deletions

View File

@@ -44,7 +44,7 @@ const requestBase: PendingRequest = {
};
describe('generateCurlCommand', () => {
it('builds curl command with method, headers, and body', () => {
it('builds curl command with method, headers, and body [POST]', () => {
const { command, hasSpecialAuth } = generateCurlCommand(
requestBase,
'https://api.example.com',
@@ -59,6 +59,76 @@ describe('generateCurlCommand', () => {
expect(hasSpecialAuth).toBe(false);
});
it('builds curl command with method, headers, and body [GET]', () => {
const getRequestBase = Object.assign({}, requestBase);
getRequestBase.method = 'GET';
getRequestBase.body.GET = getRequestBase.body.POST;
const { command, hasSpecialAuth } = generateCurlCommand(
getRequestBase,
'https://api.example.com',
);
expect(command).toContain('curl');
expect(command).toContain('"https://api.example.com/users?page=1&name=Jane"');
expect(command).toContain('-H "Authorization: Bearer token"');
expect(command).toContain('-H "Accept: application/json"');
expect(hasSpecialAuth).toBe(false);
});
it('builds curl command with method, headers, and nested body [POST]', () => {
const getRequestBase = Object.assign({}, requestBase);
getRequestBase.body.POST = {
[RequestBodyTypeEnum.JSON]: JSON.stringify({
user: { firstName: 'Jane', lastName: 'Doe' },
username: 'foobar',
}),
};
const { command, hasSpecialAuth } = generateCurlCommand(
getRequestBase,
'https://api.example.com',
);
expect(command).toContain('curl');
expect(command).toContain('"https://api.example.com/users?page=1');
expect(command).toContain('-H "Authorization: Bearer token"');
expect(command).toContain('-H "Accept: application/json"');
expect(command).toContain(
'{"user":{"firstName":"Jane","lastName":"Doe"},"username":"foobar"}',
);
expect(hasSpecialAuth).toBe(false);
});
it('builds curl command with method, headers, and nested body [GET]', () => {
const getRequestBase = Object.assign({}, requestBase);
getRequestBase.method = 'GET';
getRequestBase.body.GET = {
[RequestBodyTypeEnum.JSON]: JSON.stringify({
user: { firstName: 'Jane', lastName: 'Doe' },
username: 'foobar',
}),
};
const { command, hasSpecialAuth } = generateCurlCommand(
getRequestBase,
'https://api.example.com',
);
expect(command).toContain('curl');
expect(command).toContain(
'"https://api.example.com/users?page=1&user%5BfirstName%5D=Jane&user%5BlastName%5D=Doe&username=foobar"',
);
expect(command).toContain('-H "Authorization: Bearer token"');
expect(command).toContain('-H "Accept: application/json"');
expect(hasSpecialAuth).toBe(false);
});
it('flags special authorization types', () => {
const request: PendingRequest = {
...requestBase,