Skip to content

Commit e689eac

Browse files
committed
chore: normalize uuid in tests snapshots
1 parent b3fe735 commit e689eac

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

test/server/query.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { expect, test } from 'vitest'
2-
import { app } from './utils'
2+
import { app, normalizeUuids } from './utils'
33

44
test('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
`)

test/server/typegen.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff 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

test/server/utils.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
import { build as buildApp } from '../../src/server/app'
22

33
export 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-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-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+
}

0 commit comments

Comments
 (0)