Add additional events to TotalResponseItem (#739)

This commit is contained in:
Aaron Rubin 2021-01-30 01:40:40 -05:00 committed by GitHub
parent 66fd858a02
commit a39d0b0651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 0 deletions

View File

@ -21,6 +21,10 @@ final class TotalResponseItem
private $delivered;
private $failed;
private $complained;
private $opened;
private $clicked;
private $unsubscribed;
private $stored;
public static function create(array $data): self
{
@ -30,6 +34,10 @@ final class TotalResponseItem
$model->delivered = $data['delivered'] ?? [];
$model->failed = $data['failed'] ?? [];
$model->complained = $data['complained'] ?? [];
$model->opened = $data['opened'] ?? [];
$model->clicked = $data['clicked'] ?? [];
$model->unsubscribed = $data['unsubscribed'] ?? [];
$model->stored = $data['stored'] ?? [];
return $model;
}
@ -62,4 +70,24 @@ final class TotalResponseItem
{
return $this->complained;
}
public function getOpened(): array
{
return $this->opened;
}
public function getClicked(): array
{
return $this->clicked;
}
public function getUnsubscribed(): array
{
return $this->unsubscribed;
}
public function getStored(): array
{
return $this->stored;
}
}

View File

@ -43,6 +43,22 @@ class StatsTest extends TestCase
$this->assertInstanceOf(TotalResponse::class, $total);
$this->assertCount(count($responseData['stats']), $total->getStats());
$this->assertContainsOnlyInstancesOf(TotalResponseItem::class, $total->getStats());
$event = $queryParameters['event'];
$responseStat = $total->getStats()[0];
$statGetter = 'get'.ucwords($event);
if ('failed' !== $event) {
$expectedTotal = $responseData['stats'][0][$event]['total'];
$actualTotal = $responseStat->$statGetter()['total'];
}
if ('failed' === $event) {
$expectedTotal = $responseData['stats'][0][$event]['permanent']['total'];
$actualTotal = $responseStat->$statGetter()['permanent']['total'];
}
$this->assertEquals($expectedTotal, $actualTotal);
}
public function testTotalInvalidArgument()
@ -109,6 +125,58 @@ class StatsTest extends TestCase
],
]),
],
'clicked events' => [
'queryParameters' => [
'event' => 'clicked',
],
'responseData' => $this->generateTotalResponsePayload([
[
'time' => $this->formatDate('-7 days'),
'clicked' => [
'total' => 7,
],
],
]),
],
'opened events' => [
'queryParameters' => [
'event' => 'opened',
],
'responseData' => $this->generateTotalResponsePayload([
[
'time' => $this->formatDate('-7 days'),
'opened' => [
'total' => 19,
],
],
]),
],
'unsubscribed events' => [
'queryParameters' => [
'event' => 'unsubscribed',
],
'responseData' => $this->generateTotalResponsePayload([
[
'time' => $this->formatDate('-7 days'),
'unsubscribed' => [
'total' => 10,
],
],
]),
],
'stored events' => [
'queryParameters' => [
'event' => 'stored',
],
'responseData' => $this->generateTotalResponsePayload([
[
'time' => $this->formatDate('-7 days'),
'stored' => [
'total' => 12,
],
],
]),
],
];
}