Skip to content

Commit 0ae2e4e

Browse files
committed
Merge pull request #30 from intercom/add_tag_tests
Add Tag tests
2 parents f233deb + b550571 commit 0ae2e4e

File tree

4 files changed

+145
-6
lines changed

4 files changed

+145
-6
lines changed

src/intercom/Service/config/intercom_v3_tag.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@
102102
"required": false,
103103
"type": "string"
104104
},
105-
"email": {
106-
"location": "json",
107-
"required": false,
108-
"type": "string"
109-
},
110-
"user_id": {
105+
"company_id": {
111106
"location": "json",
112107
"required": false,
113108
"type": "string"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
class TagTest extends IntercomTestCase
6+
{
7+
8+
public function testCreateTag()
9+
{
10+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
11+
$response = $this->client->createTag(['does_not_exist' => true ,'name' => 'New']);
12+
13+
$this->assertRequest('POST', '/tags');
14+
$this->assertRequestJson(['name' => 'New']);
15+
16+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
17+
$this->assertEquals('independent', $response['name']);
18+
}
19+
20+
public function testUpdateTag()
21+
{
22+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
23+
$response = $this->client->updateTag(['id' => '123456', 'name' => 'New', 'hi' => 'hello']);
24+
25+
$this->assertRequest('POST', '/tags');
26+
$this->assertRequestJson(['id' => '123456', 'name' => 'New']);
27+
28+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
29+
$this->assertEquals('independent', $response['name']);
30+
}
31+
32+
public function testGetTags()
33+
{
34+
$this->setMockResponse($this->client, 'Tag/TagList.txt');
35+
$response = $this->client->getTags();
36+
$tags = $response->get('tags');
37+
38+
$this->assertRequest('GET', '/tags');
39+
40+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
41+
$this->assertEquals(3, count($tags));
42+
$this->assertEquals('Beta User', $tags['0']['name']);
43+
$this->assertEquals('Amazing User', $tags['1']['name']);
44+
$this->assertEquals('Epic User', $tags['2']['name']);
45+
}
46+
47+
public function testTagUsers()
48+
{
49+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
50+
$this->client->tagUsers(['name' => 'independent', 'users' => [['id' => '12'], ['email' => '[email protected]']]]);
51+
52+
$this->assertRequest('POST', '/tags');
53+
$this->assertRequestJson(['name' => 'independent', 'users' => [['id' => '12'], ['email' => '[email protected]']]]);
54+
}
55+
56+
public function testUntagUsers()
57+
{
58+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
59+
$this->client->tagUsers(['name' => 'independent', 'users' => [['id' => '12', 'untag' => true]]]);
60+
61+
$this->assertRequest('POST', '/tags');
62+
$this->assertRequestJson(['name' => 'independent', 'users' => [['id' => '12', 'untag' => true]]]);
63+
}
64+
65+
public function testTagCompanies()
66+
{
67+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
68+
$this->client->tagCompanies(['name' => 'independent', 'companies' => [['id' => '20']]]);
69+
70+
$this->assertRequest('POST', '/tags');
71+
$this->assertRequestJson(['name' => 'independent', 'companies' => [['id' => '20']]]);
72+
}
73+
74+
public function testUntagCompanies()
75+
{
76+
$this->setMockResponse($this->client, 'Tag/Tag.txt');
77+
$this->client->tagCompanies(['name' => 'independent', 'companies' => [['id' => '20', 'untag' => true]]]);
78+
79+
$this->assertRequest('POST', '/tags');
80+
$this->assertRequestJson(['name' => 'independent', 'companies' => [['id' => '20', 'untag' => true]]]);
81+
}
82+
83+
/**
84+
* @expectedException \Guzzle\Service\Exception\ValidationException
85+
*/
86+
public function testCreateTagNoName()
87+
{
88+
$this->client->createTag();
89+
}
90+
91+
/**
92+
* @expectedException \Guzzle\Service\Exception\ValidationException
93+
*/
94+
public function testUpdateTagNoID()
95+
{
96+
$this->client->updateTag(['name' => 'New']);
97+
}
98+
99+
/**
100+
* @expectedException \Guzzle\Service\Exception\ValidationException
101+
*/
102+
public function testUpdateTagNoName()
103+
{
104+
$this->client->updateTag(['id' => '123456']);
105+
}
106+
}

tests/Mock/Tag/Tag.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
"id": "17513",
9+
"name": "independent",
10+
"type": "tag"
11+
}

tests/Mock/Tag/TagList.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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": "tag.list",
9+
"tags": [
10+
{
11+
"type": "tag",
12+
"name": "Beta User",
13+
"id": 1
14+
},
15+
{
16+
"type": "tag",
17+
"name": "Amazing User",
18+
"id": 2
19+
},
20+
{
21+
"type": "tag",
22+
"name": "Epic User",
23+
"id": 3
24+
}
25+
],
26+
"pages":{}
27+
}

0 commit comments

Comments
 (0)