Skip to content

Commit

Permalink
fix: cookies from workflows and step are not set to the request (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAnansky authored and tatomyr committed Feb 20, 2025
1 parent 2dcbe9d commit cfa0d98
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 93 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1498,4 +1498,184 @@ describe('prepareRequest', () => {
},
]);
});

it('should merge cookie parameters from workflow and step', async () => {
const localCtx = {
...ctx,
...{
workflows: [
{
workflowId: 'get-breeds-workflow',
parameters: [
{
name: 'pageSize',
in: 'header',
value: 100,
},
{
name: 'cookie',
in: 'header',
value: 'sessionId=32;userId=32;workflow-cookie=32',
},
{
name: 'token-from-workflow',
in: 'cookie',
value: '32',
},
],
steps: [
{
stepId: 'get-breeds-step',
operationId: 'cats.getBreeds',
parameters: [
{
name: 'step-header',
in: 'header',
value: 'step-header-value',
},
{
name: 'token-from-step',
in: 'cookie',
value: '42',
},
{
name: 'cookie',
in: 'header',
value: 'sessionId=42;stepСookie=42',
},
],
checks: [],
response: {
body: {
current_page: 1,
data: [
{
breed: 'Abyssinian',
country: 'Ethiopia',
origin: 'Natural/Standard',
coat: 'Short',
pattern: 'Ticked',
},
{
breed: 'Aegean',
country: 'Greece',
origin: 'Natural/Standard',
coat: 'Semi-long',
pattern: 'Bi- or tri-colored',
},
],
first_page_url: 'https://catfact.ninja/breeds?page=1',
from: 1,
last_page: 4,
last_page_url: 'https://catfact.ninja/breeds?page=4',
links: [
{
url: null,
label: 'Previous',
active: false,
},
{
url: 'https://catfact.ninja/breeds?page=1',
label: '1',
active: true,
},
],
next_page_url: 'https://catfact.ninja/breeds?page=2',
path: 'https://catfact.ninja/breeds',
per_page: 25,
prev_page_url: null,
to: 25,
total: 98,
},
code: 200,
headers: {},
contentType: 'application/json',
},
verboseLog: {},
},
],
},
],
$workflows: {
'get-breeds-workflow': {
parameters: [
{
name: 'pageSize',
in: 'header',
value: 100,
},
],
steps: {
'get-breeds-step': {
request: {
headers: {},
path: '/breeds',
url: 'https://catfact.ninja/',
method: 'get',
queryParams: {},
pathParams: {},
headerParams: {},
},
},
},
},
},
$components: {
parameters: {
page: {
name: 'page',
in: 'header',
value: 1,
},
pageSize: {
name: 'pageSize',
in: 'header',
value: 100,
},
},
},
},
} as unknown as TestContext;

const step = {
stepId: 'get-breeds-step',
operationId: 'cats.getBreeds',
checks: [],
} as unknown as Step;

const { parameters } = await prepareRequest(localCtx, step, workflowName);

expect(parameters).toEqual([
{
value: 'application/json',
in: 'header',
name: 'accept',
},
{
value: 100,
in: 'header',
name: 'pageSize',
},
{
value: '32',
in: 'cookie',
name: 'sessionId',
},
{
value: '32',
in: 'cookie',
name: 'userId',
},
{
value: '32',
in: 'cookie',
name: 'workflow-cookie',
},
{
value: '32',
in: 'cookie',
name: 'token-from-workflow',
},
]);
});
});
1 change: 0 additions & 1 deletion packages/respect-core/src/modules/config-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './parse-request-body';
export * from './handle-request-body-replacements';
export * from './resolve-reusable-object-reference';
export * from './resolve-reusable-component';
export * from './map-header-params-and-cookie-to-object';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,6 @@ function extractCookieParametersFromHeaderParameters(
result.push(parameter);
}
}

return result;
}
6 changes: 6 additions & 0 deletions packages/respect-core/src/utils/api-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export class ApiFetcher implements IFetcher {
headers['content-type'] = 'application/json';
}

if (Object.keys(cookies).length) {
headers['cookie'] = Object.entries(cookies)
.map(([key, value]) => `${key}=${value}`)
.join('; ');
}

let resolvedPath = resolvePath(path, pathParams) || '';
const pathWithSearchParams = `${resolvedPath}${
searchParams.toString() ? '?' + searchParams.toString() : ''
Expand Down

0 comments on commit cfa0d98

Please sign in to comment.