Skip to content

Commit

Permalink
test: add failing tests for msecs in v7
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpokorny committed Jun 14, 2024
1 parent 5388bbb commit 9eb076a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/unit/v7.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import v7 from '../../src/v7.js';

describe('v7', () => {
const msecsFixture = 1645557742000;
const msecsFutureFixture = Date.UTC('2100');
const seqFixture = 0x661b189b;

const randomBytesFixture = [
Expand Down Expand Up @@ -63,6 +64,26 @@ describe('v7', () => {
assert.strictEqual(id.indexOf('017f22e2'), 0);
});

test('explicit options.msecs after a standard call randomises seq', () => {
const id1 = v7();
const id2 = v7({
msecs: msecsFixture,
});

assert.notDeepStrictEqual(id1.slice(14, 23), id2.slice(14, 23));
});

test('providing current options.msecs after past options.msecs works', () => {
const id1 = v7({
msecs: msecsFixture,
});
const id2 = v7({
msecs: Date.now(),
});

assert.notDeepStrictEqual(id1.slice(0, 13), id2.slice(0, 13));
});

test('fills one UUID into a buffer as expected', () => {
const buffer = [];
const result = v7(
Expand Down Expand Up @@ -169,4 +190,11 @@ describe('v7', () => {

assert(uuid.indexOf('fff') !== 15);
});

test('explicit options.msecs in the future produces expected result', () => {
const id = v7({
msecs: msecsFutureFixture,
});
assert.match(id, /^3bb2cc3/);
});
});

0 comments on commit 9eb076a

Please sign in to comment.