From 275691e0f088faffa23cac9f25f99d628e3d535f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tevfik=20T=C3=BCmer?= Date: Mon, 3 Mar 2025 15:45:08 +0100 Subject: [PATCH 1/4] Add .vscode/ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From a489ecb034f2473fc7b033d6a28494d10f008f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tevfik=20T=C3=BCmer?= Date: Mon, 3 Mar 2025 15:44:20 +0100 Subject: [PATCH 2/4] Enhance action handling to support both retrieve and upsert in AbstractSugarBeanEndpoint --- src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From a58d635e950641d05e7babc2f2eac8a1d41dd6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tevfik=20T=C3=BCmer?= Date: Mon, 3 Mar 2025 17:58:30 +0100 Subject: [PATCH 3/4] Add test for upsert with set fields in IntegrateTest --- tests/Endpoint/IntegrateTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Endpoint/IntegrateTest.php b/tests/Endpoint/IntegrateTest.php index 9ef5bc0..e22dcef 100644 --- a/tests/Endpoint/IntegrateTest.php +++ b/tests/Endpoint/IntegrateTest.php @@ -99,6 +99,29 @@ 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')); + $endpoint = new Integrate(); + $endpoint->setClient($this->client); + $endpoint->setModule('Accounts'); + $endpoint['name'] = 'Test Account'; + $endpoint['sync_key'] = 'test'; + $Reflection = new \ReflectionClass($endpoint::class); + $configurePayload = $Reflection->getMethod('configurePayload'); + $configurePayload->setAccessible(true); + $payload = $configurePayload->invoke($endpoint)->toArray(); + $this->assertArrayNotHasKey('fields', $payload); + + $this->client->mockResponses->append(new Response('201')); + $endpoint->setFields(['foobar_c', 'account_type']); + $endpoint->upsert(); + + $payload = $configurePayload->invoke($endpoint)->toArray(); + $this->assertArrayHasKey('fields', $payload); + $fields = $payload['fields']; + $this->assertEquals("foobar_c,account_type", $fields); + } /** * @covers ::getSyncKey From 712e033223ff7fdbb3947e643867aee9a8fe497d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tevfik=20T=C3=BCmer?= Date: Mon, 3 Mar 2025 18:42:06 +0100 Subject: [PATCH 4/4] Refactor upsert test to validate field handling in IntegrateTest --- tests/Endpoint/IntegrateTest.php | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/Endpoint/IntegrateTest.php b/tests/Endpoint/IntegrateTest.php index e22dcef..245b34e 100644 --- a/tests/Endpoint/IntegrateTest.php +++ b/tests/Endpoint/IntegrateTest.php @@ -101,26 +101,23 @@ public function testUpsert(): void } public function testUpsertWithSetField(): void { - $this->client->mockResponses->append(new Response('201')); + $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'; - $Reflection = new \ReflectionClass($endpoint::class); - $configurePayload = $Reflection->getMethod('configurePayload'); - $configurePayload->setAccessible(true); - $payload = $configurePayload->invoke($endpoint)->toArray(); - $this->assertArrayNotHasKey('fields', $payload); - - $this->client->mockResponses->append(new Response('201')); - $endpoint->setFields(['foobar_c', 'account_type']); $endpoint->upsert(); + $request = $this->client->mockResponses->getLastRequest(); + $body = json_decode($request->getBody()->getContents(), true); + $this->assertArrayNotHasKey('fields', $body); - $payload = $configurePayload->invoke($endpoint)->toArray(); - $this->assertArrayHasKey('fields', $payload); - $fields = $payload['fields']; - $this->assertEquals("foobar_c,account_type", $fields); + $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']); } /**