Skip to content

Commit

Permalink
Merge pull request #29 from loadimpact/fix/postData-param
Browse files Browse the repository at this point in the history
Fix/post data param
  • Loading branch information
allansson authored Mar 30, 2020
2 parents 95900f0 + 96c5ae8 commit b98ed39
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
74 changes: 49 additions & 25 deletions example/params.har
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
{
"log": {
"entries": [
{
"index": 0,
"request": {
"method": "POST",
"url": "http://test.loadimpact.com/path",
"httpVersion": "HTTP/1.1",
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"params": [
{
"name": "login",
"value": "admin"
},
{
"name": "password",
"value": "123"
}
]
}
}
}
]
}
"log": {
"entries": [
{
"variables": [
{
"name": "userName",
"type": 0,
"expression": "user.name"
},
{
"name": "userID",
"type": 0,
"expression": "user.id"
}
],
"request": {
"method": "GET",
"url": "http://test.loadimpact.com/path"
}
},
{
"request": {
"method": "POST",
"url": "http://test.loadimpact.com/path",
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"params": [
{
"name": "login",
"value": "admin"
},
{
"name": "password",
"value": ""
},
{
"name": "${userName}",
"value": ""
},
{
"name": "id",
"value": "${userID}"
}
]
}
}
}
]
}
}
5 changes: 5 additions & 0 deletions src/aid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function emptyObject (value) {
return !Object.keys(value).length
}

function isString (x) {
return Object.prototype.toString.call(x) === '[object String]'
}

// Produce valid encoding not used by enumeration
function extrinsic (enumeration) {
return Math.max(...Object.values(enumeration)) + 1
Expand Down Expand Up @@ -42,6 +46,7 @@ module.exports = {
empty,
isBlacklistedHeader,
emptyObject,
isString,
extrinsic,
nought
}
4 changes: 3 additions & 1 deletion src/parse/param.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { isString } = require('../aid')

function param (node, spec) {
const item = {}
if (node.value) {
if (isString(node.value)) {
item.value = node.value
}
if (node.fileName) {
Expand Down
3 changes: 2 additions & 1 deletion src/render/post/url/singular.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isString } = require('../../../aid')
const object = require('../../object')
const text = require('../../text')

Expand All @@ -13,7 +14,7 @@ function singular (params) {

function entry (name, item) {
const result = { name }
if (item.value) {
if (isString(item.value)) {
result.value = text(item.value)
}
if (item.comment || item.contentType || item.fileName) {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/parse/param.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ test('value', t => {
)
})

test('empty value', t => {
const spec = makeSpec()
param({ name: 'search', value: '' }, spec)
t.deepEqual(
spec,
new Map()
.set('search', new Set([ { value: '' } ]))
)
})

test('fileName', t => {
const spec = makeSpec()
param({ name: 'data', fileName: 'data.csv' }, spec)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/render/post/url/singular.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ test.serial('value', t => {
])
})

test.serial('empty value', t => {
text.returns('""')
const spec = new Map()
.set('search', new Set([ { value: '' } ]))
singular(spec)
t.deepEqual(object.firstCall.args[0], [
{ name: 'search', value: '""' }
])
})

test.serial('comment', t => {
const spec = new Map()
.set('session', new Set([ { comment: 'Start fresh session' } ]))
Expand Down

0 comments on commit b98ed39

Please sign in to comment.