Skip to content

Commit 0a918fb

Browse files
committed
feat: upgrade surrealdb_js package and fix all failed tests
1 parent 1ba2ff9 commit 0a918fb

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

integration_test/patch_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:surrealdb_wasm/surrealdb_wasm.dart';
55
void main({bool wasm = false}) {
66
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
77

8-
final db = SurrealWasmMutex.getInstance();
8+
final db = SurrealWasm.getInstance();
99

1010
setUpAll(() async {
1111
if (wasm) {

integration_test/surrealdb_wasm_test.dart

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import 'dart:typed_data';
33

44
import 'package:flutter_test/flutter_test.dart';
55
import 'package:integration_test/integration_test.dart';
6+
import 'package:surrealdb_js/surrealdb_js.dart';
67
import 'package:surrealdb_wasm/surrealdb_wasm.dart';
78

89
void main({bool wasm = false}) {
910
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1011

11-
final db = SurrealWasmMutex.getInstance();
12+
final db = SurrealWasm.getInstance();
1213
//Tests run with local SurrealDB instance started with the command below:
1314
//surreal start memory --log trace --allow-all --auth --user root --pass root
1415
setUpAll(() async {
@@ -42,40 +43,46 @@ void main({bool wasm = false}) {
4243
testWidgets('Create a record with datetime field and change it',
4344
(WidgetTester tester) async {
4445
const sql = '''
46+
REMOVE TABLE IF EXISTS document;
4547
DEFINE TABLE document SCHEMALESS;
4648
DEFINE FIELD content ON document TYPE option<string>;
4749
DEFINE FIELD created ON document TYPE datetime;
4850
''';
4951
await db.query(sql);
50-
const created = '2023-10-31T03:19:16.601Z';
52+
final created = DateTime.parse('2023-10-31T03:19:16.601Z');
53+
const converter = JSDateJsonConverter();
5154
final data = {
5255
'content': 'doc 1',
53-
'created': created,
56+
'created': converter.toJson(created),
5457
};
55-
final result =
56-
await db.query('CREATE ONLY document CONTENT ${jsonEncode(data)}');
58+
final result = await db.query(
59+
r'CREATE ONLY document CONTENT $data',
60+
bindings: {'data': data},
61+
);
5762
final doc = Map<String, dynamic>.from(
5863
result! as Map,
5964
);
6065
expect(doc['id'], isNotNull);
61-
expect(doc['created'], equals(DateTime.parse(created)));
66+
expect(doc['created'], equals(created));
6267

63-
const mergedDate = '2023-11-01T03:19:16.601Z';
68+
final mergedDate = DateTime.parse('2023-11-01T03:19:16.601Z');
6469
final mergeData = {
65-
'created': mergedDate,
70+
'created': converter.toJson(mergedDate),
6671
};
6772
final merged = await db.query(
68-
'UPDATE ONLY ${doc['id']} MERGE ${jsonEncode(mergeData)}',
73+
'UPDATE ONLY ${doc['id']} MERGE \$data',
74+
bindings: {'data': mergeData},
6975
);
7076
final mergedDoc = Map<String, dynamic>.from(
7177
merged! as Map,
7278
);
73-
expect(mergedDoc['created'], equals(DateTime.parse(mergedDate)));
79+
expect(mergedDoc['created'], equals(mergedDate));
7480
});
7581

7682
testWidgets('Create a record with bindings param',
7783
(WidgetTester tester) async {
7884
const sql = '''
85+
REMOVE TABLE IF EXISTS bindings;
7986
DEFINE TABLE bindings SCHEMALESS;
8087
DEFINE FIELD file ON bindings TYPE string;
8188
''';
@@ -105,6 +112,7 @@ DEFINE FIELD file ON bindings TYPE string;
105112
testWidgets('Create a record with bytes type field and change it',
106113
(WidgetTester tester) async {
107114
const sql = '''
115+
REMOVE TABLE IF EXISTS documents;
108116
DEFINE TABLE documents SCHEMALESS;
109117
DEFINE FIELD file ON documents TYPE bytes;
110118
''';

integration_test/transaction_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:surrealdb_wasm/surrealdb_wasm.dart';
1010
void main({bool wasm = false}) {
1111
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1212

13-
final db = SurrealWasmMutex.getInstance();
13+
final db = SurrealWasm.getInstance();
1414

1515
setUpAll(() async {
1616
if (wasm) {
@@ -28,7 +28,6 @@ void main({bool wasm = false}) {
2828
(WidgetTester tester) async {
2929
await db.transaction((txn) async {
3030
txn.query('DEFINE TABLE test SCHEMAFULL;');
31-
txn.query('DEFINE FIELD id ON test TYPE record;');
3231
txn.query('DEFINE FIELD name ON test TYPE string;');
3332
txn.query(
3433
r'CREATE test SET name = $name;',

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: surrealdb_wasm
22
description: Flutter SurrealDB WebAssembly(WASM) package
3-
version: 1.0.0-beta.16
3+
version: 1.0.0-beta.22
44
repository: https://github.com/limcheekin/surrealdb_wasm
55

66
environment:
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313
mutex: ^3.1.0
14-
surrealdb_js: ^1.0.0-beta.20+4
14+
surrealdb_js: ^1.0.1+7
1515

1616
dev_dependencies:
1717
flutter_test:

web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</script>
4242
<script type="module">
4343
import { Surreal, StringRecordId } from "/assets/packages/surrealdb_js/assets/js/index.bundled.mjs";
44-
import { surrealdbWasmEngines } from "./assets/wasm/surrealdb/esm.bundled.js";
44+
import { surrealdbWasmEngines } from "./assets/wasm/surrealdb/index.bundled.js";
4545

4646
// expose the type to the global scope
4747
globalThis.SurrealJS = Surreal;

0 commit comments

Comments
 (0)