cyberhybridhub/server/test/integration/spelling_words_api_test.dart
nathanAndrinoid 4459852f83
Some checks failed
Admin portal tests / test (push) Has been cancelled
spelling
2026-06-05 03:22:35 +00:00

65 lines
1.8 KiB
Dart

@Tags(<String>['integration', 'postgres'])
library;
import 'package:cyberhybridhub_server/spelling/spelling_items_db.dart';
import 'package:test/test.dart';
import '../helpers/test_db.dart';
void main() {
TestDb? testDb;
setUpAll(() async {
testDb = await TestDb.open();
});
tearDown(() async {
if (testDb != null) {
await testDb!.truncateTradingTables();
await testDb!.connection.execute('DELETE FROM spelling_items');
await testDb!.connection.execute('DELETE FROM spelling_words');
await testDb!.spellingItemsDb.ensureCatalogSeeded();
}
});
tearDownAll(() async {
await testDb?.close();
});
test('addCanonicalWord and listCanonicalWords', () async {
if (testDb == null) {
markTestSkipped('Set DATABASE_URL or TEST_DATABASE_URL for integration tests');
return;
}
final SpellingItemsDb db = testDb!.spellingItemsDb;
final bool added = await db.addCanonicalWord('customword');
expect(added, isTrue);
final bool duplicate = await db.addCanonicalWord('customword');
expect(duplicate, isFalse);
final List<String> words = await db.listCanonicalWords();
expect(words, contains('customword'));
});
test('importCanonicalWords adds and skips duplicates', () async {
if (testDb == null) {
markTestSkipped('Set DATABASE_URL or TEST_DATABASE_URL for integration tests');
return;
}
final SpellingItemsDb db = testDb!.spellingItemsDb;
final ({int added, int skipped}) result = await db.importCanonicalWords(
<String>['alpha', 'beta', 'alpha', '', ' '],
);
expect(result.added, 2);
expect(result.skipped, 1);
final List<String> words = await db.listCanonicalWords();
expect(words, contains('alpha'));
expect(words, contains('beta'));
});
}