diff --git a/.gitignore b/.gitignore index 8194f8c..b9a0b00 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ docs/ /.phive/ /tools/ /.php-cs-fixer.cache +.vscode/ \ No newline at end of file diff --git a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php index ba20ac1..6557f69 100644 --- a/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php @@ -169,7 +169,7 @@ protected function configureRequest(Request $request, $data): Request $this->_uploadFile['field'] => $this->_uploadFile['path'], ]); $data = null; - } elseif ($this->getCurrentAction() === self::MODEL_ACTION_RETRIEVE) { + } elseif (in_array($this->getCurrentAction(), [self::MODEL_ACTION_RETRIEVE, self::BEAN_ACTION_UPSERT])) { $data = $this->configureFieldsDataProps($data); } diff --git a/tests/Endpoint/IntegrateTest.php b/tests/Endpoint/IntegrateTest.php index 9ef5bc0..245b34e 100644 --- a/tests/Endpoint/IntegrateTest.php +++ b/tests/Endpoint/IntegrateTest.php @@ -99,6 +99,26 @@ public function testUpsert(): void $this->assertEquals('test', $endpoint->foobar_c); $this->assertEquals('Prospect', $endpoint['account_type']); } + public function testUpsertWithSetField(): void + { + $this->client->mockResponses->append(new Response('201'), new Response('201')); + $endpoint = new Integrate(); + $endpoint->setClient($this->client); + $endpoint->setModule('Accounts'); + $endpoint['name'] = 'Test Account'; + $endpoint['sync_key'] = 'test'; + $endpoint->upsert(); + $request = $this->client->mockResponses->getLastRequest(); + $body = json_decode($request->getBody()->getContents(), true); + $this->assertArrayNotHasKey('fields', $body); + + $endpoint->setFields(['foobar', 'bar']); + $endpoint->upsert(); + $request = $this->client->mockResponses->getLastRequest(); + $body = json_decode($request->getBody()->getContents(), true); + $this->assertArrayHasKey('fields', $body); + $this->assertEquals("foobar,bar", $body['fields']); + } /** * @covers ::getSyncKey