Summary
When calling updateTest with more than one group, only the last group is saved on the test. No error is thrown, so it fails silently.
Cause
In lib/api.js, form-encoded request bodies are built with querystring.stringify(flattenObject(...)). flattenObject only recurses into plain objects, not arrays:
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
Object.assign(flattened, flattenObject(value, newKey));
} else {
flattened[newKey] = value; // arrays land here
}
So { groups: ['a', 'b'] } becomes querystring.stringify({ groups: ['a', 'b'] }) → groups=a&groups=b (repeated key, no []).
The TestingBot API parses params with Rack, which collapses repeated bracket-less keys to the last value:
groups[]=a&groups[]=b => {"groups"=>["a", "b"]} # what the server expects
groups=a&groups=b => {"groups"=>"b"} # what this client sends -> only "b" kept
Expected
Multiple groups should all be attached, i.e. the client should emit groups[]=a&groups[]=b, matching the official Java client (TestingbotREST.java), which does:
if (entry.getKey().equals("groups")) {
for (int i = 0; i < ((List) entry.getValue()).size(); i++) {
nameValuePairs.add(new BasicNameValuePair("groups[]", ((List) entry.getValue()).get(i).toString()));
}
}
Suggested fix
Encode array values with []-suffixed repeated keys in flattenObject (or special-case groups), so an array serializes to groups[]=a&groups[]=b.
Note
The server now accepts both a comma-separated string and an array for groups, so single-group calls are unaffected. This issue only impacts calls that pass 2+ groups.
Summary
When calling
updateTestwith more than one group, only the last group is saved on the test. No error is thrown, so it fails silently.Cause
In
lib/api.js, form-encoded request bodies are built withquerystring.stringify(flattenObject(...)).flattenObjectonly recurses into plain objects, not arrays:So
{ groups: ['a', 'b'] }becomesquerystring.stringify({ groups: ['a', 'b'] })→groups=a&groups=b(repeated key, no[]).The TestingBot API parses params with Rack, which collapses repeated bracket-less keys to the last value:
Expected
Multiple groups should all be attached, i.e. the client should emit
groups[]=a&groups[]=b, matching the official Java client (TestingbotREST.java), which does:Suggested fix
Encode array values with
[]-suffixed repeated keys inflattenObject(or special-casegroups), so an array serializes togroups[]=a&groups[]=b.Note
The server now accepts both a comma-separated string and an array for
groups, so single-group calls are unaffected. This issue only impacts calls that pass 2+ groups.