Skip to content

Commit 00d30cd

Browse files
committed
fix: all broken integration tests due to api changes
1 parent 2373913 commit 00d30cd

File tree

4 files changed

+49
-47
lines changed

4 files changed

+49
-47
lines changed

integration_test/surrealdb_wasm_test.dart

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ SIGNIN (
3232
},
3333
);
3434
*/
35-
await db.use(ns: 'surreal', db: 'surreal');
35+
await db.use(namespace: 'surreal', database: 'surreal');
3636
});
3737

38-
tearDown(() {
39-
//db.dispose();
38+
tearDown(() async {
39+
await db.delete('person'); // delete all
4040
});
4141

4242
testWidgets('Verify the current namespace', (WidgetTester tester) async {
43-
final results = await db.query('INFO FOR NS');
44-
final result = Map<String, dynamic>.from(results! as Map);
43+
final results = (await db.query('INFO FOR NS'))! as List;
44+
final result = Map<String, dynamic>.from(results.first as Map);
4545
expect(
4646
result['databases'],
4747
isEmpty, // nothing had been created
@@ -54,8 +54,8 @@ SIGNIN (
5454
'name': 'Tobie',
5555
'settings': {'active': true, 'marketing': true},
5656
};
57-
final result = await db.create('person', data);
58-
final tobie = Map<String, dynamic>.from(result! as Map);
57+
final results = (await db.create('person', data))! as List;
58+
final tobie = Map<String, dynamic>.from(results.first as Map);
5959
expect(tobie['id'], isNotNull);
6060
});
6161

@@ -72,10 +72,10 @@ DEFINE FIELD created ON document TYPE datetime;
7272
'content': 'doc 1',
7373
'created': created,
7474
};
75-
final result =
76-
await db.query('CREATE ONLY document CONTENT ${jsonEncode(data)}');
75+
final results = (await db
76+
.query('CREATE ONLY document CONTENT ${jsonEncode(data)}'))! as List;
7777
final doc = Map<String, dynamic>.from(
78-
result! as Map,
78+
results.first as Map,
7979
);
8080
expect(doc['id'], isNotNull);
8181
expect(doc['created'], equals(created));
@@ -84,11 +84,11 @@ DEFINE FIELD created ON document TYPE datetime;
8484
final mergeData = {
8585
'created': mergedDate,
8686
};
87-
final merged = await db.query(
87+
final merged = (await db.query(
8888
'UPDATE ONLY ${doc['id']} MERGE ${jsonEncode(mergeData)}',
89-
);
89+
))! as List;
9090
final mergedDoc = Map<String, dynamic>.from(
91-
merged! as Map,
91+
merged.first as Map,
9292
);
9393
expect(mergedDoc['created'], equals(mergedDate));
9494
});
@@ -99,12 +99,13 @@ DEFINE FIELD created ON document TYPE datetime;
9999
'name': 'Tom',
100100
'settings': {'active': true, 'marketing': false},
101101
};
102-
final created = await db.create('person', data);
102+
final created = ((await db.create('person', data))! as List).first;
103103
final tom = Map<String, dynamic>.from(created! as Map);
104104
tom['name'] = 'Tom John';
105105
tom.remove('settings');
106106

107-
final updated = await db.update(tom.remove('id') as String, tom);
107+
final updated =
108+
((await db.update(tom.remove('id') as String, tom))! as List).first;
108109
final updatedTom = Map<String, dynamic>.from(updated! as Map);
109110
expect(updatedTom['name'], equals(tom['name']));
110111
expect(updatedTom['settings'], isNull);
@@ -116,12 +117,13 @@ DEFINE FIELD created ON document TYPE datetime;
116117
'name': 'Tom',
117118
'settings': {'active': true, 'marketing': false},
118119
};
119-
final created = await db.create('person', data);
120+
final created = ((await db.create('person', data))! as List).first;
120121
final tom = Map<String, dynamic>.from(created! as Map);
121122
final mergeData = {
122123
'settings': {'marketing': true},
123124
};
124-
final merged = await db.merge(tom['id'] as String, mergeData);
125+
final merged =
126+
((await db.merge(tom['id'] as String, mergeData))! as List).first;
125127
final mergedTom = Map<String, dynamic>.from(merged! as Map);
126128
final settings = Map<String, dynamic>.from(mergedTom['settings'] as Map);
127129
expect(settings['active'], equals(true));
@@ -134,16 +136,15 @@ DEFINE FIELD created ON document TYPE datetime;
134136
'name': 'Tom',
135137
'settings': {'active': true, 'marketing': false},
136138
};
137-
final created = await db.create('person', data);
139+
final created = ((await db.create('person', data))! as List).first;
138140
final tom = Map<String, dynamic>.from(created! as Map);
139-
final result = await db.select(tom['id'] as String);
141+
final result = ((await db.select(tom['id'] as String))! as List).first;
140142
final selectedTom = Map<String, dynamic>.from(result! as Map);
141143
expect(tom['name'], equals(selectedTom['name']));
142144
});
143145

