Skip to content

Commit

Permalink
implemented tests for notifications project #GCPActive
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad committed Nov 13, 2023
1 parent c458592 commit ef75ef6
Show file tree
Hide file tree
Showing 17 changed files with 579 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace Altinn.Notifications.Core.Models.Notification
public class EmailNotificationWithResult : INotificationWithResult<EmailRecipient, EmailNotificationResultType>
{
/// <inheritdoc/>
public Guid Id { get; internal set; }
public Guid Id { get; }

/// <inheritdoc/>
public bool Succeeded { get; internal set; }

/// <inheritdoc/>
public EmailRecipient Recipient { get; internal set; }
public EmailRecipient Recipient { get; }

/// <inheritdoc/>
public NotificationResult<EmailNotificationResultType> ResultStatus { get; internal set; }
public NotificationResult<EmailNotificationResultType> ResultStatus { get; }

/// <summary>
/// Initializes a new instance of the <see cref="EmailNotificationWithResult"/> class.
Expand All @@ -30,5 +30,16 @@ public EmailNotificationWithResult(Guid id, EmailRecipient recipient, Notificati
Recipient = recipient;
ResultStatus = result;
}

/// <summary>
/// Initializes a new instance of the <see cref="EmailNotificationWithResult"/> class.
/// </summary>
internal EmailNotificationWithResult(Guid id, bool succeeded, EmailRecipient recipient, NotificationResult<EmailNotificationResultType> result)
{
Id = id;
Succeeded = succeeded;
Recipient = recipient;
ResultStatus = result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ private void ProcessNotificationResults(EmailNotificationSummary summary)
{
summary.Generated = summary.Notifications.Count;

foreach (NotificationResult<EmailNotificationResultType> resultStatus in summary.Notifications.Select(n => n.ResultStatus))
foreach (EmailNotificationWithResult notification in summary.Notifications)
{
NotificationResult<EmailNotificationResultType> resultStatus = notification.ResultStatus;
if (_successResults.Contains(resultStatus.Result))
{
notification.Succeeded = true;
++summary.Succeeded;
}

Expand Down
41 changes: 22 additions & 19 deletions src/Altinn.Notifications/Mappers/NotificationSummaryMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,31 @@ public static EmailNotificationSummaryExt MapToEmailNotificationSummaryExt(this
/// </summary>
public static List<EmailNotificationWithResultExt> MapToEmailNotificationWithResultExt(this List<EmailNotificationWithResult> notifications)
{
List<EmailNotificationWithResultExt> result = new List<EmailNotificationWithResultExt>();
List<EmailNotificationWithResultExt> result = notifications.Select(n => n.MapToEmailNotificationWithResultExt()).ToList();

foreach (var notification in notifications)
return result;
}

/// <summary>
/// Maps a <see cref="EmailNotificationWithResult"/> to a <see cref="EmailNotificationWithResultExt"/>
/// </summary>
public static EmailNotificationWithResultExt MapToEmailNotificationWithResultExt(this EmailNotificationWithResult notification)
{
return new EmailNotificationWithResultExt()
{
result.Add(new EmailNotificationWithResultExt()
Id = notification.Id,
Succeeded = notification.Succeeded,
Recipient = new()
{
Id = notification.Id,
Succeeded = notification.Succeeded,
Recipient = new()
{
EmailAddress = notification.Recipient.ToAddress
},
SendStatus = new()
{
Status = notification.ResultStatus.Result.ToString(),
StatusDescription = notification.ResultStatus.ResultDescription,
LastUpdate = notification.ResultStatus.ResultTime
}
});
}

return result;
EmailAddress = notification.Recipient.ToAddress
},
SendStatus = new()
{
Status = notification.ResultStatus.Result.ToString(),
StatusDescription = notification.ResultStatus.ResultDescription,
LastUpdate = notification.ResultStatus.ResultTime
}
};
}
}
}
37 changes: 5 additions & 32 deletions src/Altinn.Notifications/Models/EmailNotificationSummaryExt.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Text.Json.Serialization;

using Altinn.Notifications.Models;

namespace Altinn.Notifications.Core.Models.Notification
{
/// <summary>
Expand All @@ -15,56 +13,31 @@ public class EmailNotificationSummaryExt
/// <summary>
/// The order id
/// </summary>
[JsonPropertyName("orderId")]
public Guid OrderId { get; set; }

/// <summary>
/// The senders reference
/// </summary>
[JsonPropertyName("sendersReference")]
public string? SendersReference { get; set; }

/// <summary>
/// The number of generated email notifications
/// </summary>
[JsonPropertyName("generated")]
public int Generated { get; set; }

/// <summary>
/// The number of email notifications that were sent successfully
/// </summary>
[JsonPropertyName("succeeded")]
public int Succeeded { get; set; }

/// <summary>
/// A list of notifications with send result
/// </summary>
[JsonPropertyName("notifications")]
public List<EmailNotificationWithResultExt> Notifications { get; set; } = new List<EmailNotificationWithResultExt>();
}

/// <summary>
/// EmailNotificationWithResultExt class
/// </summary>
public class EmailNotificationWithResultExt
{
/// <summary>
/// The notification id
/// </summary>
[JsonPropertyName("id")]
public Guid Id { get; set; }

/// <summary>
/// Boolean indicating if the sending of the notification was successful
/// </summary>
[JsonPropertyName("succeeded")]
public bool Succeeded { get; set; }

/// <summary>
/// The recipient of the notification
/// </summary>
[JsonPropertyName("recipient")]
public RecipientExt Recipient { get; set; } = new();

/// <summary>
/// The result status of the notification
/// </summary>
[JsonPropertyName("sendStatus")]
public StatusExt SendStatus { get; set; } = new();
}
}
36 changes: 36 additions & 0 deletions src/Altinn.Notifications/Models/EmailNotificationWithResultExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Text.Json.Serialization;

