11import { describe , expect , it } from "vitest" ;
2- import { monotonicFactory , ulid } from "../../" ;
2+ import { monotonicFactory , ulid , ULIDFactory } from "../../" ;
33
44const ULID_REXP = / ^ [ 0 - 7 ] [ 0 - 9 a - h j k m n p - t v - z A - H J K M N P - T V - Z ] { 25 } $ / ;
55
66describe ( "monotonicFactory" , ( ) => {
7+ function stubbedPrng ( ) {
8+ return 0.96
9+ }
10+
711 it ( "creates a factory" , ( ) => {
812 const factory = monotonicFactory ( ) ;
913 expect ( factory ) . toBeTypeOf ( "function" ) ;
@@ -15,6 +19,51 @@ describe("monotonicFactory", () => {
1519 const id = factory ( ) ;
1620 expect ( id ) . toMatch ( ULID_REXP ) ;
1721 } ) ;
22+
23+ describe ( "during single point in time" , function ( ) {
24+ const SEED_TIME = 1469918176385 ;
25+ const stubbedUlid : ULIDFactory = monotonicFactory ( stubbedPrng ) ;
26+
27+ it ( "first call" , function ( ) {
28+ expect ( stubbedUlid ( SEED_TIME ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYYY" ) ;
29+ } )
30+
31+ it ( "second call" , function ( ) {
32+ expect ( stubbedUlid ( SEED_TIME ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYYZ" ) ;
33+ } )
34+
35+ it ( "third call" , function ( ) {
36+ expect ( stubbedUlid ( SEED_TIME ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYZ0" ) ;
37+ } )
38+
39+ it ( "fourth call" , function ( ) {
40+ expect ( stubbedUlid ( SEED_TIME ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYZ1" ) ;
41+ } )
42+ } )
43+
44+ describe ( "with specific seedTime" , function ( ) {
45+ const stubbedUlid : ULIDFactory = monotonicFactory ( stubbedPrng ) ;
46+
47+ it ( "first call" , function ( ) {
48+ expect ( stubbedUlid ( 1469918176385 ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYYY" ) ;
49+ } )
50+
51+ it ( "second call with the same" , function ( ) {
52+ expect ( stubbedUlid ( 1469918176385 ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYYZ" ) ;
53+ } )
54+
55+ it ( "third call with less than" , function ( ) {
56+ expect ( stubbedUlid ( 100000000 ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYZ0" ) ;
57+ } )
58+
59+ it ( "fourth call with even more less than" , function ( ) {
60+ expect ( stubbedUlid ( 10000 ) ) . to . equal ( "01ARYZ6S41YYYYYYYYYYYYYYZ1" ) ;
61+ } )
62+
63+ it ( "fifth call with 1 greater than" , function ( ) {
64+ expect ( stubbedUlid ( 1469918176386 ) ) . to . equal ( "01ARYZ6S42YYYYYYYYYYYYYYYY" ) ;
65+ } )
66+ } ) ;
1867 } ) ;
1968} ) ;
2069
0 commit comments