144146
testWidgets('Execute a SurrealQL query and verify the result',
145147
(WidgetTester tester) async {
146-
await db.delete('person'); // delete all
147148
await db.create(
148149
'person',
149150
{
@@ -159,7 +160,7 @@ DEFINE FIELD created ON document TYPE datetime;
159160
},
160161
);
161162
const sql = 'SELECT * FROM person';
162-
final results = await db.query(sql);
163+
final results = ((await db.query(sql))! as List).first;
163164
final people = results! as List;
164165
expect(people.length, equals(2));
165166
});
@@ -170,12 +171,12 @@ DEFINE FIELD created ON document TYPE datetime;
170171
'name': 'Tom',
171172
'settings': {'active': true, 'marketing': false},
172173
};
173-
final created = await db.create('person', data);
174+
final created = ((await db.create('person', data))! as List).first;
174175
final tom = Map<String, dynamic>.from(created! as Map);
175176
final id = tom['id'] as String;
176177
await db.delete(id);
177-
final result = await db.select(id);
178-
expect(result, isNull);
178+
final results = (await db.select('person'))! as List;
179+
expect(results, isEmpty);
179180
});
180181

181182
testWidgets('set test', (WidgetTester tester) async {
@@ -192,9 +193,10 @@ DEFINE FIELD created ON document TYPE datetime;
192193
await db.patch('keyValue', [
193194
{'op': 'replace', 'path': '/key', 'value': 'newValue'},
194195
]);
195-
final result = await db.query('SELECT key FROM keyValue');
196+
final result =
197+
((await db.query('SELECT key FROM keyValue'))! as List).first;
196198
expect(
197-
result,
199+
result as List,
198200
equals([
199201
{'key': 'newValue'},
200202
]),

integration_test/transaction_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main() {
1313

1414
setUpAll(() async {
1515
await db.connect('mem://');
16-
await db.use(ns: 'surreal', db: 'surreal');
16+
await db.use(namespace: 'surreal', database: 'surreal');
1717
});
1818
group('db.transaction()', () {
1919
testWidgets('should throw error message: Connection uninitialised',
@@ -63,7 +63,7 @@ void main() {
6363
);
6464
});
6565

66-
final result = await db.query('SELECT * FROM test;');
66+
final result = ((await db.query('SELECT * FROM test;'))! as List).first;
6767
expect(result, isNotEmpty);
6868
final test = Map<String, dynamic>.from(
6969
(result! as List).first as Map,
@@ -88,7 +88,7 @@ void main() {
8888
transactionResult,
8989
equals('Transaction has been canceled by user.'),
9090
);
91-
final result = await db.query('SELECT * FROM test;');
91+
final result = ((await db.query('SELECT * FROM test;'))! as List).first;
9292
expect(result, isEmpty);
9393
});
9494

@@ -111,7 +111,7 @@ void main() {
111111
txn.query('');
112112
});
113113

114-
expect(result, isNull);
114+
expect(result, isEmpty);
115115
});
116116

117117
test('Concurrent Transactions: Multiple transactions execute concurrently',
@@ -157,7 +157,7 @@ void main() {
157157
);
158158
});
159159

160-
final result = await db.query('SELECT * FROM test2');
160+
final result = ((await db.query('SELECT * FROM test2'))! as List).first;
161161
// Ensure the data was inserted correctly in the nested transaction
162162
expect(result, isNotEmpty);
163163
final test = Map<String, dynamic>.from(

lib/src/surrealdb_wasm.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,33 @@ class Surreal {
201201

202202
/// Switch to a specific namespace or database.
203203
///
204-
/// The optional [ns] parameter is the namespace,
205-
/// and the optional [db] parameter is the database.
204+
/// The optional [namespace] parameter,
205+
/// and the optional [database] parameter.
206206
///
207-
/// If neither [ns] nor [db] is provided, it will throw an exception.
207+
/// If neither [namespace] nor [database] is provided, it will throw an exception.
208208
///
209209
/// Example usage:
210210
/// ```dart
211211
/// // Switch to a namespace
212-
/// await db.use(ns: 'namespace');
212+
/// await db.use(namespace: 'namespace');
213213
///
214214
/// // Switch to a database
215-
/// await db.use(db: 'database');
215+
/// await db.use(database: 'database');
216216
///
217217
/// // Switch both
218-
/// await db.use(ns: 'namespace', db: 'database');
218+
/// await db.use(namespace: 'namespace', database: 'database');
219219
/// ```
220-
Future<void> use({String? ns, String? db}) async {
220+
Future<void> use({String? namespace, String? database}) async {
221221
var value = <String, String>{};
222222

223-
if (ns == null && db == null) {
224-
throw Exception('Either "ns" or "db" must have value!');
225-
} else if (ns != null && db != null) {
226-
value = {'ns': ns, 'db': db};
227-
} else if (ns != null) {
228-
value = {'ns': ns};
229-
} else if (db != null) {
230-
value = {'db': db};
223+
if (namespace == null && database == null) {
224+
throw Exception('Either "namespace" or "database" must have value!');
225+
} else if (namespace != null && database != null) {
226+
value = {'namespace': namespace, 'database': database};
227+
} else if (namespace != null) {
228+
value = {'namespace': namespace};
229+
} else if (database != null) {
230+
value = {'database': database};
231231
}
232232

233233
await promiseToFuture<void>(

web/wasm_test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//});
2727

2828
// Select a specific namespace / database
29-
await db.use({ ns: "test", db: "test" });
29+
await db.use({ namespace: "test", database: "test" });
3030

3131
// Create a new person with a random id
3232
let created = await db.create("person", {

0 commit comments

Comments
 (0)