Skip to content

Commit 17b3ece

Browse files
committed
Merge pull request #27 from intercom/add_conversation_tests
Add Conversation tests
2 parents 20d886a + c17af06 commit 17b3ece

File tree

7 files changed

+265
-2
lines changed

7 files changed

+265
-2
lines changed

src/intercom/Service/config/intercom_v3_conversation.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
}
7373
}
7474
},
75-
"responseClass": "Conversation",
75+
"responseClass": "MessageModel",
7676
"responseType": "model",
7777
"summary": "Creates a new conversation",
7878
"uri": "/messages"
@@ -86,7 +86,7 @@
8686
"type": "string"
8787
}
8888
},
89-
"responseClass": "ConversationPartList",
89+
"responseClass": "ConversationModel",
9090
"responseType": "model",
9191
"summary": "Gets a conversation by ID",
9292
"uri": "/conversations/{id}"
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
class ConversationTest extends IntercomTestCase
6+
{
7+
public function testGetMessage()
8+
{
9+
$this->setMockResponse($this->client, 'Conversation/Message.txt');
10+
$response = $this->client->createMessage([
11+
'message_type' => 'email',
12+
'subject' => 'Hey',
13+
'body' => 'An important message',
14+
'from'=> [
15+
'type'=> 'admin',
16+
'id' => '25'
17+
],
18+
'to' => [
19+
'type' => 'user',
20+
'id' => '536e564f316c83104c000020'
21+
]
22+
]);
23+
24+
$this->assertBasicAuth('my-app', '1234');
25+
$this->assertRequest('POST', '/messages');
26+
27+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
28+
$this->assertEquals('[email protected]', $response['owner']['email']);
29+
$this->assertEquals('An important message', $response['body']);
30+
}
31+
32+
public function testGetConversation()
33+
{
34+
$this->setMockResponse($this->client, 'Conversation/Conversation.txt');
35+
$response = $this->client->getConversation(['id' => '123456']);
36+
37+
$this->assertRequest('GET', '/conversations/123456');
38+
39+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
40+
$this->assertEquals('25', $response['conversation_message']['author']['id']);
41+
$this->assertEquals(true, $response['open']);
42+
}
43+
44+
public function testGetConversations()
45+
{
46+
$this->setMockResponse($this->client, 'Conversation/ConversationList.txt');
47+
$response = $this->client->getConversations();
48+
$conversations = $response->get('conversations');
49+
50+
$this->assertRequest('GET', '/conversations?type=user');
51+
52+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
53+
$this->assertEquals(1, count($conversations));
54+
$this->assertEquals(1400850973, $conversations['0']['created_at']);
55+
$this->assertEquals('536e564f316c83104c000020', $conversations['0']['user']['id']);
56+
$this->assertEquals('admin', $conversations['0']['assignee']['type']);
57+
}
58+
59+
public function testReplyToConversation()
60+
{
61+
$this->setMockResponse($this->client, 'Conversation/Conversation.txt');
62+
$this->client->replyToConversation(['id' => '123456']);
63+
64+
$this->assertRequest('POST', '/conversations/123456/reply?type=json');
65+
}
66+
67+
public function testMarkConversationAsRead()
68+
{
69+
$this->setMockResponse($this->client, 'Conversation/Conversation.txt');
70+
$this->client->markConversationAsRead(['id' => '123456', 'read' => true]);
71+
72+
$this->assertRequest('PUT', '/conversations/123456');
73+
}
74+
75+
/**
76+
* @expectedException \Guzzle\Service\Exception\ValidationException
77+
*/
78+
public function testGetConversationNoID()
79+
{
80+
$this->client->getConversation();
81+
}
82+
83+
/**
84+
* @expectedException \Guzzle\Service\Exception\ValidationException
85+
*/
86+
public function testReplyConversationNoID()
87+
{
88+
$this->client->replyToConversation();
89+
}
90+
91+
/**
92+
* @expectedException \Guzzle\Service\Exception\ValidationException
93+
*/
94+
public function testMarkConversationAsReadNoID()
95+
{
96+
$this->client->markConversationAsRead();
97+
}
98+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type": "conversation",
9+
"id": "147",
10+
"created_at": 1400850973,
11+
"updated_at": 1400857494,
12+
"conversation_message": {
13+
"type": "conversation_message",
14+
"subject": "",
15+
"body": "<p>Hi Alice,</p>\n\n<p> We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
16+
"author": {
17+
"type": "admin",
18+
"id": "25"
19+
},
20+
"attachments": [
21+
{
22+
"name": "signature",
23+
"url": "http://example.org/signature.jpg"
24+
}
25+
]
26+
},
27+
"user": {
28+
"type": "user",
29+
"id": "536e564f316c83104c000020"
30+
},
31+
"assignee": {
32+
"type": "admin",
33+
"id": "25"
34+
},
35+
"open": true,
36+
"read": true,
37+
"conversation_parts": {
38+
"type": "conversation_part.list",
39+
"conversation_parts": [
40+
]
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type": "conversation.list",
9+
"conversations": [
10+
{
11+
"type": "conversation",
12+
"id": "147",
13+
"created_at": 1400850973,
14+
"updated_at": 1400857494,
15+
"user": {
16+
"type": "user",
17+
"id": "536e564f316c83104c000020"
18+
},
19+
"assignee": {
20+
"type": "admin",
21+
"id": "25"
22+
},
23+
"conversation_message": {
24+
"type": "conversation_message",
25+
"subject": "",
26+
"body": "<p>Hi Alice,</p>\n\n<p>We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
27+
"author": {
28+
"type": "admin",
29+
"id": "25"
30+
},
31+
"attachments": [
32+
{
33+
"name": "signature",
34+
"url": "http://someurl.com/signature.jpg"
35+
}
36+
]
37+
}
38+
}
39+
]
40+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type": "conversation_part",
9+
"id": "4412",
10+
"part_type": "comment",
11+
"body": "<p>Hi Jane, it's all great thanks!</p>",
12+
"created_at": 1400857494,
13+
"updated_at": 1400857494,
14+
"notified_at": 1400857587,
15+
"assigned_to": null,
16+
"author": {
17+
"type": "user",
18+
"id": "536e564f316c83104c000020"
19+
},
20+
"attachments": []
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type": "conversation_part.list",
9+
"conversation_parts": [
10+
{
11+
"type": "conversation_part",
12+
"id": "4412",
13+
"part_type": "comment",
14+
"body": "<p>Hi Jane, it's all great thanks!</p>",
15+
"created_at": 1400857494,
16+
"updated_at": 1400857494,
17+
"notified_at": 1400857587,
18+
"assigned_to": null,
19+
"author": {
20+
"type": "user",
21+
"id": "536e564f316c83104c000020"
22+
},
23+
"attachments": []
24+
},
25+
{
26+
"type": "conversation_part",
27+
"id": "4413",
28+
"part_type": "comment",
29+
"body": "<p>Thank you!</p>",
30+
"created_at": 1400857494,
31+
"updated_at": 1400857494,
32+
"notified_at": 1400857587,
33+
"assigned_to": null,
34+
"author": {
35+
"type": "user",
36+
"id": "536e564f316c83104c000020"
37+
},
38+
"attachments": []
39+
}
40+
]
41+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: max-age=0, private, must-revalidate
3+
Content-Type: application/json; charset=utf-8
4+
Date: Mon, 25 Aug 2014 23:57:54 GMT
5+
Server: nginx
6+
7+
{
8+
"type": "admin_message",
9+
"id": "2001",
10+
"created_at": 1401916877,
11+
"message_type": "email",
12+
"subject" : "Hey",
13+
"body" : "An important message",
14+
"template": "plain",
15+
"owner": {
16+
"email": "[email protected]",
17+
"id": "25",
18+
"name": "Wash",
19+
"type": "admin"
20+
}
21+
}

0 commit comments

Comments
 (0)