Open gaboesquivel opened 7 years ago
Thanks for the PR. good catch.
Wondering if simply starting the min=1
would solve this issue or not?
for (; arr.length < max; min++) { arr.push(mock(items)); }
^ here the idea of min++ has no effect on the iteration.
Starting min=1
would solve both min and max use case I believe.
It won't pass the tests if min=1
and max=1
and for(; min < max; min++)
nor (; min <= max; min++)
it needs tests for maxItems
use case, I don't have much time tho.
this seems more accurate
function arrayMock(schema) {
var items = schema.items;
var arr = [];
if (items) {
let min = schema.minItems || 1;
let max = schema.maxItems || 2;
// max needs to be iqual or greater than min
max = ( min > max)? min : max;
while ( arr.length < max) {
arr.push(mock(items));
}
}
return arr;
}
If max default is 1 the tests will fail
27 passing (4s)
2 failing
1) Parameter Mock generator should generate parameter mock for path /user/createWithArray:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
2) Request Mock generator should generate request mock for path /user/createWithArray:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
it seems these tests expect 2 items in the response, but max=1
when executed.
That's why max default has to be 2
Assumptions:
I see, lemme fix the tests to look for only one item by default.
@gaboesquivel - #17 - added these additional checks and boundary conditions, If makes sense, can you help verify? Also fixed the test case and added additional test cases.
there's bug were arrayMock generates 1 item more than the specified in maxItems this solves this problem.