@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
2
2
import readline from "node:readline" ;
3
3
import * as schema from "src/drizzle/schema" ;
4
4
import type { TestEnvConfig } from "test/envConfigSchema" ;
5
+ import { uuidv7 } from "uuidv7" ;
5
6
import { beforeAll , expect , suite , test , vi } from "vitest" ;
6
7
7
8
let testEnvConfig : TestEnvConfig ;
@@ -72,6 +73,32 @@ suite.concurrent("parseDate", () => {
72
73
} ) ;
73
74
} ) ;
74
75
76
+ suite . concurrent ( "action item ID generation" , ( ) => {
77
+ test . concurrent (
78
+ "should generate new uuidv7 when ID is not 36 characters" ,
79
+ async ( ) => {
80
+ const actionItem = {
81
+ id : "short-id" ,
82
+ assignedAt : "2024-03-14" ,
83
+ completionAt : "2024-03-15" ,
84
+ createdAt : "2024-03-13" ,
85
+ updaterId : "user-123" ,
86
+ } ;
87
+
88
+ const result = {
89
+ ...actionItem ,
90
+ id : actionItem . id . length === 36 ? actionItem . id : uuidv7 ( ) ,
91
+ assignedAt : helpers . parseDate ( actionItem . assignedAt ) ,
92
+ completionAt : helpers . parseDate ( actionItem . completionAt ) ,
93
+ createdAt : helpers . parseDate ( actionItem . createdAt ) ,
94
+ } ;
95
+
96
+ expect ( result . id ) . not . toBe ( "short-id" ) ;
97
+ expect ( result . id . length ) . toBe ( 36 ) ;
98
+ } ,
99
+ ) ;
100
+ } ) ;
101
+
75
102
suite . concurrent ( "askUserToContinue" , ( ) => {
76
103
test . concurrent ( "should resolve to true when user inputs 'y'" , async ( ) => {
77
104
const fakeInterface = {
@@ -256,6 +283,119 @@ suite.concurrent("insertCollections", () => {
256
283
) . rejects . toThrow ( / E r r o r a d d i n g d a t a t o t a b l e s : / ) ;
257
284
} ,
258
285
) ;
286
+
287
+ test . concurrent (
288
+ "should generate new uuidv7 for action items with short IDs" ,
289
+ async ( ) => {
290
+ const userId = uuidv7 ( ) ;
291
+ await helpers . checkAndInsertData (
292
+ schema . usersTable ,
293
+ [
294
+ {
295
+ id : userId ,
296
+ emailAddress :
"[email protected] " ,
297
+ name : "Test User" ,
298
+ passwordHash : "hashed_password_123" ,
299
+ isEmailAddressVerified : true ,
300
+ role : "regular" ,
301
+ createdAt : new Date ( ) ,
302
+ updatedAt : new Date ( ) ,
303
+ } ,
304
+ ] ,
305
+ schema . usersTable . id ,
306
+ 1000 ,
307
+ ) ;
308
+
309
+ const organizationId = "123e4567-e89b-12d3-a456-426614174000" ;
310
+ await helpers . checkAndInsertData (
311
+ schema . organizationsTable ,
312
+ [
313
+ {
314
+ id : organizationId ,
315
+ name : "Test Organizations" ,
316
+ description : "Test organization description" ,
317
+ createdAt : new Date ( ) ,
318
+ updatedAt : new Date ( ) ,
319
+ creatorId : userId ,
320
+ updaterId : userId ,
321
+ isUserRegistrationRequired : false ,
322
+ } ,
323
+ ] ,
324
+ schema . organizationsTable . id ,
325
+ 1000 ,
326
+ ) ;
327
+
328
+ const categoryId = "123e4567-e89b-12d3-a456-426614174001" ;
329
+ await helpers . checkAndInsertData (
330
+ schema . actionCategoriesTable ,
331
+ [
332
+ {
333
+ id : categoryId ,
334
+ name : "Test Category" ,
335
+ description : "Test category description" ,
336
+ createdAt : new Date ( ) ,
337
+ updatedAt : new Date ( ) ,
338
+ creatorId : userId ,
339
+ updaterId : userId ,
340
+ organizationId : organizationId ,
341
+ isDisabled : false ,
342
+ } ,
343
+ ] ,
344
+ schema . actionCategoriesTable . id ,
345
+ 1000 ,
346
+ ) ;
347
+ const mockActionItem = {
348
+ id : "short-id" ,
349
+ assignedAt : "2024-03-14" ,
350
+ completionAt : "2024-03-15" ,
351
+ createdAt : "2024-03-13" ,
352
+ updatedAt : "2024-03-13" ,
353
+ preCompletionNotes : "Test notes" ,
354
+ postCompletionNotes : "" ,
355
+ organizationId : organizationId ,
356
+ categoryId : categoryId ,
357
+ eventId : null ,
358
+ assigneeId : userId ,
359
+ creatorId : userId ,
360
+ updaterId : userId ,
361
+ isCompleted : false ,
362
+ } ;
363
+
364
+ let capturedData : ( typeof schema . actionsTable . $inferInsert ) [ ] = [ ] ;
365
+ const checkAndInsertDataSpy = vi
366
+ . spyOn ( helpers , "checkAndInsertData" )
367
+ . mockImplementation ( ( table , data ) => {
368
+ capturedData = data as ( typeof schema . actionsTable . $inferInsert ) [ ] ;
369
+ return Promise . resolve ( true ) ;
370
+ } ) ;
371
+
372
+ const actionItemWithUuid = {
373
+ ...mockActionItem ,
374
+ id : uuidv7 ( ) ,
375
+ assignedAt : helpers . parseDate ( mockActionItem . assignedAt ) ,
376
+ completionAt : helpers . parseDate ( mockActionItem . completionAt ) ,
377
+ createdAt : helpers . parseDate ( mockActionItem . createdAt ) ,
378
+ updatedAt : helpers . parseDate ( mockActionItem . updatedAt ) ,
379
+ } ;
380
+
381
+ await helpers . checkAndInsertData (
382
+ schema . actionsTable ,
383
+ [ actionItemWithUuid ] ,
384
+ schema . actionsTable . id ,
385
+ 1000 ,
386
+ ) ;
387
+
388
+ expect ( capturedData . length ) . toBeGreaterThan ( 0 ) ;
389
+ const firstItem = capturedData [ 0 ] ;
390
+ if ( ! firstItem || ! firstItem . id ) {
391
+ throw new Error ( "Expected action item with ID" ) ;
392
+ }
393
+ expect ( firstItem . id ) . not . toBe ( "short-id" ) ;
394
+ expect ( firstItem . id . length ) . toBe ( 36 ) ;
395
+
396
+ checkAndInsertDataSpy . mockRestore ( ) ;
397
+ } ,
398
+ ) ;
259
399
} ) ;
260
400
261
401
suite . concurrent ( "checkDataSize integration test" , ( ) => {
0 commit comments