Skip to content

Commit

Permalink
fix: trim spaces after comma (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tripodsan authored Oct 22, 2022
1 parent 8c11737 commit 24a1542
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/forms-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export async function formsPipe(state, request) {

const sourceLocation = resourceFetchResponse.headers.get('x-amz-meta-x-source-location');
const referer = request.headers.get('referer') || 'unknown';
const sheetNames = sheets.split(',');
const sheetNames = sheets.split(',').map((s) => s.trim());

if (!sourceLocation || !sheetNames.includes('incoming')) {
return error(log, `Target workbook at ${resourcePath} is not setup to intake data.`, 403, response);
Expand Down
33 changes: 22 additions & 11 deletions test/forms-pipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Form POST Requests', () => {
new PipelineResponse('', {
headers: {
'x-amz-meta-x-source-location': 'foo-bar',
'x-amz-meta-x-sheet-names': 'helix-default,incoming',
'x-amz-meta-x-sheet-names': 'helix-default, incoming',
},
}),
),
Expand All @@ -108,16 +108,27 @@ describe('Form POST Requests', () => {
it('successful POST Request w/Body and Custom Headers', async () => {
const req = new PipelineRequest('https://helix-pipeline.com/', defaultRequest);
const state = new PipelineState(defaultState());
state.s3Loader.reply(
'helix-content-bus',
'foobus/live/metadata.json',
new PipelineResponse(JSON.stringify({
data: [
{ 'url': '/**', 'access-control-allow-origin': '*' },
{ 'url': '/**', 'content-security-policy': "default-src 'self'" },
],
})),
);
state.s3Loader
.reply(
'helix-content-bus',
'foobus/live/metadata.json',
new PipelineResponse(JSON.stringify({
data: [
{ 'url': '/**', 'access-control-allow-origin': '*' },
{ 'url': '/**', 'content-security-policy': "default-src 'self'" },
],
})),
)
.reply(
'helix-content-bus',
'foobus/live/somepath/workbook.json',
new PipelineResponse('', {
headers: {
'x-amz-meta-x-source-location': 'foo-bar',
'x-amz-meta-x-sheet-names': 'helix-default,incoming', // without comma after space
},
}),
);

const resp = await formsPipe(state, req);
assert.strictEqual(resp.status, 201);
Expand Down

0 comments on commit 24a1542

Please sign in to comment.