-
Notifications
You must be signed in to change notification settings - Fork 0
5. Adding a New Command Hints and Tips 🕳
To add a new command, for example "@CloudOpsBot help" add a new test to slack_spec.rb
and follow standard TDD processes.
Initially you can copy another test and this should looks something like the following:
it "verifies and responds with 'help' message when slack sends a string 'help' app mention request from a channel" do
headers = { "X-Slack-Request-Timestamp" => "1642698248", "X-Slack-Signature" => "v0=fe7c0d0cc0fb94eb1ae7bfbdc783d2f69e5b0d41de970d5d46fed65633847eeb" }
post "/slack/events", :params => { :slack => JSON.parse(File.read("./spec/lib/data/app_mention_help.json")) }, :headers => headers
expect(response).to have_http_status(:success)
expect(response.body).to eql("Hi <@U029KDGBGNT>, here's some help.")
end
Notably this test verifies requests from Slack, as such the test calls the method verify_slack_signature
from slack_controller.rb
and replicates the methodology illustrated in the linked documentation.
On the first run of a new test (using an X-Slack-Signature
from another test) the result should be:
Failure/Error: expect(response).to have_http_status(:success)
expected the response to have a success status code (2xx) but it was 401
This is because the computed_signature
and slack_signature
do not match.
Our new test will have a different X-Slack-Signature
than all other tests, to view the new X-Slack-Signature
for your new test add lines to print both computed_signature
and slack_signature
in the controller and re-run the tests. The computed_signature
and slack_signature
will not match, replace the X-Slack-Signature
in your new test with the computed_signature
. Re-run make test
and you should see a different error.
In future testing will be localised using either webmock
or vcr
.
01110111 01101000 01111001 00100000 01100001 01110010 01100101 00100000 01111001 01101111 01110101 00100000 01110010 01100101 01100001 01100100 01101001 01101110 01100111 00100000 01110100 01101000 01101001 01110011 00111111