|
1 | 1 | require 'helper'
|
2 | 2 |
|
3 | 3 | describe 'api' do
|
4 |
| - let (:client) { ApiAiRuby::Client.new(:client_access_token => '3485a96fb27744db83e78b8c4bc9e7b7')} |
| 4 | + before(:all) { @client = ApiAiRuby::Client.new( |
| 5 | + :client_access_token => '3485a96fb27744db83e78b8c4bc9e7b7', |
| 6 | + :api_session_id => 'testsession' |
| 7 | + )} |
5 | 8 |
|
6 | 9 | it 'should return response' do
|
7 |
| - response = client.text_request 'Hello' |
| 10 | + response = @client.text_request 'Hello' |
8 | 11 | expect(response[:result][:resolvedQuery]).to eq 'Hello'
|
9 | 12 | expect(response[:result][:action]).to eq 'greeting'
|
10 | 13 | end
|
11 | 14 |
|
12 | 15 | it 'should use input contexts' do
|
13 |
| - response = client.text_request 'Hello', :resetContexts => true |
| 16 | + response = @client.text_request 'Hello', :resetContexts => true |
14 | 17 | expect(response[:result][:action]).to eq 'greeting'
|
15 | 18 |
|
16 |
| - response = client.text_request 'Hello', :contexts => ['firstContext'], :resetContexts => true |
| 19 | + response = @client.text_request 'Hello', :contexts => ['firstContext'], :resetContexts => true |
17 | 20 | expect(response[:result][:action]).to eq 'firstGreeting'
|
18 | 21 |
|
19 |
| - response = client.text_request 'Hello', :contexts => ['secondContext'], :resetContexts => true |
| 22 | + response = @client.text_request 'Hello', :contexts => ['secondContext'], :resetContexts => true |
20 | 23 | expect(response[:result][:action]).to eq 'secondGreeting'
|
21 | 24 | end
|
22 | 25 |
|
23 | 26 | it 'should return output contexts' do
|
24 |
| - response = client.text_request 'weather', :resetContexts => true |
| 27 | + response = @client.text_request 'weather', :resetContexts => true |
25 | 28 | expect(response[:result][:action]).to eq 'showWeather'
|
26 | 29 | expect(response[:result][:contexts]).not_to be_nil
|
27 | 30 | expect(response[:result][:contexts].any? {|context| context[:name] == 'weather'}).to be true
|
|
33 | 36 | end
|
34 | 37 |
|
35 | 38 | it 'should send voiceData to API' do
|
36 |
| - expect(client.voice_request(File.new(fixture_path + '/hello.wav'))[:result][:resolvedQuery]).to eq 'hello' |
| 39 | + expect(@client.voice_request(File.new(fixture_path + '/hello.wav'))[:result][:resolvedQuery]).to eq 'hello' |
37 | 40 | end
|
38 | 41 |
|
39 | 42 | it 'should correctly set contexts with parameters' do
|
40 |
| - client.text_request 'Hello', :resetContexts => true |
41 |
| - response = client.text_request 'hello', contexts: [{ name: 'user', parameters: { first_name: 'Johnny' }}] |
| 43 | + @client.text_request 'Hello', :resetContexts => true |
| 44 | + response = @client.text_request 'hello', contexts: [{ name: 'user', parameters: { first_name: 'Johnny' }}] |
42 | 45 | expect(response[:result][:contexts]).not_to be_nil
|
43 | 46 | expect(response[:result][:contexts][0][:name]).to eq 'user'
|
44 | 47 | expect(response[:result][:contexts][0][:parameters][:first_name]).to eq 'Johnny'
|
45 | 48 | end
|
46 | 49 |
|
47 | 50 | it 'should use custom entities' do
|
48 |
| - response = client.text_request 'hi nori', entities: [ |
| 51 | + response = @client.text_request 'hi nori', entities: [ |
49 | 52 | {
|
50 | 53 | name: 'dwarfs',
|
51 | 54 | entries: [
|
|
58 | 61 | expect(response[:result][:action]).to eq 'say_hi'
|
59 | 62 | expect(response[:result][:fulfillment][:speech]). to eq 'hi Bilbo, I am Ori'
|
60 | 63 | end
|
61 |
| -=begin |
62 |
| - it 'should use custom entities through separate request' do |
63 |
| - entry = ApiAiRuby::Entry.new 'giur', %w(Giur Amaldur) |
64 |
| - client.user_entities_request('dwarfs', [entry]) |
65 | 64 |
|
66 |
| - response = client.text_request 'hi Amaldur' |
67 |
| - expect(response[:result][:action]).to eq 'say_hi' |
68 |
| - expect(response[:result][:fulfillment][:speech]). to eq 'hi Bilbo, I am giur' |
| 65 | + describe 'userEntities endpoint' do |
69 | 66 |
|
70 |
| - end |
| 67 | + before(:all) { @uer = @client.user_entities_request} |
71 | 68 |
|
72 |
| - it 'should use custom entities through separate request' do |
| 69 | + let(:entity1) { |
| 70 | + ApiAiRuby::Entity.new 'dwarfs', [ApiAiRuby::Entry.new('giur', %w(Giur Amaldur))] |
| 71 | + } |
73 | 72 |
|
74 |
| - entity1 = ApiAiRuby::Entity.new 'dwarfs', [ |
75 |
| - ApiAiRuby::Entry.new('test1', %w(test1 test_1)), |
76 |
| - ApiAiRuby::Entry.new('test2', %w(test2 test_2)) |
77 |
| - ] |
| 73 | + let(:entries) { |
| 74 | + [ApiAiRuby::Entry.new('mami', %w(Mami Nami))] |
| 75 | + } |
78 | 76 |
|
79 |
| - entity2 = ApiAiRuby::Entity.new 'dwarfs', [ |
80 |
| - ApiAiRuby::Entry.new('test1', %w(test1 test_1)), |
81 |
| - ApiAiRuby::Entry.new('test2', %w(test2 test_2)) |
82 |
| - ] |
| 77 | + it 'should create custom entities through separate request' do |
| 78 | + @uer.create(entity1) |
| 79 | + response = @client.text_request 'hi Amaldur' |
| 80 | + expect(response[:result][:action]).to eq 'say_hi' |
| 81 | + expect(response[:result][:fulfillment][:speech]). to eq 'hi Bilbo, I am giur' |
| 82 | + end |
| 83 | + |
| 84 | + it 'should update custom entities through separate request' do |
| 85 | + @uer.update('dwarfs', entries) |
| 86 | + response = @client.text_request 'hi Nami' |
| 87 | + expect(response[:result][:action]).to eq 'say_hi' |
| 88 | + expect(response[:result][:fulfillment][:speech]). to eq 'hi Bilbo, I am mami' |
| 89 | + end |
| 90 | + |
| 91 | + it 'should retrieve custom enitities' do |
| 92 | + response = @uer.retrieve('dwarfs') |
| 93 | + expect(response[:name]).to eq 'dwarfs' |
| 94 | + expect(response[:entries][0][:value]).to eq 'mami' |
| 95 | + end |
| 96 | + |
| 97 | + it 'should remove custom entities' do |
| 98 | + @uer.delete('dwarfs') |
| 99 | + expect{@uer.retrieve('dwarfs')}.to raise_error(ApiAiRuby::RequestError) |
| 100 | + end |
| 101 | + |
| 102 | + end |
83 | 103 |
|
84 |
| - uer = client.user_entities_request |
85 |
| - #response = uer.create([entity1, entity2]) |
86 |
| - response = uer.create(entity1) |
87 |
| - response = uer.retrieve('dwarfs') |
88 |
| - puts(response) |
89 | 104 |
|
90 |
| -=end |
91 | 105 | end
|
0 commit comments