Skip to content

Commit d2fb5fc

Browse files
committed
add tests for conversations client
1 parent ac5667f commit d2fb5fc

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

spec/conversation_client_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
describe MessageBird::ConversationClient do
4+
before(:all) do
5+
@client = MessageBird::ConversationClient.new('secret-access-key')
6+
end
7+
8+
context 'initialization' do
9+
it 'uses Conversations API base URL' do
10+
expect(@client.endpoint).to eq('https://conversations.messagebird.com/v1/')
11+
end
12+
13+
it 'uses the provided access key' do
14+
expect(@client.access_key).to eq('secret-access-key')
15+
end
16+
end
17+
18+
context 'performing a HTTP request' do
19+
before(:each) do
20+
stub_request(:get, 'https://conversations.messagebird.com/v1/conversations')
21+
.with(
22+
headers: {
23+
'Accept' => 'application/json',
24+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
25+
'Authorization' => "AccessKey #{@client.access_key}",
26+
'User-Agent' => "MessageBird/ApiClient/#{MessageBird::Version::STRING} Ruby/#{RUBY_VERSION}"
27+
}
28+
)
29+
.to_return(status: 200, body: File.new(File.join(File.dirname(__FILE__), './data/conversations/list.json')), headers: {})
30+
31+
@response = JSON.parse(@client.request(:get, 'conversations'), symbolize_names: true)
32+
end
33+
34+
it 'contains an offset in the HTTP response body' do
35+
expect(@response[:offset]).to be(0)
36+
end
37+
38+
it 'contains a limit in the HTTP response body' do
39+
expect(@response[:limit]).to be(20)
40+
end
41+
42+
it 'contains a count in the HTTP response body' do
43+
expect(@response[:count]).to be(2)
44+
end
45+
46+
it 'contains a totalCount in the HTTP response body' do
47+
expect(@response[:totalCount]).to be(2)
48+
end
49+
50+
it 'contains two items' do
51+
expect(@response[:items].length).to be(2)
52+
end
53+
end
54+
end

spec/data/conversations/list.json

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"offset": 0,
3+
"limit": 20,
4+
"count": 2,
5+
"totalCount": 2,
6+
"items": [
7+
{
8+
"id": "fbbdde79129f45e3a179458a91e2ead6",
9+
"contactId": "03dfc27855c3475b953d6200a1b7eaf7",
10+
"contact": {
11+
"id": "03dfc27855c3475b953d6200a1b7eaf7",
12+
"href": "https://rest.messagebird.com/contacts/03dfc27855c3475b953d6200a1b7eaf7",
13+
"msisdn": 31612345678,
14+
"firstName": "John",
15+
"lastName": "Doe",
16+
"customDetails": {
17+
"custom1": null,
18+
"custom2": null,
19+
"custom3": null,
20+
"custom4": null
21+
},
22+
"createdDatetime": "2018-08-01T09:45:52Z",
23+
"updatedDatetime": "2018-08-28T12:37:35Z"
24+
},
25+
"channels": [
26+
{
27+
"id": "619747f69cf940a98fb443140ce9aed2",
28+
"name": "My WhatsApp",
29+
"platformId": "whatsapp",
30+
"status": "active",
31+
"createdDatetime": "2018-08-28T11:56:57Z",
32+
"updatedDatetime": "2018-08-29T08:16:33Z"
33+
}
34+
],
35+
"status": "active",
36+
"createdDatetime": "2018-08-29T08:52:54Z",
37+
"updatedDatetime": "2018-08-29T08:52:54Z",
38+
"lastReceivedDatetime": "2018-08-29T08:52:54Z",
39+
"lastUsedChannelId": "619747f69cf940a98fb443140ce9aed2",
40+
"lastUsedPlatformId": "whatsapp",
41+
"messages": {
42+
"totalCount": 10,
43+
"href": "https://conversations.messagebird.com/v1/conversations/fbbdde79129f45e3a179458a91e2ead6/messages"
44+
}
45+
},
46+
{
47+
"id": "2e15efafec384e1c82e9842075e87beb",
48+
"contactId": "a621095fa44947a28b441cfdf85cb802",
49+
"contact": {
50+
"id": "a621095fa44947a28b441cfdf85cb802",
51+
"href": "https://rest.messagebird.com/1/contacts/a621095fa44947a28b441cfdf85cb802",
52+
"msisdn": 316123456789,
53+
"firstName": "Jen",
54+
"lastName": "Smith",
55+
"customDetails": {
56+
"custom1": null,
57+
"custom2": null,
58+
"custom3": null,
59+
"custom4": null
60+
},
61+
"createdDatetime": "2018-06-03T20:06:03Z",
62+
"updatedDatetime": null
63+
},
64+
"channels": [
65+
{
66+
"id": "853eeb5348e541a595da93b48c61a1ae",
67+
"name": "SMS",
68+
"platformId": "sms",
69+
"status": "active",
70+
"createdDatetime": "2018-08-28T11:56:57Z",
71+
"updatedDatetime": "2018-08-29T08:16:33Z"
72+
},
73+
{
74+
"id": "619747f69cf940a98fb443140ce9aed2",
75+
"name": "My WhatsApp",
76+
"platformId": "whatsapp",
77+
"status": "active",
78+
"createdDatetime": "2018-08-28T11:56:57Z",
79+
"updatedDatetime": "2018-08-29T08:16:33Z"
80+
}
81+
],
82+
"status": "active",
83+
"createdDatetime": "2018-08-13T09:17:22Z",
84+
"updatedDatetime": "2018-08-29T07:35:48Z",
85+
"lastReceivedDatetime": "2018-08-29T07:35:48Z",
86+
"lastUsedChannelId": "853eeb5348e541a595da93b48c61a1ae",
87+
"lastUsedPlatformId": "sms",
88+
"messages": {
89+
"totalCount": 23,
90+
"href": "https://conversations.messagebird.com/v1/conversations/2e15efafec384e1c82e9842075e87beb/messages"
91+
}
92+
}
93+
]
94+
}

0 commit comments

Comments
 (0)