Skip to content

Commit 8a799a0

Browse files
committed
added contact resource tests
1 parent 469a9d2 commit 8a799a0

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

tests/Resources/ContactsTest.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
use Dcblogdev\MsGraph\Facades\MsGraph;
4+
use Dcblogdev\MsGraph\Resources\Contacts;
5+
6+
beforeEach(function () {
7+
MsGraph::shouldReceive('isConnected')->andReturn(true);
8+
$this->contacts = new Contacts;
9+
});
10+
11+
test('get contacts with params', function () {
12+
13+
$messageQueryParams = [
14+
'$orderby' => 'displayName',
15+
'$skip' => 0,
16+
'$top' => 5,
17+
'$count' => 'true',
18+
];
19+
20+
MsGraph::shouldReceive('get')
21+
->with('me/contacts?'.http_build_query($messageQueryParams))
22+
->andReturn([
23+
'@odata.count' => 10,
24+
'value' => [
25+
['id' => '1', 'displayName' => 'John Doe'],
26+
['id' => '2', 'displayName' => 'Jane Doe'],
27+
],
28+
]);
29+
30+
$response = (new Contacts)->get($messageQueryParams);
31+
32+
expect($response)->toHaveKeys(['contacts', 'total', 'links', 'links_array'])
33+
->and($response['contacts']['value'])->toBeArray()
34+
->and($response['total'])->toBe(10);
35+
});
36+
37+
test('find method retrieves a specific contact', function () {
38+
39+
MsGraph::shouldReceive('get')
40+
->with('me/contacts/1')
41+
->andReturn([
42+
'id' => '1',
43+
'displayName' => 'John Doe',
44+
'email' => 'johndoe@example.com',
45+
]);
46+
47+
$response = (new Contacts)->find('1');
48+
49+
expect($response)
50+
->toHaveKeys(['id', 'displayName', 'email'])
51+
->and($response['id'])->toBe('1')
52+
->and($response['displayName'])->toBe('John Doe')
53+
->and($response['email'])->toBe('johndoe@example.com');
54+
});
55+
56+
test('can create contact', function () {
57+
58+
$data = [
59+
'displayName' => 'John Doe',
60+
'givenName' => 'John Doe',
61+
'emailAddresses' => [
62+
[
63+
'address' => 'john@doe.com',
64+
'name' => 'John Doe',
65+
],
66+
],
67+
];
68+
69+
MsGraph::shouldReceive('post')
70+
->with('me/contacts', $data)
71+
->andReturn([
72+
'id' => '1',
73+
'displayName' => 'John Doe',
74+
'email' => 'johndoe@example.com',
75+
]);
76+
77+
$response = (new Contacts)->store($data);
78+
79+
expect($response)
80+
->toHaveKeys(['id', 'displayName', 'email'])
81+
->and($response['id'])->toBe('1')
82+
->and($response['displayName'])->toBe('John Doe')
83+
->and($response['email'])->toBe('johndoe@example.com');
84+
});
85+
86+
test('can update contact', function () {
87+
88+
$data = [
89+
'displayName' => 'John Doe',
90+
'givenName' => 'John Doe',
91+
'emailAddresses' => [
92+
[
93+
'address' => 'john@doe.com',
94+
'name' => 'John Doe',
95+
],
96+
],
97+
];
98+
99+
MsGraph::shouldReceive('patch')
100+
->with('me/contacts/1', $data)
101+
->andReturn([
102+
'id' => '1',
103+
'displayName' => 'John Doe',
104+
'email' => 'johndoe@example.com',
105+
]);
106+
107+
$response = (new Contacts)->update(1, $data);
108+
109+
expect($response)
110+
->toHaveKeys(['id', 'displayName', 'email'])
111+
->and($response['id'])->toBe('1')
112+
->and($response['displayName'])->toBe('John Doe')
113+
->and($response['email'])->toBe('johndoe@example.com');
114+
});
115+
116+
test('can delete contact', function () {
117+
118+
MsGraph::shouldReceive('delete')
119+
->with('me/contacts/1')
120+
->andReturn('');
121+
122+
$response = (new Contacts)->delete(1);
123+
124+
expect($response)->toBe('');
125+
});

0 commit comments

Comments
 (0)