|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe Layer::Api::Connection do |
| 4 | + |
4 | 5 | before do |
5 | 6 | @layer = Layer::Api::Client.new |
6 | 7 | @conn = @layer.connection |
|
58 | 59 | end |
59 | 60 | end |
60 | 61 | end |
| 62 | + |
| 63 | + describe ".call" do |
| 64 | + it "should run request & return response body" do |
| 65 | + VCR.use_cassette('conversation') do |
| 66 | + existing_conversation = @layer.create_conversation(conversation_params) |
| 67 | + existing_id = @layer.get_stripped_id(existing_conversation["id"]) |
| 68 | + |
| 69 | + url = "#{@layer.base_url}/conversations/#{existing_id}" |
| 70 | + body = @layer.call(:get, url, conversation_params) |
| 71 | + |
| 72 | + # Compare body with expected values |
| 73 | + expect(body["participants"]).to match_array(conversation_params[:participants]) |
| 74 | + expect(body["distinct"]).to eq(conversation_params[:distinct]) |
| 75 | + expect(body["metadata"].to_json).to eq(conversation_params[:metadata].to_json) |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + it "should run request & return nil if response has no body" do |
| 80 | + VCR.use_cassette('conversation') do |
| 81 | + existing_conversation = @layer.create_conversation(conversation_params) |
| 82 | + existing_conversation_id = @layer.get_stripped_id(existing_conversation["id"]) |
| 83 | + |
| 84 | + operations = [ |
| 85 | + {operation: "add", property: "participants", value: "user1"}, |
| 86 | + {operation: "add", property: "participants", value: "user2"} |
| 87 | + ] |
| 88 | + |
| 89 | + response = @layer.edit_conversation(existing_conversation_id, operations) |
| 90 | + expect(response).to be(nil) |
| 91 | + end |
| 92 | + end |
| 93 | + end |
61 | 94 | end |
0 commit comments