Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmosquera committed Oct 4, 2024
1 parent e50f614 commit 605ee93
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions DopplerBeplic.Tests/GetTemplateMessageStatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using DopplerBeplic.Models.Responses;
using DopplerBeplic.Services.Interfaces;
using Newtonsoft.Json;

namespace DopplerBeplic.Tests
{
public class GetTemplateMessageStatusTests
{
[Fact]
public async Task GET_get_message_status_should_not_authorize_without_token()
{
var application = new PlaygroundApplication();
var client = application.CreateClient();

var response = await client.GetAsync("/customer/messages/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Equal("Bearer", response.Headers.WwwAuthenticate.ToString());
}

[Fact]
public async Task GET_get_message_status_should_authorize_super_user_and_returns_status()
{
var bodyParams = new { };

var application = new PlaygroundApplication();

var messageId = Guid.NewGuid().ToString();

var expectedResponse = new TemplateMessageResponse()
{
MessageId = messageId,
Status = new List<TemplateMessageStatusResponse>()
{
new TemplateMessageStatusResponse()
{
Status = "READ",
StatusDate = DateTime.UtcNow
}
}
};

var beplicServiceMock = new Mock<IBeplicService>();
beplicServiceMock.Setup(x => x.GetMessageStatus(messageId)).ReturnsAsync(expectedResponse);

application.ConfigureServices(services => services.AddSingleton(beplicServiceMock.Object));

var client = application.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TestUsersData.Token_Superuser_Expire2033_05_18);

var response = await client.GetAsync($"/customer/messages/{messageId}");

Assert.Equal(HttpStatusCode.OK, response.StatusCode);

beplicServiceMock.Verify(x => x.GetMessageStatus(messageId), Times.Once);

var content = await response.Content.ReadAsStringAsync();

var messageResponse = JsonConvert.DeserializeObject<TemplateMessageResponse>(content);

Assert.Equal(messageResponse?.MessageId, expectedResponse.MessageId);
Assert.Equal("READ", messageResponse?.Status?[0].Status);
}

}
}

0 comments on commit 605ee93

Please sign in to comment.