Skip to content

Commit c9cc345

Browse files
committed
fix(postgrest): stabilize time-based inline snapshots
1 parent 193729f commit c9cc345

File tree

1 file changed

+26
-48
lines changed

1 file changed

+26
-48
lines changed

packages/core/postgrest-js/test/embeded_functions_join.test.ts

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,36 +1229,19 @@ describe('embeded functions select', () => {
12291229
// test select the created_ago embeded function
12301230
test('select the created_ago embeded function', async () => {
12311231
const res = await postgrest.from('users_audit').select('id, created_ago')
1232-
expect(res).toMatchInlineSnapshot(`
1233-
Object {
1234-
"count": null,
1235-
"data": Array [
1236-
Object {
1237-
"created_ago": 7,
1238-
"id": 1,
1239-
},
1240-
Object {
1241-
"created_ago": 7,
1242-
"id": 2,
1243-
},
1244-
Object {
1245-
"created_ago": 7,
1246-
"id": 3,
1247-
},
1248-
Object {
1249-
"created_ago": 7,
1250-
"id": 4,
1251-
},
1252-
Object {
1253-
"created_ago": 7,
1254-
"id": 5,
1255-
},
1256-
],
1257-
"error": null,
1258-
"status": 200,
1259-
"statusText": "OK",
1260-
}
1261-
`)
1232+
// Don't snapshot time-based values - they change daily and cause flaky tests
1233+
expect(res.error).toBeNull()
1234+
expect(res.status).toBe(200)
1235+
expect(res.statusText).toBe('OK')
1236+
expect(res.count).toBeNull()
1237+
expect(res.data).toHaveLength(5)
1238+
// Verify structure of each record
1239+
expect(res.data?.[0]).toMatchObject({
1240+
id: expect.any(Number),
1241+
created_ago: expect.any(Number),
1242+
})
1243+
// Verify time-based value is reasonable
1244+
expect(res.data?.[0].created_ago).toBeGreaterThanOrEqual(0)
12621245
let result: Exclude<typeof res.data, null>
12631246
const ExpectedSchema = z.array(
12641247
z.object({
@@ -1301,24 +1284,19 @@ describe('embeded functions select', () => {
13011284
// Test the days_since_event embeded function over partitioned table
13021285
test('select the days_since_event embeded function over partitioned table', async () => {
13031286
const res = await postgrest.from('events').select('id, days_since_event')
1304-
expect(res).toMatchInlineSnapshot(`
1305-
Object {
1306-
"count": null,
1307-
"data": Array [
1308-
Object {
1309-
"days_since_event": 500,
1310-
"id": 1,
1311-
},
1312-
Object {
1313-
"days_since_event": 222,
1314-
"id": 2,
1315-
},
1316-
],
1317-
"error": null,
1318-
"status": 200,
1319-
"statusText": "OK",
1320-
}
1321-
`)
1287+
// Don't snapshot time-based values - they change daily and cause flaky tests
1288+
expect(res.error).toBeNull()
1289+
expect(res.status).toBe(200)
1290+
expect(res.statusText).toBe('OK')
1291+
expect(res.count).toBeNull()
1292+
expect(res.data).toHaveLength(2)
1293+
// Verify structure of each record
1294+
expect(res.data?.[0]).toMatchObject({
1295+
id: expect.any(Number),
1296+
days_since_event: expect.any(Number),
1297+
})
1298+
// Verify time-based value is reasonable
1299+
expect(res.data?.[0].days_since_event).toBeGreaterThanOrEqual(0)
13221300
let result: Exclude<typeof res.data, null>
13231301
const ExpectedSchema = z.array(
13241302
z.object({

0 commit comments

Comments
 (0)