Skip to content

Commit

Permalink
support default headers on top level
Browse files Browse the repository at this point in the history
  • Loading branch information
knuthelv committed Nov 10, 2022
1 parent 2c1c7dd commit d9be47d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/scenario-algorithm.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function toScenario(input, globalReplace, replaceRule = {}, scenarioExecutionNum
headers: toHeaders(
interactionTemplate.request?.headerTemplateFile,
interactionTemplate.request?.headers,
input?.headerTemplateFile?.[toTechnology(interaction.technology)] || input?.headerTemplateFile
input?.headerTemplateFile?.[toTechnology(interaction.technology)] || input?.headerTemplateFile || input?.headers
)
},
responseTemplate: {
Expand Down
30 changes: 2 additions & 28 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {readFileSync, writeFile} from "https://deno.land/std@0.156.0/node/fs.ts";
import { readFileSync } from "https://deno.land/std@0.156.0/node/fs.ts"

function randomIban(countryCode, technicalOrgNum) {
return countryCode + randomInteger(20, 90) + technicalOrgNum + randomInteger(1000000, 9999999)
Expand All @@ -8,17 +8,13 @@ function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min)) + min
}

function uuid() {
return crypto.randomUUID()
}

function generateReplace(generate, config) {
const filtered = generate
.map(value => {
switch (value) {
case 'uuid':
return {
uuid: uuid()
uuid: crypto.randomUUID()
}
case 'iban':
return {
Expand Down Expand Up @@ -129,14 +125,6 @@ function toPath(name) {
export default {
setWorkingDirectory: dir => workingDirectory = dir || '.',

saveToFile: (fileName, data) => {
writeFile(fileName, JSON.stringify(data, null, 2), 'utf8', (err) => {
if (err) {
throw 'Failed to save' + err
}
})
},

openFile: fileName => {
return JSON.parse(readFileSync(toPath(fileName)).toString())
},
Expand All @@ -152,19 +140,5 @@ export default {
return generateReplace(generate || [], config || {})
},

flattenInputArray: array => array
.reduce((a, b) => {
if (Array.isArray(a) && Array.isArray(b)) {
return [...a, ...b]
}
else if (Array.isArray(a)) {
return [...a, b]
}
else if (Array.isArray(b)) {
return [a, ...b]
}
return [a, b]
}),

inputReplacesToJson: csv => inputReplacesToJson(csv)
}

0 comments on commit d9be47d

Please sign in to comment.