Add test for the commands controller
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
require "test_helper"
|
||||
|
||||
class CommandsControllerTest < ActionDispatch::IntegrationTest
|
||||
include VcrTestHelper
|
||||
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
@@ -21,12 +23,39 @@ class CommandsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to cards_path
|
||||
end
|
||||
|
||||
test "commands requiring confirmation return a 409 conflict response" do
|
||||
test "command requiring a confirmation without redirect" do
|
||||
assert_no_difference -> { users(:kevin).commands.count } do
|
||||
post commands_path, params: { command: "/assign @kevin" }, headers: { "HTTP_REFERER" => cards_path }
|
||||
end
|
||||
|
||||
assert_response :conflict
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
assert_equal "Assign Kevin to 3 cards", json["confirmation"]
|
||||
assert_nil json["redirect_to"]
|
||||
end
|
||||
|
||||
test "command requiring a confirmation with a redirect" do
|
||||
assert_no_difference -> { users(:kevin).commands.count } do
|
||||
post commands_path, params: { command: "close cards assigned to jz" }, headers: { "HTTP_REFERER" => cards_path }
|
||||
end
|
||||
|
||||
assert_response :conflict
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
assert_match /Close 2 cards/, json["confirmation"]
|
||||
assert_equal cards_path(assignee_ids: [ users(:jz) ]), json["redirect_to"]
|
||||
end
|
||||
|
||||
test "get insight" do
|
||||
assert_difference -> { users(:kevin).commands.root.count }, +1 do
|
||||
post commands_path, params: { command: "summarize this" }, headers: { "HTTP_REFERER" => card_path(cards(:logo)) }
|
||||
end
|
||||
|
||||
assert_response :accepted
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
assert_not_nil json["message"]
|
||||
end
|
||||
|
||||
test "get a 422 on errors" do
|
||||
|
||||
Reference in New Issue
Block a user