- enough_mail: use uidFetchMessage/uidMarkSeen/uidMarkFlagged/uidMove/
uidMarkDeleted/uidExpunge, remove non-existent isUidSequence param,
fix SmtpClient construction and use quit() not disconnect()
- Drift: add @DataClassName('MailboxRow') to avoid ugly 'Mailboxe',
alias core model imports to resolve type name conflicts
- EmailsCompanion.insert: uid/receivedAt are required, not Value<T>
- Lint: remove unrecognised rules (prefer_const_collections,
avoid_returning_null_for_future), add missing mounted guards after await
- Tests: fix html_utils expectations to match trim() behaviour,
add explicit Map casts in email_model_test for avoid_dynamic_calls
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
91 lines
2.7 KiB
Dart
91 lines
2.7 KiB
Dart
// Integration tests — requires a running Stalwart instance.
|
|
// Run via: stalwart-dev/test.sh (sets the env vars below)
|
|
//
|
|
// STALWART_IMAP_HOST, STALWART_IMAP_PORT, STALWART_SMTP_HOST, STALWART_SMTP_PORT
|
|
// STALWART_USER_B / STALWART_PASS_B (alice@localhost)
|
|
// STALWART_USER_C / STALWART_PASS_C (bob@localhost)
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:enough_mail/enough_mail.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
String _env(String key) {
|
|
final v = Platform.environment[key];
|
|
if (v == null || v.isEmpty) throw StateError('$key is not set');
|
|
return v;
|
|
}
|
|
|
|
Future<ImapClient> _connect(
|
|
String user,
|
|
String pass, {
|
|
required String host,
|
|
required int port,
|
|
}) async {
|
|
final client = ImapClient();
|
|
await client.connectToServer(host, port, isSecure: false);
|
|
await client.login(user, pass);
|
|
return client;
|
|
}
|
|
|
|
void main() {
|
|
late String imapHost;
|
|
late int imapPort;
|
|
late int smtpPort;
|
|
late String userA, passA, userB, passB;
|
|
|
|
setUpAll(() {
|
|
imapHost = Platform.environment['STALWART_IMAP_HOST'] ?? '127.0.0.1';
|
|
imapPort = int.parse(_env('STALWART_IMAP_PORT'));
|
|
smtpPort = int.parse(_env('STALWART_SMTP_PORT'));
|
|
userA = _env('STALWART_USER_B'); // alice
|
|
passA = _env('STALWART_PASS_B');
|
|
userB = _env('STALWART_USER_C'); // bob
|
|
passB = _env('STALWART_PASS_C');
|
|
});
|
|
|
|
test('login and list mailboxes', () async {
|
|
final client = await _connect(
|
|
userA,
|
|
passA,
|
|
host: imapHost,
|
|
port: imapPort,
|
|
);
|
|
addTearDown(() => client.logout().ignore());
|
|
|
|
// listMailboxes() returns List<Mailbox> directly
|
|
final mailboxes = await client.listMailboxes();
|
|
expect(mailboxes, isNotEmpty);
|
|
expect(mailboxes.map((m) => m.name), contains('INBOX'));
|
|
});
|
|
|
|
test('send via SMTP and receive via IMAP', () async {
|
|
final smtpClient = SmtpClient('test');
|
|
await smtpClient.connectToServer(imapHost, smtpPort, isSecure: false);
|
|
await smtpClient.ehlo();
|
|
await smtpClient.authenticate('$userA@localhost', passA);
|
|
|
|
final builder = MessageBuilder()
|
|
..from = [MailAddress('Alice', '$userA@localhost')]
|
|
..to = [MailAddress('Bob', '$userB@localhost')]
|
|
..subject = 'Integration test ${DateTime.now().millisecondsSinceEpoch}'
|
|
..text = 'Hello from SharedInbox integration test.';
|
|
await smtpClient.sendMessage(builder.buildMimeMessage());
|
|
await smtpClient.quit();
|
|
|
|
// Give Stalwart a moment to deliver the message.
|
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
|
|
|
final imapClient = await _connect(
|
|
userB,
|
|
passB,
|
|
host: imapHost,
|
|
port: imapPort,
|
|
);
|
|
addTearDown(() => imapClient.logout().ignore());
|
|
|
|
final inbox = await imapClient.selectMailboxByPath('INBOX');
|
|
expect(inbox.messagesExists, greaterThan(0));
|
|
});
|
|
}
|