@@ -128,4 +128,70 @@ def test_delete_session
128128 )
129129 assert_nil ( service_response )
130130 end
131+
132+ def test_message_stateless
133+ # service.set_default_headers("x-watson-learning-opt-out" => true)
134+ assistant_id = "f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec"
135+ message_response = {
136+ "context" => {
137+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b" ,
138+ "system" => {
139+ "dialog_stack" => [ "root" ] ,
140+ "dialog_turn_counter" => 1 ,
141+ "dialog_request_counter" => 1
142+ }
143+ } ,
144+ "intents" => [ ] ,
145+ "entities" => [ ] ,
146+ "input" => { } ,
147+ "output" => {
148+ "text" => "okay" ,
149+ "log_messages" => [ ]
150+ }
151+ }
152+ headers = {
153+ "Content-Type" => "application/json"
154+ }
155+ stub_request ( :post , "https://gateway.watsonplatform.net/assistant/api/v2/assistants/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/message?version=2018-02-16" )
156+ . with (
157+ body : "{\" input\" :{\" text\" :\" Turn on the lights\" }}" ,
158+ headers : {
159+ "Accept" => "application/json" ,
160+ "Content-Type" => "application/json" ,
161+ "Host" => "gateway.watsonplatform.net"
162+ }
163+ ) . to_return ( status : 200 , body : message_response . to_json , headers : headers )
164+ service_response = service . message_stateless (
165+ assistant_id : assistant_id ,
166+ input : { "text" => "Turn on the lights" } ,
167+ context : nil
168+ )
169+ assert_equal ( message_response , service_response . result )
170+
171+ message_ctx = {
172+ "context" => {
173+ "conversation_id" => "1b7b67c0-90ed-45dc-8508-9488bc483d5b" ,
174+ "system" => {
175+ "dialog_stack" => [ "root" ] ,
176+ "dialog_turn_counter" => 2 ,
177+ "dialog_request_counter" => 1
178+ }
179+ }
180+ }
181+ stub_request ( :post , "https://gateway.watsonplatform.net/assistant/api/v2/assistants/f8fdbc65-e0bd-4e43-b9f8-2975a366d4ec/message?version=2018-02-16" )
182+ . with (
183+ body : "{\" input\" :{\" text\" :\" Turn on the lights\" },\" context\" :\" {\\ \" conversation_id\\ \" :\\ \" 1b7b67c0-90ed-45dc-8508-9488bc483d5b\\ \" ,\\ \" system\\ \" :{\\ \" dialog_stack\\ \" :[\\ \" root\\ \" ],\\ \" dialog_turn_counter\\ \" :2,\\ \" dialog_request_counter\\ \" :1}}\" }" ,
184+ headers : {
185+ "Accept" => "application/json" ,
186+ "Content-Type" => "application/json" ,
187+ "Host" => "gateway.watsonplatform.net"
188+ }
189+ ) . to_return ( status : 200 , body : message_response . to_json , headers : headers )
190+ service_response = service . message_stateless (
191+ assistant_id : assistant_id ,
192+ input : { "text" => "Turn on the lights" } ,
193+ context : message_ctx [ "context" ] . to_json
194+ )
195+ assert_equal ( message_response , service_response . result )
196+ end
131197end
0 commit comments