spec/lib/chatops/controller_spec.rb in chatops-controller-4.0.1 vs spec/lib/chatops/controller_spec.rb in chatops-controller-4.1.0
- old
+ new
@@ -23,10 +23,17 @@
"how to foo and bar" do
raise "there's always params" unless jsonrpc_params.respond_to?(:[])
jsonrpc_success "You just foo and bar like it just don't matter"
end
+ chatop :proxy_parameters,
+ /(?:proxy_parameters)/,
+ "proxy parameters back to test" do
+ response = { :params => params, :jsonrpc_params => jsonrpc_params }.to_json
+ jsonrpc_success response
+ end
+
skip_before_action :ensure_method_exists, only: :non_chatop_method
def non_chatop_method
render :plain => "Why would you have something thats not a chatop?"
end
@@ -226,10 +233,16 @@
"foobar" => {
"help" => "how to foo and bar",
"regex" => /(?:how can i foo and bar all at once)?/.source,
"params" => [],
"path" => "foobar"
+ },
+ "proxy_parameters" => {
+ "help" => "proxy parameters back to test",
+ "regex" => /(?:proxy_parameters)/.source,
+ "params" => [],
+ "path" => "proxy_parameters"
}
},
"version" => "3"
})
end
@@ -291,10 +304,30 @@
"result" => "You can deploy foo just fine."
})
expect(response.status).to eq 200
end
+ it "passes all expected paramters" do
+ rails_flexible_post :execute_chatop, {
+ :chatop => "proxy_parameters",
+ :user => "foo",
+ :mention_slug => "mention_slug_here",
+ :message_id => "message_id_here",
+ :room_id => "#someroom",
+ :unknown_key => "few" # This should get ignored
+ }, {
+ "app" => "foo"
+ }
+ expect(json_response).to eq({
+ "jsonrpc" => "2.0",
+ "id" => nil,
+ "result" => "{\"params\":{\"action\":\"proxy_parameters\",\"chatop\":\"proxy_parameters\",\"controller\":\"anonymous\",\"mention_slug\":\"mention_slug_here\",\"message_id\":\"message_id_here\",\"room_id\":\"#someroom\",\"user\":\"foo\"},\"jsonrpc_params\":{\"app\":\"foo\"}}"
+ })
+ expect(response.status).to eq 200
+ end
+
+
it "uses typical controller fun like before_action" do
rails_flexible_post :execute_chatop, :chatop => "wcid", :user => "foo"
expect(json_response).to eq({
"jsonrpc" => "2.0",
"id" => nil,
@@ -356,9 +389,18 @@
chat "where can i deploy foobar --this-is-sparta", "bhuga"
expect(request.params["action"]).to eq "execute_chatop"
expect(request.params["chatop"]).to eq "wcid"
expect(request.params["user"]).to eq "bhuga"
expect(request.params["params"]["this-is-sparta"]).to eq "true"
+ end
+
+ it "sends along all the parameters" do
+ chat "where can i deploy foobar", "my_username", "room_id_5", "message_id_6"
+ expect(request.params["action"]).to eq "execute_chatop"
+ expect(request.params["chatop"]).to eq "wcid"
+ expect(request.params["user"]).to eq "my_username"
+ expect(request.params["room_id"]).to eq "room_id_5"
+ expect(request.params["message_id"]).to eq "message_id_6"
end
it "anchors regexes" do
expect {
chat "too bad that this message doesn't start with where can i deploy foobar", "bhuga"