Skip to content

Commit 20377de

Browse files
authored
Merge pull request #8 from tevfik6/CXAPPS-329
CXAPPS-329: Fix Handling of Fields in Request for Upsert API
2 parents 2df2241 + 712e033 commit 20377de

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ docs/
1010
/.phive/
1111
/tools/
1212
/.php-cs-fixer.cache
13+
.vscode/

src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function configureRequest(Request $request, $data): Request
169169
$this->_uploadFile['field'] => $this->_uploadFile['path'],
170170
]);
171171
$data = null;
172-
} elseif ($this->getCurrentAction() === self::MODEL_ACTION_RETRIEVE) {
172+
} elseif (in_array($this->getCurrentAction(), [self::MODEL_ACTION_RETRIEVE, self::BEAN_ACTION_UPSERT])) {
173173
$data = $this->configureFieldsDataProps($data);
174174
}
175175

tests/Endpoint/IntegrateTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ public function testUpsert(): void
9999
$this->assertEquals('test', $endpoint->foobar_c);
100100
$this->assertEquals('Prospect', $endpoint['account_type']);
101101
}
102+
public function testUpsertWithSetField(): void
103+
{
104+
$this->client->mockResponses->append(new Response('201'), new Response('201'));
105+
$endpoint = new Integrate();
106+
$endpoint->setClient($this->client);
107+
$endpoint->setModule('Accounts');
108+
$endpoint['name'] = 'Test Account';
109+
$endpoint['sync_key'] = 'test';
110+
$endpoint->upsert();
111+
$request = $this->client->mockResponses->getLastRequest();
112+
$body = json_decode($request->getBody()->getContents(), true);
113+
$this->assertArrayNotHasKey('fields', $body);
114+
115+
$endpoint->setFields(['foobar', 'bar']);
116+
$endpoint->upsert();
117+
$request = $this->client->mockResponses->getLastRequest();
118+
$body = json_decode($request->getBody()->getContents(), true);
119+
$this->assertArrayHasKey('fields', $body);
120+
$this->assertEquals("foobar,bar", $body['fields']);
121+
}
102122

103123
/**
104124
* @covers ::getSyncKey

0 commit comments

Comments
 (0)