-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
131 additions
and
12 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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/Altinn.Notifications.Persistence/Migration/v0.06/01-alter-tables.sql
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ALTER TABLE notifications.emailnotifications | ||
ADD COLUMN operationid text; | ||
ADD COLUMN IF NOT EXISTS operationid text; |
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
75 changes: 75 additions & 0 deletions
75
....IntegrationTests/Notifications.Integrations/TestingConsumers/EmailStatusConsumerTests.cs
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Altinn.Notifications.Core.Enums; | ||
using Altinn.Notifications.Core.Models.Notification; | ||
using Altinn.Notifications.Core.Models.Orders; | ||
using Altinn.Notifications.Integrations.Kafka.Consumers; | ||
using Altinn.Notifications.IntegrationTests.Utils; | ||
|
||
using Microsoft.Extensions.Hosting; | ||
|
||
using Xunit; | ||
|
||
namespace Altinn.Notifications.IntegrationTests.Notifications.Core.Consumers; | ||
|
||
public class EmailStatusConsumerTests : IDisposable | ||
{ | ||
private readonly string _statusUpdatedTopicName = Guid.NewGuid().ToString(); | ||
private readonly string _sendersRef = $"ref-{Guid.NewGuid()}"; | ||
|
||
[Fact] | ||
public async Task RunTask_ConfirmExpectedSideEffects() | ||
{ | ||
// Arrange | ||
Dictionary<string, string> vars = new() | ||
{ | ||
{ "KafkaSettings__EmailStatusUpdatedTopicName", _statusUpdatedTopicName }, | ||
{ "KafkaSettings__Admin__TopicList", $"[\"{_statusUpdatedTopicName}\"]" } | ||
}; | ||
|
||
using EmailStatusConsumer consumerService = (EmailStatusConsumer)ServiceUtil | ||
.GetServices(new List<Type>() { typeof(IHostedService) }, vars) | ||
.First(s => s.GetType() == typeof(EmailStatusConsumer))!; | ||
|
||
(NotificationOrder Order, EmailNotification Notification) = await PostgreUtil.PopulateDBWithOrderAndEmailNotification(_sendersRef); | ||
|
||
SendOperationResult sendOperationResult = new() | ||
{ | ||
NotificationId = Notification.Id, | ||
OperationId = Guid.NewGuid().ToString(), | ||
SendResult = EmailNotificationResultType.Succeeded | ||
}; | ||
await KafkaUtil.PublishMessageOnTopic(_statusUpdatedTopicName, sendOperationResult.Serialize()); | ||
|
||
|
||
// Act | ||
await consumerService.StartAsync(CancellationToken.None); | ||
await Task.Delay(10000); | ||
await consumerService.StopAsync(CancellationToken.None); | ||
|
||
// Assert | ||
|
||
string emailNotificationStatus = await SelectEmailNotificationStatus(Notification.Id); | ||
Assert.Equal(emailNotificationStatus, EmailNotificationResultType.Succeeded.ToString()); | ||
|
||
} | ||
|
||
public async void Dispose() | ||
{ | ||
await Dispose(true); | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual async Task Dispose(bool disposing) | ||
{ | ||
string sql = $"delete from notifications.orders where sendersreference = '{_sendersRef}'"; | ||
|
||
await PostgreUtil.RunSql(sql); | ||
await KafkaUtil.DeleteTopicAsync(_statusUpdatedTopicName); | ||
} | ||
|
||
private async Task<string> SelectEmailNotificationStatus(Guid notificationId) | ||
{ | ||
string sql = $"select result from notifications.emailnotifications where alternateid = '{notificationId}'"; | ||
return await PostgreUtil.RunSqlReturnStringOutput(sql); | ||
} | ||
} |
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