Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endret variabelnavn til RequestedPublishTime #329

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public async Task DeleteAttachment_WhenAttachedCorrespondenceIsReadyForPublish_F
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithExistingAttachments([attachmentId])
.WithVisibleFrom(DateTime.UtcNow.AddDays(1))
.WithRequestedPublishTime(DateTime.UtcNow.AddDays(1))
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
Expand Down
57 changes: 36 additions & 21 deletions Test/Altinn.Correspondence.Tests/CorrespondenceControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ public async Task InitializeCorrespondence_DueDate_PriorToday_Returns_BadRequest
}

[Fact]
public async Task InitializeCorrespondence_DueDate_PriorVisibleFrom_Returns_BadRequest()
public async Task InitializeCorrespondence_DueDate_PriorRequestedPublishTime_Returns_BadRequest()
{
// Arrange
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithDueDateTime(DateTimeOffset.Now.AddDays(7))
.WithVisibleFrom(DateTimeOffset.Now.AddDays(14))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(14))
.Build();

// Act
Expand All @@ -280,14 +280,14 @@ public async Task InitializeCorrespondence_AllowSystemDeleteAfter_PriorToday_Ret
}

[Fact]
public async Task InitializeCorrespondence_AllowSystemDeleteAfter_PriorVisibleFrom_Returns_BadRequest()
public async Task InitializeCorrespondence_AllowSystemDeleteAfter_PriorRequestedPublishTime_Returns_BadRequest()
{
// Arrange
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithAllowSystemDeleteAfter(DateTimeOffset.Now.AddDays(7))
.WithVisibleFrom(DateTimeOffset.Now.AddDays(14))
.WithDueDateTime(DateTimeOffset.Now.AddDays(21)) // ensure DueDate is after VisibleFrom
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(14))
.WithDueDateTime(DateTimeOffset.Now.AddDays(21)) // ensure DueDate is after RequestedPublishTime
.Build();

// Act
Expand All @@ -304,7 +304,7 @@ public async Task InitializeCorrespondence_AllowSystemDeleteAfter_PriorDueDate_R
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithAllowSystemDeleteAfter(DateTimeOffset.Now.AddDays(14))
.WithVisibleFrom(DateTimeOffset.Now.AddDays(7))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(7))
.WithDueDateTime(DateTimeOffset.Now.AddDays(21))
.Build();

Expand Down Expand Up @@ -555,7 +555,7 @@ public async Task GetCorrespondences_WithStatusSpecified_ShowsSpecifiedCorrespon
var initializedCorrespondence = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithResourceId(resourceId)
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();
var a = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", initializedCorrespondence);
var correspondence = await a.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
Expand All @@ -565,7 +565,7 @@ public async Task GetCorrespondences_WithStatusSpecified_ShowsSpecifiedCorrespon
var publishedCorrespondences = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithResourceId(resourceId)
.WithVisibleFrom(DateTimeOffset.Now.AddDays(-1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(-1))
.Build();
await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", publishedCorrespondences);

Expand Down Expand Up @@ -601,7 +601,7 @@ public async Task GetCorrespondences_WithoutStatusSpecified_AsReceiver_ReturnsAl
.CreateCorrespondence()
.WithResourceId(resource)
.WithRecipients([recipientId])
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build(); // One ready for publish

// Act
Expand All @@ -624,7 +624,7 @@ public async Task GetCorrespondences_WithoutStatusSpecified_AsSender_ReturnsAllE
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithResourceId(resource)
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build(); // One ReadyForPublish

// Act
Expand All @@ -651,7 +651,7 @@ public async Task GetCorrespondences_WithStatusSpecified_ButStatusIsBlackListed_
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithResourceId(resource)
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build(); // One ReadyForPublish

// Act
Expand Down Expand Up @@ -708,7 +708,7 @@ public async Task GetCorrespondenceOverview_AsReceiver_WhenNotPublishedReturns40
// Arrange
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();

var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
Expand Down Expand Up @@ -805,7 +805,7 @@ public async Task GetCorrespondenceDetails_AsReceiver_WhenNotPublishedReturns404
// Arrange
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondence = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
Expand Down Expand Up @@ -875,7 +875,7 @@ public async Task ReceiverMarkActions_CorrespondenceNotPublished_Return404()
{
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
Expand Down Expand Up @@ -979,7 +979,7 @@ public async Task DownloadCorrespondenceAttachment_WhenCorrespondenceUnavailable
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithExistingAttachments([attachmentId])
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1)) // Set visibleFrom in the future so that it is not published
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1)) // Set RequestedPublishTime in the future so that it is not published
.Build();


Expand Down Expand Up @@ -1014,7 +1014,7 @@ public async Task Delete_ReadyForPublished_Correspondence_SuccessForSender_Fails
// Arrange
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();

var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
Expand Down Expand Up @@ -1061,7 +1061,7 @@ public async Task Delete_Correspondence_Also_deletes_attachment()
var payload = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithExistingAttachments([attachmentId])
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
Expand Down Expand Up @@ -1089,12 +1089,12 @@ public async Task Delete_correspondence_dont_delete_attachment_with_multiple_cor
var payload1 = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithExistingAttachments([attachmentId])
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();
var payload2 = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithExistingAttachments([attachmentId])
.WithVisibleFrom(DateTimeOffset.Now.AddDays(1))
.WithRequestedPublishTime(DateTimeOffset.Now.AddDays(1))
.Build();

var initializeCorrespondenceResponse1 = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload1, _responseSerializerOptions);
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public async Task CancelNotificationHandler_SendsSlackNotification_WhenCancellat
var notificationEntities = correspondence.Notifications;
notificationEntities.ForEach(notification =>
{
notification.RequestedSendTime = correspondence.VisibleFrom.AddMinutes(1); // Set requested send time to future
notification.RequestedSendTime = correspondence.RequestedPublishTime.AddMinutes(1); // Set requested send time to future
notification.NotificationOrderId = null; // Invalidate notification order id
});

Expand All @@ -1354,13 +1354,28 @@ public async Task CancelNotificationHandler_SendsSlackNotification_WhenCancellat
slackClientMock.Verify(client => client.Post(It.IsAny<SlackMessage>()), Times.Once);
}

[Fact]
public async Task InitializeCorrespondence_With_RequestedPublishTime_Null()
{
// Arrange
var correspondence = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithRequestedPublishTime(null)
.Build();

var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", correspondence);

// Assert
Assert.Equal(HttpStatusCode.OK, initializeCorrespondenceResponse.StatusCode);
}

private MultipartFormDataContent CorrespondenceToFormData(BaseCorrespondenceExt correspondence)
{
var formData = new MultipartFormDataContent(){
{ new StringContent(correspondence.ResourceId), "correspondence.resourceId" },
{ new StringContent(correspondence.Sender), "correspondence.sender" },
{ new StringContent(correspondence.SendersReference), "correspondence.sendersReference" },
{ new StringContent(correspondence.VisibleFrom.ToString()), "correspondence.visibleFrom" },
{ new StringContent(correspondence.RequestedPublishTime.ToString()), "correspondence.RequestedPublishTime" },
{ new StringContent(correspondence.DueDateTime.ToString()), "correspondence.dueDateTime" },
{ new StringContent(correspondence.AllowSystemDeleteAfter.ToString()), "correspondence.AllowSystemDeleteAfter" },
{ new StringContent(correspondence.Content.MessageTitle), "correspondence.content.MessageTitle" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CorrespondenceBuilder CreateCorrespondence()
MessageSummary = "# test",
MessageBody = "# test body /n __test__ /n **test**/n [test](www.test.no) /n ![test](www.test.no) /n ```test``` /n > test /n - test /n 1. test /n 1. test /n [x] test /n [ ] test /n ## test /n ### test /n #### test /n ##### test /n ###### test /n + test list /n - test list /n * list element",
},
VisibleFrom = DateTimeOffset.UtcNow,
RequestedPublishTime = DateTimeOffset.UtcNow,
DueDateTime = DateTimeOffset.UtcNow.AddDays(2),
AllowSystemDeleteAfter = DateTimeOffset.UtcNow.AddDays(3),
PropertyList = new Dictionary<string, string>(){
Expand Down Expand Up @@ -121,9 +121,9 @@ public CorrespondenceBuilder WithDueDateTime(DateTimeOffset dueDateTime)
_correspondence.Correspondence.DueDateTime = dueDateTime;
return this;
}
public CorrespondenceBuilder WithVisibleFrom(DateTimeOffset dueDateTime)
public CorrespondenceBuilder WithRequestedPublishTime(DateTimeOffset? requestedPublishTime)
{
_correspondence.Correspondence.VisibleFrom = dueDateTime;
_correspondence.Correspondence.RequestedPublishTime = requestedPublishTime;
return this;
}
public CorrespondenceBuilder WithAllowSystemDeleteAfter(DateTimeOffset dueDateTime)
Expand Down Expand Up @@ -185,7 +185,7 @@ public static CorrespondenceEntity CorrespondenceEntityWithNotifications()
Sender = "0192:991825827",
Recipient = "0192:991825827",
SendersReference = "1",
VisibleFrom = DateTimeOffset.UtcNow,
RequestedPublishTime = DateTimeOffset.UtcNow,
Statuses = new List<CorrespondenceStatusEntity>(),
Created = DateTimeOffset.UtcNow,
Notifications = new List<CorrespondenceNotificationEntity>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static class InitializeCorrespondenceFactory
}
},
},
VisibleFrom = DateTimeOffset.UtcNow,
RequestedPublishTime = DateTimeOffset.UtcNow,
AllowSystemDeleteAfter = DateTimeOffset.UtcNow.AddDays(3),
DueDateTime = DateTimeOffset.UtcNow.AddDays(2),
ExternalReferences = new List<ExternalReferenceExt>(){
Expand Down Expand Up @@ -118,7 +118,7 @@ internal static InitializeCorrespondencesExt BasicCorrespondenceWithoutAttachmen
internal static InitializeCorrespondencesExt BasicCorrespondenceAlreadyVisible()
{
var data = BasicCorrespondences();
data.Correspondence.VisibleFrom = DateTime.UtcNow.AddDays(-1);
data.Correspondence.RequestedPublishTime = DateTime.UtcNow.AddDays(-1);
return data;
}
internal static InitializeCorrespondencesExt BasicCorrespondenceWithHtmlInTitle()
Expand Down Expand Up @@ -320,7 +320,7 @@ internal static CorrespondenceEntity CorrespondenceEntityWithNotifications()
Sender = "0192:991825827",
Recipient = "0192:991825827",
SendersReference = "1",
VisibleFrom = DateTimeOffset.UtcNow,
RequestedPublishTime = DateTimeOffset.UtcNow,
Statuses = new List<CorrespondenceStatusEntity>(),
Created = DateTimeOffset.UtcNow,
Notifications = new List<CorrespondenceNotificationEntity>()
Expand Down
2 changes: 1 addition & 1 deletion Test/Altinn.Correspondence.Tests/NotificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task CheckNotification_For_Correspondence_With_Read_Status_Gives_Fa
var client = factory.CreateClientWithAddedClaims(("scope", AuthorizationConstants.SenderScope));
var correspondence = new CorrespondenceBuilder()
.CreateCorrespondence()
.WithVisibleFrom(DateTime.UtcNow.AddHours(-1))
.WithRequestedPublishTime(DateTime.UtcNow.AddHours(-1))
.Build();

var initializeCorrespondenceResponse = await client.PostAsJsonAsync("correspondence/api/v1/correspondence", correspondence);
Expand Down
Loading
Loading