forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#1060 from mautic-inc/MAUT-4362
MAUT-4362: Scoring - SFDC clearing out new data from ACS
- Loading branch information
1 parent
6ac2e69
commit 55b5ab7
Showing
9 changed files
with
200 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/bundles/IntegrationsBundle/Tests/Functional/Entity/FieldChangeRepositoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mautic\IntegrationsBundle\Tests\Functional\Entity; | ||
|
||
use Mautic\CoreBundle\Test\MauticMysqlTestCase; | ||
use Mautic\IntegrationsBundle\Entity\FieldChange; | ||
use Mautic\IntegrationsBundle\Entity\FieldChangeRepository; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use PHPUnit\Framework\Assert; | ||
|
||
final class FieldChangeRepositoryTest extends MauticMysqlTestCase | ||
{ | ||
const INTEGRATION = 'someIntegration'; | ||
const COLUMN_NAME = 'some_column'; | ||
const OBJECT_ID = 100; | ||
|
||
private FieldChangeRepository $repository; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->repository = $this->em->getRepository(FieldChange::class); | ||
} | ||
|
||
public function testThatFindChangesBeforeMethodReturnsChangesInCorrectOrder(): void | ||
{ | ||
$fieldChanges = $this->generateFieldChanges(3); | ||
$fieldChanges[0]->setObjectId(3); | ||
$fieldChanges[1]->setObjectId(1); | ||
$fieldChanges[2]->setObjectId(2); | ||
|
||
foreach ($fieldChanges as $fieldChange) { | ||
$this->em->persist($fieldChange); | ||
} | ||
|
||
$this->em->flush(); | ||
|
||
$changes = $this->repository->findChangesBefore( | ||
static::INTEGRATION, | ||
Lead::class, | ||
$this->getNow()->modify('+30 seconds'), | ||
null, | ||
2 | ||
); | ||
|
||
Assert::assertSame(1, (int) $changes[0]['object_id']); | ||
Assert::assertSame(2, (int) $changes[1]['object_id']); | ||
} | ||
|
||
public function testThatItDoesntDeleteObjectsThatCameDuringInternalSynchronization(): void | ||
{ | ||
$now = $this->getNow(); | ||
$fieldChanges = $this->generateFieldChanges(2); | ||
$aDayLater = (clone $now)->modify('+1 day'); // Don't use \DateTimeImmutable because entity expects \DateTime | ||
$fieldChanges[1]->setModifiedAt($aDayLater); | ||
|
||
foreach ($fieldChanges as $fieldChange) { | ||
$this->em->persist($fieldChange); | ||
} | ||
|
||
$this->em->flush(); | ||
|
||
$this->repository->deleteEntitiesForObject( | ||
static::OBJECT_ID, | ||
Lead::class, | ||
static::INTEGRATION, | ||
$now->modify('+30 seconds') | ||
); | ||
|
||
$remainingChanges = $this->repository->findAll(); | ||
Assert::assertCount(1, $remainingChanges); | ||
Assert::assertSame($fieldChanges[1]->getId(), $remainingChanges[0]->getId()); | ||
} | ||
|
||
/** | ||
* @return FieldChange[] | ||
*/ | ||
private function generateFieldChanges(int $quantity): array | ||
{ | ||
$fieldChanges = []; | ||
$now = $this->getNow(); | ||
for ($i = 1; $i <= $quantity; ++$i) { | ||
$fieldChange = new FieldChange(); | ||
$fieldChange->setIntegration(static::INTEGRATION); | ||
$fieldChange->setObjectId(static::OBJECT_ID); | ||
$fieldChange->setObjectType(Lead::class); | ||
$fieldChange->setModifiedAt($now); | ||
$fieldChange->setColumnName(static::COLUMN_NAME); | ||
$fieldChange->setColumnType('string'); | ||
$fieldChange->setColumnValue((string) $i); | ||
|
||
$fieldChanges[] = $fieldChange; | ||
} | ||
|
||
return $fieldChanges; | ||
} | ||
|
||
private function getNow(): \DateTime | ||
{ | ||
return new \DateTime('now', new \DateTimeZone('UTC')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters