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

Include more details in InitializeCorrespondence response #355

Merged
merged 13 commits into from
Oct 18, 2024
Merged
12 changes: 6 additions & 6 deletions Test/Altinn.Correspondence.Tests/AttachmentControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ public async Task DeleteAttachment_WhenAttachedCorrespondenceIsPublished_Returns
.WithExistingAttachments([attachmentId])
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>(_responseSerializerOptions);

var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.CorrespondenceIds.FirstOrDefault()}", _responseSerializerOptions);
var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.Correspondences.FirstOrDefault().CorrespondenceId}", _responseSerializerOptions);
Assert.True(overview?.Status == CorrespondenceStatusExt.Published);

var deleteResponse = await _senderClient.DeleteAsync($"correspondence/api/v1/attachment/{attachmentId}");
Expand All @@ -350,8 +350,8 @@ public async Task DeleteAttachment_WhenAttachedCorrespondenceIsReadyForPublish_F
.WithRequestedPublishTime(DateTime.UtcNow.AddDays(1))
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.CorrespondenceIds.FirstOrDefault()}", _responseSerializerOptions);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>(_responseSerializerOptions);
var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.Correspondences.FirstOrDefault().CorrespondenceId}", _responseSerializerOptions);
Assert.True(overview?.Status == CorrespondenceStatusExt.ReadyForPublish);

var deleteResponse = await _senderClient.DeleteAsync($"correspondence/api/v1/attachment/{correspondenceResponse?.AttachmentIds.FirstOrDefault()}");
Expand All @@ -371,9 +371,9 @@ public async Task DeleteAttachment_AsRecipient_ReturnsForbidden()
.WithExistingAttachments([attachmentId])
.Build();
var initializeCorrespondenceResponse = await _senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", payload);
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>();
var correspondenceResponse = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>(_responseSerializerOptions);

var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.CorrespondenceIds.FirstOrDefault()}", _responseSerializerOptions);
var overview = await _senderClient.GetFromJsonAsync<CorrespondenceOverviewExt>($"correspondence/api/v1/correspondence/{correspondenceResponse?.Correspondences.FirstOrDefault().CorrespondenceId}", _responseSerializerOptions);
Assert.Equal(CorrespondenceStatusExt.Published, overview?.Status);

// Act
Expand Down
260 changes: 189 additions & 71 deletions Test/Altinn.Correspondence.Tests/CorrespondenceControllerTests.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Test/Altinn.Correspondence.Tests/DialogportenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ public async Task GetCorrespondenceContent_WithDialogTokenFromRecipient_Succeeds
var initializeCorrespondenceResponse = await senderClient.PostAsJsonAsync("correspondence/api/v1/correspondence", correspondenceToBeMade);
var initializedCorrespondence = await initializeCorrespondenceResponse.Content.ReadFromJsonAsync<InitializeCorrespondencesResponseExt>(_responseSerializerOptions);
using var scope = _factory.Services.CreateScope();
var correspondence = await scope.ServiceProvider.GetRequiredService<ICorrespondenceRepository>().GetCorrespondenceById(initializedCorrespondence.CorrespondenceIds[0], false, false, CancellationToken.None);
var correspondence = await scope.ServiceProvider.GetRequiredService<ICorrespondenceRepository>().GetCorrespondenceById(initializedCorrespondence.Correspondences[0].CorrespondenceId, false, false, CancellationToken.None);
var config = _factory.Services.GetService<IConfiguration>();
var dialogportenSettings = new DialogportenSettings();
config.GetSection(nameof(DialogportenSettings)).Bind(dialogportenSettings);
var dialogTokenClient = _factory.CreateClientWithDialogportenClaims(dialogportenSettings.Issuer, ("p", DialogportenCorrespondenceMapper.GetRecipientUrn(correspondence)));

// Act
var contentResponse = await dialogTokenClient.GetAsync("correspondence/api/v1/correspondence/" + initializedCorrespondence.CorrespondenceIds[0] + "/content");
var contentResponse = await dialogTokenClient.GetAsync("correspondence/api/v1/correspondence/" + initializedCorrespondence.Correspondences[0].CorrespondenceId + "/content");