using Altinn.Notifications.Models;

namespace Altinn.Notifications.Core.Models.Notification
{
/// <summary>
/// EmailNotificationWithResultExt class
/// </summary>
public class EmailNotificationWithResultExt
{
/// <summary>
/// The notification id
/// </summary>
[JsonPropertyName("id")]
public Guid Id { get; set; }

/// <summary>
/// Boolean indicating if the sending of the notification was successful
/// </summary>
[JsonPropertyName("succeeded")]
public bool Succeeded { get; set; }

/// <summary>
/// The recipient of the notification
/// </summary>
[JsonPropertyName("recipient")]
public RecipientExt Recipient { get; set; } = new();

/// <summary>
/// The result status of the notification
/// </summary>
[JsonPropertyName("sendStatus")]
public StatusExt SendStatus { get; set; } = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public async Task DisposeAsync()

protected virtual async Task Dispose(bool disposing)
{
string sql = $"delete from notifications.orders where sendersreference = '{_sendersRef}'";

await PostgreUtil.RunSql(sql);
await PostgreUtil.DeleteOrderFromDb(_sendersRef);
await KafkaUtil.DeleteTopicAsync(_statusUpdatedTopicName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public async void Dispose()

protected virtual async Task Dispose(bool disposing)
{
string sql = $"delete from notifications.orders where sendersreference = '{_sendersRef}'";
await PostgreUtil.RunSql(sql);
await PostgreUtil.DeleteOrderFromDb(_sendersRef);
await KafkaUtil.DeleteTopicAsync(_pastDueOrdersTopicName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public async void Dispose()
protected virtual async Task Dispose(bool disposing)
{
await KafkaUtil.DeleteTopicAsync(_retryTopicName);
string sql = $"delete from notifications.orders where sendersreference = '{_sendersRef}'";
await PostgreUtil.RunSql(sql);
await PostgreUtil.DeleteOrderFromDb(_sendersRef);
}

private static async Task<long> SelectCompletedOrderCount(Guid orderId)
Expand Down
Loading

0 comments on commit ef75ef6

Please sign in to comment.