Skip to content

Commit 228af05

Browse files
committed
Migrate tests
1 parent 438b6e9 commit 228af05

File tree

2 files changed

+37
-74
lines changed

2 files changed

+37
-74
lines changed

modules/module-postgres/test/src/wal_stream.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,42 @@ bucket_definitions:
325325
}
326326
});
327327

328+
test('old date format', async () => {
329+
await using context = await WalStreamTestContext.open(factory);
330+
await context.updateSyncRules(BASIC_SYNC_RULES);
331+
332+
const { pool } = context;
333+
await pool.query(`DROP TABLE IF EXISTS test_data`);
334+
await pool.query(`CREATE TABLE test_data(id text primary key, description timestamptz);`);
335+
336+
await context.initializeReplication();
337+
await pool.query(`INSERT INTO test_data(id, description) VALUES ('t1', '2025-09-10 15:17:14+02')`);
338+
339+
let data = await context.getBucketData('global[]');
340+
expect(data).toMatchObject([putOp('test_data', { id: 't1', description: '2025-09-10 13:17:14Z' })]);
341+
});
342+
343+
test('new date format', async () => {
344+
await using context = await WalStreamTestContext.open(factory);
345+
await context.updateSyncRules(`
346+
streams:
347+
stream:
348+
query: SELECT id, * FROM "test_data"
349+
350+
config:
351+
edition: 2
352+
`);
353+
const { pool } = context;
354+
await pool.query(`DROP TABLE IF EXISTS test_data`);
355+
await pool.query(`CREATE TABLE test_data(id text primary key, description timestamptz);`);
356+
357+
await context.initializeReplication();
358+
await pool.query(`INSERT INTO test_data(id, description) VALUES ('t1', '2025-09-10 15:17:14+02')`);
359+
360+
const data = await context.getBucketData('1#stream|0[]');
361+
expect(data).toMatchObject([putOp('test_data', { id: 't1', description: '2025-09-10T13:17:14.000000Z' })]);
362+
});
363+
328364
test('custom types', async () => {
329365
await using context = await WalStreamTestContext.open(factory);
330366

packages/service-core-tests/src/tests/register-data-storage-data-tests.ts

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
BucketDataBatchOptions,
3-
getUuidReplicaIdentityBson,
4-
OplogEntry,
5-
SaveOptions,
6-
storage
7-
} from '@powersync/service-core';
8-
import { DateTimeValue } from '@powersync/service-sync-rules';
1+
import { BucketDataBatchOptions, getUuidReplicaIdentityBson, OplogEntry, storage } from '@powersync/service-core';
92
import { describe, expect, test } from 'vitest';
103
import * as test_utils from '../test-utils/test-utils-index.js';
114
import { TEST_TABLE } from './util.js';
@@ -1137,72 +1130,6 @@ bucket_definitions:
11371130
expect(checkpoint2).toBeGreaterThan(checkpoint1);
11381131
});
11391132

1140-
test('data with custom types', async () => {
1141-
await using factory = await generateStorageFactory();
1142-
const testValue = {
1143-
sourceTable: TEST_TABLE,
1144-
tag: storage.SaveOperationTag.INSERT,
1145-
after: {
1146-
id: 't1',
1147-
description: new DateTimeValue('2025-08-28T11:30:00')
1148-
},
1149-
afterReplicaId: test_utils.rid('t1')
1150-
} satisfies SaveOptions;
1151-
1152-
{
1153-
// First, deploy old sync rules and row with date time value
1154-
const syncRules = await factory.updateSyncRules({
1155-
content: `
1156-
bucket_definitions:
1157-
global:
1158-
data:
1159-
- SELECT id, description FROM test
1160-
`
1161-
});
1162-
const bucketStorage = factory.getInstance(syncRules);
1163-
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
1164-
await batch.save(testValue);
1165-
await batch.commit('1/1');
1166-
});
1167-
1168-
const { checkpoint } = await bucketStorage.getCheckpoint();
1169-
const batch = await test_utils.fromAsync(
1170-
bucketStorage.getBucketDataBatch(checkpoint, new Map([['global[]', 0n]]))
1171-
);
1172-
expect(batch[0].chunkData.data).toMatchObject([
1173-
{
1174-
data: '{"id":"t1","description":"2025-08-28 11:30:00"}'
1175-
}
1176-
]);
1177-
}
1178-
1179-
const syncRules = await factory.updateSyncRules({
1180-
content: `
1181-
bucket_definitions:
1182-
global:
1183-
data:
1184-
- SELECT id, description FROM test
1185-
1186-
config:
1187-
edition: 2
1188-
`
1189-
});
1190-
const bucketStorage = factory.getInstance(syncRules);
1191-
await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
1192-
await batch.save(testValue);
1193-
await batch.commit('1/2');
1194-
});
1195-
const { checkpoint } = await bucketStorage.getCheckpoint();
1196-
const batch = await test_utils.fromAsync(
1197-
bucketStorage.getBucketDataBatch(checkpoint, new Map([['2#global[]', 0n]]))
1198-
);
1199-
expect(batch[0].chunkData.data).toMatchObject([
1200-
{
1201-
data: '{"id":"t1","description":"2025-08-28T11:30:00"}'
1202-
}
1203-
]);
1204-
});
1205-
12061133
test('unchanged checksums', async () => {
12071134
await using factory = await generateStorageFactory();
12081135
const syncRules = await factory.updateSyncRules({

0 commit comments

Comments
 (0)