From 70b6afdedc0cf56234b8b6dfcece5ffcb49a0a76 Mon Sep 17 00:00:00 2001 From: John Linhart Date: Mon, 16 Jan 2023 17:25:38 +0100 Subject: [PATCH] Fixing failing tests due to new duplicity checks in Mautic --- tests/Api/CompaniesTest.php | 11 ++++++++++- tests/Api/ContactsTest.php | 12 ++++++++++++ tests/Api/MauticApiTestCase.php | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/Api/CompaniesTest.php b/tests/Api/CompaniesTest.php index 1f189b00..7763b265 100644 --- a/tests/Api/CompaniesTest.php +++ b/tests/Api/CompaniesTest.php @@ -84,6 +84,15 @@ public function testAddAndRemove() public function testBatchEndpoints() { - $this->standardTestBatchEndpoints(); + $batch = []; + + // Company name must be unique + for ($i = 0; $i < 3; ++$i) { + $company = $this->testPayload; + $company['companyname'] = 'test'.$i; + $batch[] = $company; + } + + $this->standardTestBatchEndpoints($batch); } } diff --git a/tests/Api/ContactsTest.php b/tests/Api/ContactsTest.php index 7179bb83..4cc1aabc 100644 --- a/tests/Api/ContactsTest.php +++ b/tests/Api/ContactsTest.php @@ -11,6 +11,7 @@ namespace Mautic\Tests\Api; use Mautic\Api\Contacts; +use Mautic\QueryBuilder\QueryBuilder; class ContactsTest extends AbstractCustomFieldsTest { @@ -365,6 +366,17 @@ public function testEditPatchFormError() public function testEditPut() { + $qb = new QueryBuilder(); + $qb->addWhere($qb->getWhereBuilder()->eq('email', $this->testPayload['email'])); + $response = $this->api->getCustomList($qb, 0, 1); + $this->assertErrors($response); + + // Making sure that if the contact exists, it won't try to create it. Otherwise we'll get an error about duplicated email. + if (isset($response[$this->api->listName()]) && count($response[$this->api->listName()])) { + $response = $this->api->delete(array_pop($response[$this->api->listName()])['id']); + $this->assertErrors($response); + } + $this->standardTestEditPut(); } diff --git a/tests/Api/MauticApiTestCase.php b/tests/Api/MauticApiTestCase.php index b15c4f51..4b330fb3 100644 --- a/tests/Api/MauticApiTestCase.php +++ b/tests/Api/MauticApiTestCase.php @@ -320,7 +320,7 @@ public function standardTestEditPut() $response = $this->api->edit(10000, $this->testPayload, true); $this->assertPayload($response); - //now delete the category + //now delete the entity $response = $this->api->delete($response[$this->api->itemName()]['id']); $this->assertErrors($response); }