diff --git a/app/lib/shared/email.dart b/app/lib/shared/email.dart index b6ab089dc6..597379724a 100644 --- a/app/lib/shared/email.dart +++ b/app/lib/shared/email.dart @@ -126,9 +126,9 @@ EmailMessage createPackageUploadedEmail({ $uploaderEmail has published a new version ($packageVersion) of the $packageName package to the Dart package site ($primaryHost). -For details, go to $url. +For details, go to $url -If you have any concerns about this package, file an issue at https://github.com/dart-lang/pub-dev/issues. +If you have any concerns about this package, file an issue at https://github.com/dart-lang/pub-dev/issues Thanks for your contributions to the Dart community! @@ -145,10 +145,11 @@ EmailMessage createUploaderConfirmationEmail({ @required String addedUploaderEmail, @required String confirmationUrl, }) { + final pkgUrl = pkgPageUrl(packageName, includeHost: true); final subject = 'Uploader invitation for package: $packageName'; final bodyText = '''Dear package maintainer, -$activeAccountEmail has invited you to become an uploader of the $packageName package. If you accept this invitation, you’ll be able to upload new versions of the package to the Dart package site ($primaryHost), and you’ll be listed as an uploader at $siteRoot/packages/$packageName. +$activeAccountEmail has invited you to become an uploader of the $packageName package. If you accept this invitation, you’ll be able to upload new versions of the package to the Dart package site ($primaryHost), and you’ll be listed as an uploader at $pkgUrl To accept this invitation, visit the following URL: $confirmationUrl @@ -156,7 +157,7 @@ $confirmationUrl If you don’t want to be an uploader, simply ignore this email. -If you have any concerns about this invitation, file an issue at https://github.com/dart-lang/pub-dev/issues. +If you have any concerns about this invitation, file an issue at https://github.com/dart-lang/pub-dev/issues Thanks for your contributions to the Dart community! @@ -183,7 +184,7 @@ $consentUrl If you don’t want to accept it, simply ignore this email. -If you have any concerns about this invitation, file an issue at https://github.com/dart-lang/pub-dev/issues. +If you have any concerns about this invitation, file an issue at https://github.com/dart-lang/pub-dev/issues Thanks for your contributions to the Dart community! diff --git a/app/test/frontend/backend_test.dart b/app/test/frontend/backend_test.dart index 1c0e7367e3..8e32bf4092 100644 --- a/app/test/frontend/backend_test.dart +++ b/app/test/frontend/backend_test.dart @@ -229,7 +229,12 @@ void main() { final p = list.single; expect(p.uploaders, [hansUser.userId]); - // TODO: check sent e-mail + expect(fakeEmailSender.sentMessages, hasLength(1)); + final email = fakeEmailSender.sentMessages.single; + expect(email.recipients.single.email, 'somebody@example.com'); + expect(email.subject, 'Uploader invitation for package: hydrogen'); + expect(email.bodyText, contains('https://pub.dev/packages/hydrogen\n')); + // TODO: check consent (after migrating to consent API) }); }); @@ -444,7 +449,15 @@ void main() { expect(pv.downloads, 0); expect(pv.sortOrder, 0); - // TODO: check sent e-mail + expect(fakeEmailSender.sentMessages, hasLength(1)); + final email = fakeEmailSender.sentMessages.single; + expect(email.recipients.single.email, hansUser.email); + expect(email.subject, 'Package uploaded: new_package 1.2.3'); + expect( + email.bodyText, + contains( + 'https://pub.dev/packages/new_package/versions/1.2.3\n')); + // TODO: check history // TODO: check assets }); @@ -538,7 +551,13 @@ void main() { await backend.repository.upload(Stream.fromIterable([tarball])); expect(version.packageName, foobarPackage.name); expect(version.versionString, '1.2.3'); - // TODO: check sent e-mail + + expect(fakeEmailSender.sentMessages, hasLength(1)); + final email = fakeEmailSender.sentMessages.single; + expect(email.recipients.single.email, hansUser.email); + expect(email.subject, 'Package uploaded: foobar_pkg 1.2.3'); + expect(email.bodyText, + contains('https://pub.dev/packages/foobar_pkg/versions/1.2.3\n')); final packages = await backend.latestPackages(); expect(packages.first.name, foobarPackage.name); diff --git a/app/test/frontend/backend_test_utils.dart b/app/test/frontend/backend_test_utils.dart index f9cc67a6b0..019495def1 100644 --- a/app/test/frontend/backend_test_utils.dart +++ b/app/test/frontend/backend_test_utils.dart @@ -7,10 +7,6 @@ library pub_dartlang_org.backend_test_utils; import 'dart:async'; import 'dart:io'; -import 'package:pub_dartlang_org/shared/email.dart'; - -import 'package:pub_dartlang_org/frontend/email_sender.dart'; - import '../shared/test_models.dart'; Future withTempDirectory(Future func(String temp)) async { @@ -55,13 +51,3 @@ Future> packageArchiveBytes({String pubspecContent}) async { return bytes; }); } - -class EmailSenderMock implements EmailSender { - final sentMessages = []; - - @override - Future sendMessage(EmailMessage message) async { - sentMessages.add(message); - return; - } -} diff --git a/app/test/shared/test_services.dart b/app/test/shared/test_services.dart index 39629d03ef..ae4fdaeaf5 100644 --- a/app/test/shared/test_services.dart +++ b/app/test/shared/test_services.dart @@ -16,6 +16,7 @@ import 'package:shelf/shelf.dart' as shelf; import 'package:pub_dartlang_org/account/backend.dart'; import 'package:pub_dartlang_org/account/testing/fake_auth_provider.dart'; +import 'package:pub_dartlang_org/frontend/email_sender.dart'; import 'package:pub_dartlang_org/frontend/handlers.dart'; import 'package:pub_dartlang_org/frontend/handlers/pubapi.client.dart'; import 'package:pub_dartlang_org/frontend/testing/fake_upload_signer_service.dart'; @@ -26,6 +27,7 @@ import 'package:pub_dartlang_org/search/handlers.dart'; import 'package:pub_dartlang_org/search/index_simple.dart'; import 'package:pub_dartlang_org/search/updater.dart'; import 'package:pub_dartlang_org/shared/configuration.dart'; +import 'package:pub_dartlang_org/shared/email.dart'; import 'package:pub_dartlang_org/shared/exceptions.dart' show AuthorizationException; import 'package:pub_dartlang_org/shared/handler_helpers.dart'; @@ -88,6 +90,7 @@ void testWithServices(String name, Future fn()) { registerAccountBackend( AccountBackend(db, authProvider: FakeAuthProvider())); registerDomainVerifier(_FakeDomainVerifier()); + registerEmailSender(FakeEmailSender()); registerUploadSigner(FakeUploadSignerService('https://storage.url')); await dartSdkIndex.merge(); @@ -191,3 +194,15 @@ void _setupLogging() { } }); } + +FakeEmailSender get fakeEmailSender => emailSender as FakeEmailSender; + +class FakeEmailSender implements EmailSender { + final sentMessages = []; + + @override + Future sendMessage(EmailMessage message) async { + sentMessages.add(message); + return; + } +}