From 605ee9371b856198c507bd57212f95418c4ff711 Mon Sep 17 00:00:00 2001 From: mmosquera Date: Fri, 4 Oct 2024 13:15:12 -0300 Subject: [PATCH] chore: add tests --- .../GetTemplateMessageStatusTests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 DopplerBeplic.Tests/GetTemplateMessageStatusTests.cs diff --git a/DopplerBeplic.Tests/GetTemplateMessageStatusTests.cs b/DopplerBeplic.Tests/GetTemplateMessageStatusTests.cs new file mode 100644 index 0000000..55fc456 --- /dev/null +++ b/DopplerBeplic.Tests/GetTemplateMessageStatusTests.cs @@ -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() + { + new TemplateMessageStatusResponse() + { + Status = "READ", + StatusDate = DateTime.UtcNow + } + } + }; + + var beplicServiceMock = new Mock(); + 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(content); + + Assert.Equal(messageResponse?.MessageId, expectedResponse.MessageId); + Assert.Equal("READ", messageResponse?.Status?[0].Status); + } + + } +}