Skip to content

Commit

Permalink
fix: use deterministic date-time string sampler (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
frodeaa authored May 14, 2020
1 parent 9d6c312 commit f4e0782
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/samplers/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function passwordSample(min, max) {
}

function commonDateTimeSample(min, max, omitTime) {
let res = toRFCDateTime(new Date(), omitTime, false);
let res = toRFCDateTime(new Date("2019-08-24T14:15:22.123Z"), omitTime, false);
if (res.length < min) {
throw new Error(`Using minLength = ${min} is incorrect with format "date-time"`);
}
Expand Down
10 changes: 10 additions & 0 deletions test/unit/string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ describe('sampleString', () => {
expect(Date.parse(res)).not.to.be.NaN;
});

it('should return deterministic date string for format date', () => {
res = sampleString({format: 'date'});
expect(res).to.equal("2019-08-24");
});

it('should return date string for format date', () => {
res = sampleString({format: 'date-time'});
expect(Date.parse(res)).not.to.be.NaN;
});

it('should return deterministic date string for format date-time', () => {
res = sampleString({format: 'date-time'});
expect(res).to.equal("2019-08-24T14:15:22Z");
});

it('should throw if incorrect maxLength applied to date-time', () => {
res = () => sampleString({format: 'date-time', maxLength: 5});
expect(res).to.throw();
Expand Down

0 comments on commit f4e0782

Please sign in to comment.