diff --git a/src/SlackConnector/Connections/Clients/Chat/FlurlChatClient.cs b/src/SlackConnector/Connections/Clients/Chat/FlurlChatClient.cs index 9dfa7c7..f248c5f 100644 --- a/src/SlackConnector/Connections/Clients/Chat/FlurlChatClient.cs +++ b/src/SlackConnector/Connections/Clients/Chat/FlurlChatClient.cs @@ -21,21 +21,18 @@ public FlurlChatClient(IResponseVerifier responseVerifier) public async Task PostMessage(string slackKey, string channel, string text, IList attachments) { - var request = ClientConstants + var response = await ClientConstants .SlackApiHost .AppendPathSegment(SEND_MESSAGE_PATH) - .SetQueryParam("token", slackKey) - .SetQueryParam("channel", channel) - .SetQueryParam("text", text) - .SetQueryParam("as_user", "true") - .SetQueryParam("link_names", "true"); - - if (attachments != null && attachments.Any()) - { - request.SetQueryParam("attachments", JsonConvert.SerializeObject(attachments)); - } + .WithOAuthBearerToken(slackKey) + .PostJsonAsync(new { + channel = channel, + text = text, + as_user = true, + link_names = true, + attachments = attachments + }).ReceiveJson(); - var response = await request.GetJsonAsync(); _responseVerifier.VerifyResponse(response); } } diff --git a/tests/SlackConnector.Tests.Unit/Connections/Clients/Flurl/FlurlChatClientTests.cs b/tests/SlackConnector.Tests.Unit/Connections/Clients/Flurl/FlurlChatClientTests.cs index 13f879d..5dc1288 100644 --- a/tests/SlackConnector.Tests.Unit/Connections/Clients/Flurl/FlurlChatClientTests.cs +++ b/tests/SlackConnector.Tests.Unit/Connections/Clients/Flurl/FlurlChatClientTests.cs @@ -50,18 +50,22 @@ public async Task should_call_expected_url_with_given_slack_key() _responseVerifierMock.Verify(x => x.VerifyResponse(Looks.Like(expectedResponse))); _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH)) - .WithQueryParamValue("token", slackKey) - .WithQueryParamValue("channel", channel) - .WithQueryParamValue("text", text) - .WithQueryParamValue("as_user", "true") - .WithQueryParamValue("link_names", "true") - .WithoutQueryParam("attachments") + .WithOAuthBearerToken(slackKey) + .WithRequestJson(new + { + channel = channel, + text = text, + as_user = true, + link_names = true, + attachments = (object)null + }) .Times(1); } [Fact] public async Task should_add_attachments_if_given() { + const string slackKey = "something-that-looks-like-a-slack-key"; // given _httpTest.RespondWithJson(new StandardResponse()); var attachments = new List @@ -71,12 +75,20 @@ public async Task should_add_attachments_if_given() }; // when - await _chatClient.PostMessage(It.IsAny(), It.IsAny(), It.IsAny(), attachments); + await _chatClient.PostMessage(slackKey, It.IsAny(), It.IsAny(), attachments); // then _httpTest .ShouldHaveCalled(ClientConstants.SlackApiHost.AppendPathSegment(FlurlChatClient.SEND_MESSAGE_PATH)) - .WithQueryParamValue("attachments", JsonConvert.SerializeObject(attachments)) + .WithOAuthBearerToken(slackKey) + .WithRequestJson(new + { + channel = (string)null, + text = (string)null, + as_user = true, + link_names = true, + attachments = attachments + }) .Times(1); } }