-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSearchTest.php
More file actions
72 lines (59 loc) · 2.42 KB
/
SearchTest.php
File metadata and controls
72 lines (59 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
test('Can search all records for SalesforcePhp', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/create_test_account'),
MockResponse::fixture('search/search_all'),
]);
$api = getAPI($mockClient);
$api->createRecord('Account', [
'Name' => 'SalesforcePhp Test',
'Website' => 'https://salesforcephp.test',
]);
sleep(3);
$results = $api->search('SalesforcePhp');
expect($results['searchRecords'])->not()->toBeEmpty();
});
test('Can search just accounts for SalesforcePhp', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/search_in_account'),
]);
$api = getAPI($mockClient);
$results = $api->searchIn('SalesforcePhp', 'Account');
expect($results['searchRecords'])->not()->toBeEmpty();
});
test('Can search just accounts and supply additional fields to select', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/search_in_account_fields'),
]);
$api = getAPI($mockClient);
$results = $api->searchIn('SalesforcePhp', 'Account', ['Name']);
expect($results['searchRecords'])->not()->toBeEmpty();
expect($results['searchRecords'][0])->toHaveKey('Name');
});
test('Can search using helper function searchObjectWhereProperties', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/query_where_properties'),
]);
$api = getAPI($mockClient);
$results = $api->searchObjectWhereProperties('Account', ['name' => 'SalesforcePhp Test'], ['Id', 'Name']);
expect($results)->not()->toBeEmpty();
expect($results[0])->toHaveKey('Name', 'SalesforcePhp Test');
});
test('Can find a single record and return properties directly', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/find_record'),
]);
$api = getAPI($mockClient);
$result = $api->findRecord('Account', ['name' => 'SalesforcePhp Test'], ['Id', 'Name']);
expect($result)->toHaveKey('Name', 'SalesforcePhp Test');
});
test('Returns null if it fails to find a record', function () {
$mockClient = new MockClient([
MockResponse::fixture('search/find_record_empty'),
]);
$api = getAPI($mockClient);
$result = $api->findRecord('Account', ['name' => 'Not A Real Record'], ['Id', 'Name']);
expect($result)->toBeNull();
});