From 9eb076a0a36bd86958f220328aaf2bc54bf9f1c4 Mon Sep 17 00:00:00 2001 From: robinpokorny Date: Fri, 14 Jun 2024 15:09:08 +0200 Subject: [PATCH] test: add failing tests for msecs in v7 --- test/unit/v7.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/unit/v7.test.js b/test/unit/v7.test.js index aa2b5430..c754bb82 100644 --- a/test/unit/v7.test.js +++ b/test/unit/v7.test.js @@ -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 = [ @@ -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( @@ -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/); + }); });