Skip to content

Commit 0293b14

Browse files
committed
Merge pull request #29 from intercom/add_note_tests
Add Note tests
2 parents 0ae2e4e + 689709a commit 0293b14

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

src/intercom/Service/config/intercom_v3_note.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Intercom API (Note) v3",
33
"description": "The Intercom API (Note) v3",
44
"operations": {
5-
"getNotes": {
5+
"getNotesForUser": {
66
"extends": "_abstract_pagination_page",
77
"httpMethod": "GET",
88
"parameters": {
@@ -24,14 +24,15 @@
2424
},
2525
"responseClass": "NoteListModel",
2626
"responseType": "model",
27-
"summary": "Get a list of notes",
27+
"summary": "Get a list of notes for given user",
2828
"uri": "/notes"
2929
},
3030
"getNote": {
3131
"httpMethod": "GET",
3232
"parameters": {
3333
"id": {
3434
"location": "uri",
35+
"required": true,
3536
"type": "string"
3637
}
3738
},
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
class NoteTest extends IntercomTestCase
6+
{
7+
public function testGetNote()
8+
{
9+
$this->setMockResponse($this->client, 'Note/Note.txt');
10+
$response = $this->client->getNote(['id' => '123456']);
11+
12+
$this->assertBasicAuth('my-app', '1234');
13+
$this->assertRequest('GET', '/notes/123456');
14+
15+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
16+
$this->assertEquals('Jayne Cobb', $response['author']['name']);
17+
}
18+
19+
public function testGetNotesForUserByID()
20+
{
21+
$this->setMockResponse($this->client, 'Note/NoteList.txt');
22+
$response = $this->client->getNotesForUser(['id' => '1234']);
23+
$notes = $response->get('notes');
24+
25+
$this->assertRequest('GET', '/notes?id=1234');
26+
27+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
28+
$this->assertEquals(2, count($notes));
29+
$this->assertEquals('Jayne Cobb', $notes['0']['author']['name']);
30+
$this->assertEquals('<p>Text for my note</p>', $notes['1']['body']);
31+
}
32+
33+
public function testGetNotesForUserByUserID()
34+
{
35+
$this->setMockResponse($this->client, 'Note/NoteList.txt');
36+
$this->client->getNotesForUser(['user_id' => 'aabb']);
37+
38+
$this->assertRequest('GET', '/notes?user_id=aabb');
39+
}
40+
41+
public function testGetNotesForUserByEmail()
42+
{
43+
$this->setMockResponse($this->client, 'Note/NoteList.txt');
44+
$this->client->getNotesForUser(['email' => '[email protected]']);
45+
46+
$this->assertRequest('GET', '/notes?email=bob%40example.org');
47+
}
48+
49+
public function testCreateNote()
50+
{
51+
$this->setMockResponse($this->client, 'Note/Note.txt');
52+
$this->client->createNote(['admin_id' => '6', 'user' => ['email' => '[email protected]'], 'body' => 'Hi']);
53+
54+
$this->assertRequest('POST', '/notes');
55+
$this->assertRequestJson(['admin_id' => '6', 'user' => ['email' => '[email protected]'], 'body' => 'Hi']);
56+
}
57+
58+
/**
59+
* @expectedException \Guzzle\Service\Exception\ValidationException
60+
*/
61+
public function testGetNoteNoID()
62+
{
63+
$this->client->getNote();
64+
}
65+
66+
/**
67+
* @expectedException \Guzzle\Service\Exception\ValidationException
68+
*/
69+
public function testCreateNoteNoArguments()
70+
{
71+
$this->client->getNote();
72+
}
73+
74+
/**
75+
* @expectedException \Guzzle\Service\Exception\ValidationException
76+
*/
77+
public function testCreateNoteNoAdminID()
78+
{
79+
$this->client->getNote(['user' => ['email' => '[email protected]'], 'body' => 'Hi']);
80+
}
81+
82+
/**
83+
* @expectedException \Guzzle\Service\Exception\ValidationException
84+
*/
85+
public function testCreateNoteNoUser()
86+
{
87+
$this->client->getNote(['admin_id' => '6', 'body' => 'Hi']);
88+
}
89+
90+
/**
91+
* @expectedException \Guzzle\Service\Exception\ValidationException
92+
*/
93+
public function testCreateNoteNoBody()
94+
{
95+
$this->client->getNote(['admin_id' => '6', 'user' => ['email' => '[email protected]']]);
96+
}
97+
}

tests/Mock/Note/Note.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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": "note",
9+
"id": "16",
10+
"created_at": 1389913941,
11+
"body": "<p>Text for my note</p>",
12+
"author": {
13+
"type": "admin",
14+
"id": "21",
15+
"name": "Jayne Cobb",
16+
"email": "[email protected]",
17+
"companies": []
18+
},
19+
"user": {
20+
"type": "user",
21+
"id": "5310d8e8598c9a0b24000005"
22+
}
23+
}

tests/Mock/Note/NoteList.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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": "note.list",
9+
"notes": [
10+
{
11+
"type": "note",
12+
"id": "1",
13+
"created_at": 1389913941,
14+
"body": "<p>Text for my note</p>",
15+
"author": {
16+
"type": "admin",
17+
"id": "21",
18+
"name": "Jayne Cobb",
19+
"email": "[email protected]",
20+
"companies": []
21+
},
22+
"user": {
23+
"type": "user",
24+
"id": "5310d8e8598c9a0b24000005"
25+
}
26+
},
27+
{
28+
"type": "note",
29+
"id": "2",
30+
"created_at": 1389913951,
31+
"body": "<p>Text for my note</p>",
32+
"user": {
33+
"id": "5310d8e8598c9a0b24000005",
34+
"type": "user"
35+
}
36+
}
37+
],
38+
"pages": {}
39+
}

0 commit comments

Comments
 (0)