-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4422 from dfe-analytical-services/master
Merge Master back into dev
- Loading branch information
Showing
19 changed files
with
776 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -699,7 +699,7 @@ public async Task InvitePreReleaseUsers_FailsSendingEmail_ExistingUser_ApprovedR | |
|
||
await using (var context = InMemoryApplicationDbContext(contextId)) | ||
{ | ||
Assert.Empty(context.UserReleaseRoles); | ||
Assert.Empty(context.UserReleaseRoles); | ||
Assert.Empty(context.UserReleaseInvites); | ||
} | ||
} | ||
|
@@ -1739,99 +1739,6 @@ await userAndRolesDbContext.AddAsync( | |
} | ||
} | ||
|
||
[Fact] | ||
public async Task SendPreReleaseUserInviteEmails() | ||
{ | ||
var release = new Release | ||
{ | ||
ReleaseName = "2020", | ||
TimePeriodCoverage = TimeIdentifier.CalendarYear, | ||
Publication = new Publication {Title = "Test publication"}, | ||
PublishScheduled = PublishedScheduledStartOfDay | ||
}; | ||
var contextId = Guid.NewGuid().ToString(); | ||
|
||
await using (var context = InMemoryApplicationDbContext(contextId)) | ||
{ | ||
await context.AddRangeAsync( | ||
release, | ||
new User | ||
{ | ||
Email = "[email protected]", | ||
}, | ||
new UserReleaseInvite | ||
{ | ||
Release = release, | ||
Role = ReleaseRole.PrereleaseViewer, | ||
Email = "[email protected]", | ||
EmailSent = false, | ||
}, | ||
new User | ||
{ | ||
Email = "[email protected]" | ||
}, | ||
new UserReleaseInvite | ||
{ | ||
Release = release, | ||
Role = ReleaseRole.PrereleaseViewer, | ||
Email = "[email protected]", | ||
EmailSent = true, | ||
} | ||
); | ||
|
||
await context.SaveChangesAsync(); | ||
} | ||
|
||
var emailService = new Mock<IEmailService>(MockBehavior.Strict); | ||
|
||
var expectedTemplateValues = GetExpectedPreReleaseTemplateValues(release, newUser: false); | ||
|
||
emailService.Setup(mock => mock.SendEmail( | ||
"[email protected]", | ||
PreReleaseTemplateId, | ||
expectedTemplateValues | ||
)) | ||
.Returns(Unit.Instance); | ||
|
||
var preReleaseService = new Mock<IPreReleaseService>(MockBehavior.Strict); | ||
SetupGetPrereleaseWindow(preReleaseService, release); | ||
|
||
await using (var context = InMemoryApplicationDbContext(contextId)) | ||
await using (var userAndRolesDbContext = InMemoryUserAndRolesDbContext(contextId)) | ||
{ | ||
var service = SetupPreReleaseUserService( | ||
context, | ||
usersAndRolesDbContext: userAndRolesDbContext, | ||
preReleaseService: preReleaseService.Object, | ||
emailService: emailService.Object | ||
); | ||
|
||
var result = await service.SendPreReleaseUserInviteEmails(release.Id); | ||
|
||
emailService.Verify( | ||
s => s.SendEmail( | ||
"[email protected]", | ||
PreReleaseTemplateId, | ||
expectedTemplateValues | ||
), Times.Once | ||
); | ||
|
||
VerifyAllMocks(emailService, preReleaseService); | ||
|
||
result.AssertRight(); | ||
} | ||
|
||
await using (var context = InMemoryApplicationDbContext(contextId)) | ||
{ | ||
var updatedInvite = context.UserReleaseInvites | ||
.Single(i => i.Email == "[email protected]"); | ||
|
||
Assert.Equal(release.Id, updatedInvite.ReleaseId); | ||
Assert.Equal(ReleaseRole.PrereleaseViewer, updatedInvite.Role); | ||
Assert.True(updatedInvite.EmailSent); | ||
} | ||
} | ||
|
||
private static Dictionary<string, dynamic> GetExpectedPreReleaseTemplateValues(Release release, bool newUser) | ||
{ | ||
return new() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.