Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Switch to HTTP POST instead of GET #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/SlackConnector/Connections/Clients/Chat/FlurlChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,18 @@ public FlurlChatClient(IResponseVerifier responseVerifier)

public async Task PostMessage(string slackKey, string channel, string text, IList<SlackAttachment> 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<StandardResponse>();

var response = await request.GetJsonAsync<StandardResponse>();
_responseVerifier.VerifyResponse(response);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SlackAttachment>
Expand All @@ -71,12 +75,20 @@ public async Task should_add_attachments_if_given()
};

// when
await _chatClient.PostMessage(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), attachments);
await _chatClient.PostMessage(slackKey, It.IsAny<string>(), It.IsAny<string>(), 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);
}
}
Expand Down