Skip to content

Commit

Permalink
Fix e-mail urls (#2644)
Browse files Browse the repository at this point in the history
* Fix e-mail urls

* remove dot from test expectation
  • Loading branch information
isoos authored Aug 9, 2019
1 parent 389f259 commit 802c20e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
11 changes: 6 additions & 5 deletions app/lib/shared/email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -145,18 +145,19 @@ 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
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!
Expand All @@ -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!
Expand Down
25 changes: 22 additions & 3 deletions app/test/frontend/backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, '[email protected]');
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)
});
});
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions app/test/frontend/backend_test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> withTempDirectory<T>(Future<T> func(String temp)) async {
Expand Down Expand Up @@ -55,13 +51,3 @@ Future<List<int>> packageArchiveBytes({String pubspecContent}) async {
return bytes;
});
}

class EmailSenderMock implements EmailSender {
final sentMessages = <EmailMessage>[];

@override
Future sendMessage(EmailMessage message) async {
sentMessages.add(message);
return;
}
}
15 changes: 15 additions & 0 deletions app/test/shared/test_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -191,3 +194,15 @@ void _setupLogging() {
}
});
}

FakeEmailSender get fakeEmailSender => emailSender as FakeEmailSender;

class FakeEmailSender implements EmailSender {
final sentMessages = <EmailMessage>[];

@override
Future sendMessage(EmailMessage message) async {
sentMessages.add(message);
return;
}
}

0 comments on commit 802c20e

Please sign in to comment.