-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathjs_key_encoding_test.dart
More file actions
79 lines (68 loc) · 1.96 KB
/
js_key_encoding_test.dart
File metadata and controls
79 lines (68 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import 'dart:convert';
import 'package:file/local.dart';
import 'package:sqlite3/common.dart';
import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite3_test/sqlite3_test.dart';
import 'package:test/test.dart';
import 'utils/native_test_utils.dart';
void main() {
// Needs an unique name per test file to avoid concurrency issues
final vfs = TestSqliteFileSystem(
fs: const LocalFileSystem(), name: 'js-key-encoding-test-vfs');
late CommonDatabase db;
setUpAll(() {
loadExtension();
sqlite3.registerVirtualFileSystem(vfs, makeDefault: false);
});
tearDownAll(() => sqlite3.unregisterVirtualFileSystem(vfs));
setUp(() async {
db = openTestDatabase(vfs: vfs)
..select('select powersync_init();')
..select('select powersync_replace_schema(?)', [json.encode(_schema)]);
});
tearDown(() {
db.dispose();
});
test('can fix JS key encoding', () {
db.execute('insert into powersync_operations (op, data) VALUES (?, ?);', [
'save',
json.encode({
'buckets': [
{
'bucket': 'a',
'data': [
{
'op_id': '1',
'op': 'PUT',
'object_type': 'items',
'object_id': '1',
'subkey': json.encode('subkey'),
'checksum': 0,
'data': {'col': 'a'},
}
],
}
],
})
]);
db.execute('INSERT INTO powersync_operations(op, data) VALUES (?, ?)',
['sync_local', null]);
var [row] = db.select('select * from ps_oplog');
expect(row['key'], 'items/1/"subkey"');
// Apply migration
db.execute(
'UPDATE ps_oplog SET key = powersync_remove_duplicate_key_encoding(key);');
[row] = db.select('select * from ps_oplog');
expect(row['key'], 'items/1/subkey');
});
}
const _schema = {
'tables': [
{
'name': 'items',
'columns': [
{'name': 'col', 'type': 'text'}
],
}
]
};