Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 12, 2023
1 parent f3da52f commit 6a74326
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions tools/TestSuite/TestSuite.ApiTests/SmsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ==========================================================================

using Notifo.SDK;
using System.Linq;
using TestSuite.Fixtures;
using TestSuite.Utils;

Expand Down Expand Up @@ -361,30 +362,10 @@ PublishDto BuildEvent(string subject)


// Get SMS status
var messageBird = new MessageBirdClient(AccessKey);

using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)))
{
while (!cts.IsCancellationRequested)
{
var messages = await messageBird.GetMessagesAsync(200);

if (messages.Items.Any(x =>
x.Body.Contains(subjectId3, StringComparison.OrdinalIgnoreCase) &&
x.Body.Contains(subjectMore, StringComparison.OrdinalIgnoreCase) &&
x.Recipients.Items[0].Status == "delivered"))
{
return;
}

await Task.Delay(1000);
}
}

Assert.False(true, "SMS not sent.");
await AssertDeliveredAsync(subjectId3, 2);
}

[Fact]
[Fact(Skip = "Not stable")]
public async Task Should_send_sms_with_channel_group_key()
{
// In pull requests from forks we cannot inject the secret key.
Expand Down Expand Up @@ -487,20 +468,26 @@ PublishDto BuildEvent(string subject)

await _.Client.Events.PostEventsAsync(app_0.Id, publishRequest);

var subjectMore = "+ 2 more";

// Get SMS status
await AssertDeliveredAsync(subjectId3, 2);
}

private static async Task AssertDeliveredAsync(string subjectId, int more)
{
var subjectMore = $"+ {more} more";

// Get SMS status
var messageBird = new MessageBirdClient(AccessKey);

using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)))
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(120)))
{
while (!cts.IsCancellationRequested)
{
var messages = await messageBird.GetMessagesAsync(200);

if (messages.Items.Any(x =>
x.Body.Contains(subjectId3, StringComparison.OrdinalIgnoreCase) &&
x.Body.Contains(subjectId, StringComparison.OrdinalIgnoreCase) &&
x.Body.Contains(subjectMore, StringComparison.OrdinalIgnoreCase) &&
x.Recipients.Items[0].Status == "delivered"))
{
Expand Down

0 comments on commit 6a74326

Please sign in to comment.