File tree Expand file tree Collapse file tree 3 files changed +44
-18
lines changed
Expand file tree Collapse file tree 3 files changed +44
-18
lines changed Original file line number Diff line number Diff line change 11import { expect , test } from 'vitest'
2- import { app } from './utils'
2+ import { app , normalizeUuids } from './utils'
33
44test ( 'query' , async ( ) => {
55 const res = await app . inject ( {
66 method : 'POST' ,
77 path : '/query' ,
88 payload : { query : 'SELECT * FROM users' } ,
99 } )
10- expect ( res . json ( ) ) . toMatchInlineSnapshot ( `
10+ expect ( normalizeUuids ( res . json ( ) ) ) . toMatchInlineSnapshot ( `
1111 [
1212 {
1313 "decimal": null,
1414 "id": 1,
1515 "name": "Joe Bloggs",
1616 "status": "ACTIVE",
17- "user_uuid": "0db4bf5e-98df-4ecf-aa2c-a077323c53b1 ",
17+ "user_uuid": "00000000-0000-0000-0000-000000000000 ",
1818 },
1919 {
2020 "decimal": null,
2121 "id": 2,
2222 "name": "Jane Doe",
2323 "status": "ACTIVE",
24- "user_uuid": "eda00f72-451f-419e-8ede-b7873ad6890c ",
24+ "user_uuid": "00000000-0000-0000-0000-000000000000 ",
2525 },
2626 ]
2727 ` )
@@ -760,14 +760,14 @@ test('parameter binding with positional parameters', async () => {
760760 parameters : [ 1 , 'ACTIVE' ] ,
761761 } ,
762762 } )
763- expect ( res . json ( ) ) . toMatchInlineSnapshot ( `
763+ expect ( normalizeUuids ( res . json ( ) ) ) . toMatchInlineSnapshot ( `
764764 [
765765 {
766766 "decimal": null,
767767 "id": 1,
768768 "name": "Joe Bloggs",
769769 "status": "ACTIVE",
770- "user_uuid": "0db4bf5e-98df-4ecf-aa2c-a077323c53b1 ",
770+ "user_uuid": "00000000-0000-0000-0000-000000000000 ",
771771 },
772772 ]
773773 ` )
Original file line number Diff line number Diff line change @@ -6437,18 +6437,18 @@ test('typegen: python', async () => {
64376437 expect ( body ) . toMatchInlineSnapshot ( `
64386438 "from __future__ import annotations
64396439
6440- import datetime
6441- import uuid
6442- from typing import (
6443- Annotated,
6444- Any,
6445- List,
6446- Literal,
6447- NotRequired,
6448- Optional,
6449- TypeAlias,
6450- TypedDict,
6451- )
6440+ import datetime
6441+ import uuid
6442+ from typing import (
6443+ Annotated,
6444+ Any,
6445+ List,
6446+ Literal,
6447+ NotRequired,
6448+ Optional,
6449+ TypeAlias,
6450+ TypedDict,
6451+ )
64526452
64536453 from pydantic import BaseModel, Field, Json
64546454
Original file line number Diff line number Diff line change 11import { build as buildApp } from '../../src/server/app'
22
33export const app = buildApp ( )
4+
5+ /**
6+ * Normalizes UUIDs in test data to make snapshots resilient to UUID changes.
7+ * Replaces all UUID strings with a consistent placeholder.
8+ */
9+ export function normalizeUuids ( data : unknown ) : unknown {
10+ const uuidRegex = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i
11+
12+ if ( typeof data === 'string' && uuidRegex . test ( data ) ) {
13+ return '00000000-0000-0000-0000-000000000000'
14+ }
15+
16+ if ( Array . isArray ( data ) ) {
17+ return data . map ( normalizeUuids )
18+ }
19+
20+ if ( data !== null && typeof data === 'object' ) {
21+ const normalized : Record < string , unknown > = { }
22+ for ( const [ key , value ] of Object . entries ( data ) ) {
23+ normalized [ key ] = normalizeUuids ( value )
24+ }
25+ return normalized
26+ }
27+
28+ return data
29+ }
You can’t perform that action at this time.
0 commit comments