Skip to content

Commit

Permalink
Improve test segments
Browse files Browse the repository at this point in the history
  • Loading branch information
dompie committed Jun 25, 2024
1 parent 47e8650 commit 97ee201
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions tests/ApiClientV1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ApiClientV1Test extends KeilaTestCase

private static string $baseUri = '';
private static string $apiKey;
private array $segmentFilter1 = [];
private array $segmentFilter2 = [];

public function setUp(): void
{
Expand All @@ -47,6 +49,18 @@ public function setUp(): void
$this->client = new ApiClientV1($httpClient, self::$baseUri, self::$apiKey);
$this->email1 = 'first.example@' . $this->testTld1;
$this->email2 = 'first.test@' . $this->testTld2;

$this->segmentFilter1 = ['$or' =>
[['$and' => [[
'email' => $this->email1
]]]]
];

$this->segmentFilter2 = ['$or' =>
[['$and' => [[
'email' => $this->email2
]]]]
];
}

public function testContactCreate(): string
Expand Down Expand Up @@ -300,7 +314,7 @@ public function testCampaignScheduleFor(): void
{
$this->deleteContacts();
$this->client->contactCreate($this->email1, 'First', 'Last');
$segment = $this->response2Object($this->client->segmentCreate('Campaign-Schedule-Test .' . date('His'), ['email' => $this->email1]));
$segment = $this->response2Object($this->client->segmentCreate('Campaign-Schedule-Test .' . date('His'), $this->segmentFilter1));

$name = 'Send campaign test ' . date('dmY-His');
$senderIndexResponse = KeilaResponse::new($this->client->senderIndex());
Expand Down Expand Up @@ -331,7 +345,7 @@ public function testBlockCampaignSave(): void
{
$this->deleteContacts();
$this->client->contactCreate($this->email1, 'First', 'Last');
$segment = $this->response2Object($this->client->segmentCreate('Campaign-Send-Test ' . date('His'), ['email' => $this->email1]));
$segment = $this->response2Object($this->client->segmentCreate('Campaign-Send-Test ' . date('His'), $this->segmentFilter1));

$name = 'Send campaign test ' . date('dmY-His');
$senderIndexResponse = KeilaResponse::new($this->client->senderIndex());
Expand All @@ -351,15 +365,15 @@ public function testCampaignSend(): void
{
$this->deleteContacts();
$this->client->contactCreate($this->email1, 'First', 'Last');
$segment = $this->response2Object($this->client->segmentCreate('Campaign-Send-Test ' . date('His'), ['email' => $this->email1]));
$name = 'Send campaign test ' . date('dmY-His');
$senderIndexResponse = KeilaResponse::new($this->client->senderIndex());
$segment = $this->response2Object($this->client->segmentCreate('Segment-Send-Test ' . date('His'), $this->segmentFilter1));
$name = 'Campaign send test ' . date('His');
$senderId = KeilaResponse::new($this->client->senderIndex())->getDataItem(0)['id'];
$c = (new Campaign())
->withName($name)
->withSenderId($senderIndexResponse->getDataItem(0)['id'])
->withSenderId($senderId)
->withSegmentId($segment->data->id)

->withTextEditor('Hello world!');

$response = $this->response2Object($this->client->campaignCreate($c));
self::assertNull($response->data->sent_at);

Expand Down

0 comments on commit 97ee201

Please sign in to comment.