fix: format, analyze-fix and update mocks
This commit is contained in:
@@ -16,7 +16,8 @@ Future<imap.ImapClient> _fakeImapConnect(
|
||||
Account account,
|
||||
String username,
|
||||
String password,
|
||||
) async => throw const SocketException('fake — no real IMAP server in tests');
|
||||
) async =>
|
||||
throw const SocketException('fake — no real IMAP server in tests');
|
||||
|
||||
void main() {
|
||||
test(
|
||||
@@ -83,27 +84,27 @@ void main() {
|
||||
}
|
||||
|
||||
Account _account(String id) => Account(
|
||||
id: id,
|
||||
displayName: 'Account $id',
|
||||
email: '$id@example.com',
|
||||
imapHost: 'localhost',
|
||||
imapPort: 143,
|
||||
imapSsl: false,
|
||||
smtpHost: 'localhost',
|
||||
smtpPort: 25,
|
||||
smtpSsl: false,
|
||||
);
|
||||
id: id,
|
||||
displayName: 'Account $id',
|
||||
email: '$id@example.com',
|
||||
imapHost: 'localhost',
|
||||
imapPort: 143,
|
||||
imapSsl: false,
|
||||
smtpHost: 'localhost',
|
||||
smtpPort: 25,
|
||||
smtpSsl: false,
|
||||
);
|
||||
|
||||
Account _jmapAccount(String id) => Account(
|
||||
id: id,
|
||||
displayName: 'Account $id',
|
||||
email: '$id@example.com',
|
||||
type: AccountType.jmap,
|
||||
jmapUrl: 'http://localhost:8080/.well-known/jmap',
|
||||
smtpHost: 'localhost',
|
||||
smtpPort: 25,
|
||||
smtpSsl: false,
|
||||
);
|
||||
id: id,
|
||||
displayName: 'Account $id',
|
||||
email: '$id@example.com',
|
||||
type: AccountType.jmap,
|
||||
jmapUrl: 'http://localhost:8080/.well-known/jmap',
|
||||
smtpHost: 'localhost',
|
||||
smtpPort: 25,
|
||||
smtpSsl: false,
|
||||
);
|
||||
|
||||
class _FakeAccounts implements AccountRepository {
|
||||
_FakeAccounts(this.password);
|
||||
@@ -132,16 +133,16 @@ class _FakeAccounts implements AccountRepository {
|
||||
class _FakeMailboxes implements MailboxRepository {
|
||||
@override
|
||||
Stream<List<Mailbox>> observeMailboxes(String? accountId) => Stream.value([
|
||||
Mailbox(
|
||||
id: '$accountId:INBOX',
|
||||
accountId: accountId ?? '',
|
||||
path: 'INBOX',
|
||||
name: 'INBOX',
|
||||
unreadCount: 0,
|
||||
totalCount: 0,
|
||||
role: 'inbox',
|
||||
),
|
||||
]);
|
||||
Mailbox(
|
||||
id: '$accountId:INBOX',
|
||||
accountId: accountId ?? '',
|
||||
path: 'INBOX',
|
||||
name: 'INBOX',
|
||||
unreadCount: 0,
|
||||
totalCount: 0,
|
||||
role: 'inbox',
|
||||
),
|
||||
]);
|
||||
|
||||
@override
|
||||
Future<int> syncMailboxes(String accountId) async => 0;
|
||||
@@ -158,15 +159,16 @@ class _FakeMailboxes implements MailboxRepository {
|
||||
String accountId,
|
||||
String name,
|
||||
String role,
|
||||
) async => Mailbox(
|
||||
id: '$accountId:$name',
|
||||
accountId: accountId,
|
||||
path: name,
|
||||
name: name,
|
||||
role: role,
|
||||
unreadCount: 0,
|
||||
totalCount: 0,
|
||||
);
|
||||
) async =>
|
||||
Mailbox(
|
||||
id: '$accountId:$name',
|
||||
accountId: accountId,
|
||||
path: name,
|
||||
name: name,
|
||||
role: role,
|
||||
unreadCount: 0,
|
||||
totalCount: 0,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeEmails implements EmailRepository {
|
||||
@@ -181,7 +183,8 @@ class _FakeEmails implements EmailRepository {
|
||||
String a,
|
||||
String m, {
|
||||
int limit = 50,
|
||||
}) => Stream.value([]);
|
||||
}) =>
|
||||
Stream.value([]);
|
||||
|
||||
@override
|
||||
Stream<List<Email>> observeEmailsInThread(String a, String m, String t) =>
|
||||
@@ -225,7 +228,8 @@ class _FakeEmails implements EmailRepository {
|
||||
Future<Email?> findEmailByMessageId(
|
||||
String accountId,
|
||||
String messageId,
|
||||
) async => null;
|
||||
) async =>
|
||||
null;
|
||||
|
||||
@override
|
||||
Future<String?> deleteEmail(String id) async => null;
|
||||
@@ -243,7 +247,8 @@ class _FakeEmails implements EmailRepository {
|
||||
Future<String> downloadAttachment(
|
||||
String emailId,
|
||||
EmailAttachment attachment,
|
||||
) async => '/tmp/${attachment.filename}';
|
||||
) async =>
|
||||
'/tmp/${attachment.filename}';
|
||||
|
||||
@override
|
||||
Future<String> fetchRawRfc822(String emailId) async => '';
|
||||
@@ -262,7 +267,8 @@ class _FakeEmails implements EmailRepository {
|
||||
String? a,
|
||||
String q, {
|
||||
int limit = 10,
|
||||
}) async => [];
|
||||
}) async =>
|
||||
[];
|
||||
|
||||
@override
|
||||
Stream<void> watchJmapPush(String accountId, String password) =>
|
||||
@@ -272,7 +278,8 @@ class _FakeEmails implements EmailRepository {
|
||||
Future<ReliabilityResult> verifySyncReliability(
|
||||
String accountId,
|
||||
String mailboxPath,
|
||||
) async => ReliabilityResult.healthy;
|
||||
) async =>
|
||||
ReliabilityResult.healthy;
|
||||
|
||||
@override
|
||||
Stream<List<FailedMutation>> observeFailedMutations(String accountId) =>
|
||||
|
||||
@@ -246,9 +246,8 @@ void main() {
|
||||
);
|
||||
|
||||
// Alice and bob each received at least msgCount messages.
|
||||
final aliceEmails = allEmails
|
||||
.where((e) => e.accountId == 'alice')
|
||||
.toList();
|
||||
final aliceEmails =
|
||||
allEmails.where((e) => e.accountId == 'alice').toList();
|
||||
final bobEmails = allEmails.where((e) => e.accountId == 'bob').toList();
|
||||
expect(
|
||||
aliceEmails.length,
|
||||
|
||||
@@ -138,7 +138,7 @@ void main() {
|
||||
}
|
||||
|
||||
({AppDatabase db, AccountRepositoryImpl accounts, EmailRepositoryImpl emails})
|
||||
makeRepo() {
|
||||
makeRepo() {
|
||||
final db = openTestDatabase();
|
||||
final storage = MapSecureStorage();
|
||||
final accounts = AccountRepositoryImpl(db, storage);
|
||||
@@ -346,9 +346,7 @@ void main() {
|
||||
final emailId = emails.first.id;
|
||||
|
||||
// Simulate a legacy row with no cachedAt.
|
||||
await r.db
|
||||
.into(r.db.emailBodies)
|
||||
.insertOnConflictUpdate(
|
||||
await r.db.into(r.db.emailBodies).insertOnConflictUpdate(
|
||||
EmailBodiesCompanion.insert(
|
||||
emailId: emailId,
|
||||
textBody: const Value('stale text'),
|
||||
@@ -374,9 +372,7 @@ void main() {
|
||||
final emailId = emails.first.id;
|
||||
|
||||
// Simulate a row cached 8 days ago.
|
||||
await r.db
|
||||
.into(r.db.emailBodies)
|
||||
.insertOnConflictUpdate(
|
||||
await r.db.into(r.db.emailBodies).insertOnConflictUpdate(
|
||||
EmailBodiesCompanion.insert(
|
||||
emailId: emailId,
|
||||
textBody: const Value('old text'),
|
||||
|
||||
@@ -107,8 +107,7 @@ void main() {
|
||||
AccountRepositoryImpl accounts,
|
||||
EmailRepositoryImpl emails,
|
||||
MailboxRepositoryImpl mailboxes,
|
||||
})
|
||||
makeRepo() {
|
||||
}) makeRepo() {
|
||||
final db = openTestDatabase();
|
||||
final accounts = AccountRepositoryImpl(db, MapSecureStorage());
|
||||
final emails = EmailRepositoryImpl(
|
||||
@@ -128,13 +127,12 @@ void main() {
|
||||
) async {
|
||||
await accounts.addAccount(account, userPass);
|
||||
await mailboxes.syncMailboxes('test-jmap');
|
||||
final row =
|
||||
await (db.select(db.mailboxes)
|
||||
..where(
|
||||
(t) => t.accountId.equals('test-jmap') & t.role.equals('inbox'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
final row = await (db.select(db.mailboxes)
|
||||
..where(
|
||||
(t) => t.accountId.equals('test-jmap') & t.role.equals('inbox'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
if (row == null) throw StateError('INBOX not found after syncMailboxes');
|
||||
return row.path;
|
||||
}
|
||||
@@ -272,21 +270,18 @@ void main() {
|
||||
);
|
||||
|
||||
// A sent copy should appear in the Sent mailbox.
|
||||
final sentRow =
|
||||
await (r.db.select(r.db.mailboxes)
|
||||
..where(
|
||||
(t) =>
|
||||
t.accountId.equals('test-jmap') & t.role.equals('sent'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
final sentRow = await (r.db.select(r.db.mailboxes)
|
||||
..where(
|
||||
(t) => t.accountId.equals('test-jmap') & t.role.equals('sent'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
final sentId = sentRow?.path;
|
||||
|
||||
if (sentId != null) {
|
||||
await r.emails.syncEmails('test-jmap', sentId);
|
||||
final sentEmails = await r.emails
|
||||
.observeEmails('test-jmap', sentId)
|
||||
.first;
|
||||
final sentEmails =
|
||||
await r.emails.observeEmails('test-jmap', sentId).first;
|
||||
expect(sentEmails.any((e) => e.subject == subject), isTrue);
|
||||
} else {
|
||||
// If no Sent mailbox exists, just verify sendEmail didn't throw.
|
||||
@@ -353,13 +348,12 @@ void main() {
|
||||
await r.emails.syncEmails('test-jmap', inboxId);
|
||||
|
||||
// Find a destination mailbox (Trash).
|
||||
final trashRow =
|
||||
await (r.db.select(r.db.mailboxes)
|
||||
..where(
|
||||
(t) => t.accountId.equals('test-jmap') & t.role.equals('trash'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
final trashRow = await (r.db.select(r.db.mailboxes)
|
||||
..where(
|
||||
(t) => t.accountId.equals('test-jmap') & t.role.equals('trash'),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
if (trashRow == null) {
|
||||
markTestSkipped('No trash mailbox found on this Stalwart instance');
|
||||
return;
|
||||
|
||||
@@ -76,8 +76,7 @@ void main() {
|
||||
AppDatabase db,
|
||||
AccountRepositoryImpl accounts,
|
||||
MailboxRepositoryImpl mailboxes,
|
||||
})
|
||||
makeRepo() {
|
||||
}) makeRepo() {
|
||||
final db = openTestDatabase();
|
||||
final accounts = AccountRepositoryImpl(db, MapSecureStorage());
|
||||
final mailboxes = MailboxRepositoryImpl(
|
||||
|
||||
@@ -107,9 +107,7 @@ void main() {
|
||||
'verifySyncReliability identifies extra local emails (missing on server)',
|
||||
() async {
|
||||
// 1. Manually insert a row into local DB that doesn't exist on server
|
||||
await db
|
||||
.into(db.emails)
|
||||
.insert(
|
||||
await db.into(db.emails).insert(
|
||||
EmailsCompanion.insert(
|
||||
id: 'test:999',
|
||||
accountId: 'test',
|
||||
|
||||
Reference in New Issue
Block a user