Skip to content

Commit b95f352

Browse files
committed
Merge pull request #26 from intercom/add_company_tests
Add Company tests
2 parents 17b3ece + a0a3178 commit b95f352

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
class CompanyTest extends IntercomTestCase
6+
{
7+
public function testGetCompanyByID()
8+
{
9+
$this->setMockResponse($this->client, 'Company/Company.txt');
10+
$response = $this->client->getCompany(['id' => '123456']);
11+
12+
$this->assertBasicAuth('my-app', '1234');
13+
$this->assertRequest('GET', '/companies/123456');
14+
15+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
16+
$this->assertEquals('Blue Sun', $response['name']);
17+
}
18+
19+
public function testGetCompanyByName()
20+
{
21+
$this->setMockResponse($this->client, 'Company/Company.txt');
22+
$this->client->getCompany(['name' => 'Blue Sun']);
23+
24+
$this->assertRequest('GET', '/companies/?name=Blue%20Sun');
25+
}
26+
27+
public function testGetCompanyByCompanyID()
28+
{
29+
$this->setMockResponse($this->client, 'Company/Company.txt');
30+
$this->client->getCompany(['company_id' => 'hgsdfhsasdfg']);
31+
32+
$this->assertRequest('GET', '/companies/?company_id=hgsdfhsasdfg');
33+
}
34+
35+
public function testCreateCompany()
36+
{
37+
$this->setMockResponse($this->client, 'Company/Company.txt');
38+
$response = $this->client->createCompany(['name' => 'Blue Sun', 'company_id' => '1234']);
39+
40+
$this->assertRequest('POST', '/companies');
41+
$this->assertRequestJson(['company_id' => '1234', 'name' => 'Blue Sun']);
42+
43+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
44+
$this->assertEquals('Blue Sun', $response['name']);
45+
}
46+
47+
public function testUpdateCompany()
48+
{
49+
$this->setMockResponse($this->client, 'Company/Company.txt');
50+
$response = $this->client->updateCompany(['id' => '123456', 'company_id' => '1234', 'hi' => 'hello']);
51+
52+
$this->assertRequest('POST', '/companies');
53+
$this->assertRequestJson(['company_id' => '1234']);
54+
55+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
56+
$this->assertEquals('Blue Sun', $response['name']);
57+
}
58+
59+
public function testGetCompanies()
60+
{
61+
$this->setMockResponse($this->client, 'Company/CompanyList.txt');
62+
$response = $this->client->getCompanies();
63+
$companies = $response->get('companies');
64+
65+
$this->assertRequest('GET', '/companies');
66+
67+
$this->assertInstanceOf('\Guzzle\Service\Resource\Model', $response);
68+
$this->assertEquals(2, count($companies));
69+
$this->assertEquals('Blue Sun', $companies['0']['name']);
70+
$this->assertEquals('Blue Moon', $companies['1']['name']);
71+
}
72+
73+
public function testGetCompaniesByTagID()
74+
{
75+
$this->setMockResponse($this->client, 'Company/CompanyList.txt');
76+
$this->client->getCompanies(['tag_id' => '10', 'hello'=>'hi']);
77+
78+
$this->assertRequest('GET', '/companies?tag_id=10');
79+
}
80+
81+
public function testGetCompaniesBySegmentID()
82+
{
83+
$this->setMockResponse($this->client, 'Company/CompanyList.txt');
84+
$this->client->getCompanies(['segment_id' => '20', 'hello'=>'hi']);
85+
86+
$this->assertRequest('GET', '/companies?segment_id=20');
87+
}
88+
89+
public function testGetCompanyUsers()
90+
{
91+
$this->setMockResponse($this->client, 'User/UserList.txt');
92+
$this->client->getCompanyUsers(['id' => '1234']);
93+
94+
$this->assertRequest('GET', '/companies/1234/users');
95+
}
96+
97+
public function testGetCompanyUsersByCompanyID()
98+
{
99+
$this->setMockResponse($this->client, 'User/UserList.txt');
100+
$this->client->getCompanyUsersByCompanyID(['company_id' => '10', 'type' => 'user']);
101+
102+
$this->assertRequest('GET', '/companies?company_id=10&type=user');
103+
}
104+
105+
public function testGetCompanyUsersByCompanyIDNoType()
106+
{
107+
$this->setMockResponse($this->client, 'User/UserList.txt');
108+
$this->client->getCompanyUsersByCompanyID(['company_id' => '10']);
109+
110+
$this->assertRequest('GET', '/companies?company_id=10&type=user');
111+
}
112+
113+
/**
114+
* @expectedException \Guzzle\Service\Exception\ValidationException
115+
*/
116+
public function testCreateCompanyNoCompanyID()
117+
{
118+
$this->client->createCompany();
119+
}
120+
121+
/**
122+
* @expectedException \Guzzle\Service\Exception\ValidationException
123+
*/
124+
public function testUpdateCompanyNoCompanyID()
125+
{
126+
$this->client->updateCompany();
127+
}
128+
}

tests/Mock/Company/Company.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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": "company",
9+
"id": "531ee472cce572a6ec000006",
10+
"name": "Blue Sun",
11+
"plan": {
12+
"type":"plan",
13+
"id":"1",
14+
"name":"Paid"
15+
},
16+
"company_id": "6",
17+
"remote_created_at": 1394531169,
18+
"created_at": 1394533506,
19+
"updated_at": 1396874658,
20+
"last_request_at": 1396874658,
21+
"monthly_spend": 49,
22+
"session_count": 26,
23+
"user_count": 10,
24+
"custom_attributes": {
25+
"paid_subscriber" : true,
26+
"team_mates": 0
27+
}
28+
}

tests/Mock/Company/CompanyList.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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": "company.list",
9+
"total_count": 2,
10+
"companies": [
11+
{
12+
"type": "company",
13+
"id": "531ee472cce572a6ec000006",
14+
"name": "Blue Sun",
15+
"plan": {
16+
"type":"plan",
17+
"id":"1",
18+
"name":"Paid"
19+
},
20+
"company_id": "6",
21+
"remote_created_at": 1394531169,
22+
"created_at": 1394533506,
23+
"updated_at": 1396874658,
24+
"last_request_at": 1396874658,
25+
"monthly_spend": 49,
26+
"session_count": 26,
27+
"user_count": 10,
28+
"custom_attributes": {
29+
"paid_subscriber" : true,
30+
"team_mates": 0
31+
}
32+
},
33+
{
34+
"type": "company",
35+
"id": "654ee472cce572a6ec000006",
36+
"name": "Blue Moon",
37+
"plan": {
38+
"type":"plan",
39+
"id":"1",
40+
"name":"Paid"
41+
},
42+
"company_id": "7",
43+
"remote_created_at": 1394531180,
44+
"created_at": 1394533506,
45+
"updated_at": 1396874658,
46+
"last_request_at": 1396874658,
47+
"monthly_spend": 49,
48+
"session_count": 26,
49+
"user_count": 10,
50+
"custom_attributes": {
51+
"paid_subscriber" : true,
52+
"team_mates": 0
53+
}
54+
}
55+
],
56+
"pages": {
57+
"page": 1,
58+
"per_page": 50,
59+
"total_pages": 1
60+
}
61+
}

0 commit comments

Comments
 (0)