// Assert
Assert.Equal(HttpStatusCode.OK, contentResponse.StatusCode);
Expand Down
4 changes: 2 additions & 2 deletions Test/Altinn.Correspondence.Tests/NotificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task CheckNotification_For_Correspondence_With_Unread_Status_Gives_
var initializeCorrespondenceResponse = await client.PostAsJsonAsync("correspondence/api/v1/correspondence", correspondence);
initializeCorrespondenceResponse.EnsureSuccessStatusCode();
var responseContent = await initializeCorrespondenceResponse.Content.ReadAsStringAsync();
var correspondenceId = JsonSerializer.Deserialize<InitializeCorrespondencesResponseExt>(responseContent, _responseSerializerOptions).CorrespondenceIds.First();
var correspondenceId = JsonSerializer.Deserialize<InitializeCorrespondencesResponseExt>(responseContent, _responseSerializerOptions).Correspondences.First().CorrespondenceId;

var response = await _client.GetAsync($"correspondence/api/v1/correspondence/{correspondenceId}/notification/check");
var content = await response.Content.ReadAsStringAsync();
Expand All @@ -67,7 +67,7 @@ public async Task CheckNotification_For_Correspondence_With_Read_Status_Gives_Fa
var initializeCorrespondenceResponse = await client.PostAsJsonAsync("correspondence/api/v1/correspondence", correspondence);
initializeCorrespondenceResponse.EnsureSuccessStatusCode();
var responseContent = await initializeCorrespondenceResponse.Content.ReadAsStringAsync();
var correspondenceId = JsonSerializer.Deserialize<InitializeCorrespondencesResponseExt>(responseContent, _responseSerializerOptions).CorrespondenceIds.First();
var correspondenceId = JsonSerializer.Deserialize<InitializeCorrespondencesResponseExt>(responseContent, _responseSerializerOptions).Correspondences.First().CorrespondenceId;;

var recipientClient = factory.CreateClientWithAddedClaims(("scope", AuthorizationConstants.RecipientScope));
var markasread = await recipientClient.PostAsync($"correspondence/api/v1/correspondence/{correspondenceId}/markasread", null);
Expand Down
8 changes: 4 additions & 4 deletions altinn-correspondence-postman-collection.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"info": {
"_postman_id": "f1377c01-c7ce-4f03-88ff-3e977acd8f95",
"_postman_id": "0990ec3d-32ae-4af6-adc6-23ff0ea2cf5c",
"name": "Altinn.Correspondence.API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "7106668"
"_exporter_id": "34552244"
},
"item": [
{
Expand Down Expand Up @@ -746,7 +746,7 @@
"script": {
"exec": [
"var correspondence = pm.response.json()\r",
"pm.collectionVariables.set(\"correspondenceId\", correspondence.correspondenceIds[0]);\r",
"pm.collectionVariables.set(\"correspondenceId\", correspondence.correspondences[0].correspondenceId);\r",
"pm.collectionVariables.set(\"attachmentId\", correspondence.attachmentIds[0])\r",
""
],
Expand Down Expand Up @@ -860,7 +860,7 @@
"script": {
"exec": [
"var correspondence = pm.response.json()\r",
"pm.collectionVariables.set(\"correspondenceId\", correspondence.correspondenceIds[0]);\r",
"pm.collectionVariables.set(\"correspondenceId\", correspondence.correspondences[0].correspondenceId);\r",
"pm.collectionVariables.set(\"attachmentId\", correspondence.attachmentIds[0])\r",
""
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<ActionResult<CorrespondenceOverviewExt>> InitializeCorresponde
return commandResult.Match(
data => Ok(new InitializeCorrespondencesResponseExt()
{
CorrespondenceIds = data.CorrespondenceIds,
Correspondences = data.Correspondences,
AttachmentIds = data.AttachmentIds
}),
Problem
Expand Down Expand Up @@ -89,7 +89,7 @@ public async Task<ActionResult<CorrespondenceOverviewExt>> UploadCorrespondences
return commandResult.Match(
data => Ok(new InitializeCorrespondencesResponseExt()
{
CorrespondenceIds = data.CorrespondenceIds,
Correspondences = data.Correspondences,
AttachmentIds = data.AttachmentIds
}),
Problem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Altinn.Correspondence.Application.InitializeCorrespondences;
using Altinn.Correspondence.Core.Models.Enums;

namespace Altinn.Correspondence.API.Models;

public class InitializeCorrespondencesResponseExt
{
public List<Guid> CorrespondenceIds { get; set; }
public List<CorrespondenceDetails> Correspondences { get; set; }
public List<Guid> AttachmentIds { get; set; }
}
Loading
Loading