Skip to content

Commit 86fa27a

Browse files
committed
Fix tests for API compatibility
1 parent 50d7e62 commit 86fa27a

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

tests/ConvertKitAPITest.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,10 @@ public function testGetGrowthStatsWithStartDate()
765765
$this->assertArrayHasKey('ending', $stats);
766766

767767
// Assert start and end dates were honored.
768-
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00-05:00');
769-
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59-05:00');
768+
// Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
769+
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P');
770+
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
771+
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
770772
}
771773

772774
/**
@@ -802,8 +804,10 @@ public function testGetGrowthStatsWithEndDate()
802804
$this->assertArrayHasKey('ending', $stats);
803805

804806
// Assert start and end dates were honored.
805-
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00-05:00');
806-
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59-05:00');
807+
// Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
808+
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P');
809+
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
810+
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
807811
}
808812

809813
/**
@@ -1186,7 +1190,7 @@ public function testGetFormSubscriptionsWithBouncedSubscriberState()
11861190
*/
11871191
public function testGetFormSubscriptionsWithAddedAfterParam()
11881192
{
1189-
$date = new \DateTime('2024-01-01');
1193+
$date = new \DateTime('2022-01-01');
11901194
$result = $this->api->get_form_subscriptions(
11911195
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
11921196
added_after: $date
@@ -1242,7 +1246,7 @@ public function testGetFormSubscriptionsWithAddedBeforeParam()
12421246
*/
12431247
public function testGetFormSubscriptionsWithCreatedAfterParam()
12441248
{
1245-
$date = new \DateTime('2024-01-01');
1249+
$date = new \DateTime('2022-01-01');
12461250
$result = $this->api->get_form_subscriptions(
12471251
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
12481252
created_after: $date
@@ -1702,7 +1706,7 @@ public function testGetSequenceSubscriptionsWithBouncedSubscriberState()
17021706
*/
17031707
public function testGetSequenceSubscriptionsWithAddedAfterParam()
17041708
{
1705-
$date = new \DateTime('2024-01-01');
1709+
$date = new \DateTime('2022-01-01');
17061710
$result = $this->api->get_sequence_subscriptions(
17071711
sequence_id: (int) $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
17081712
added_after: $date
@@ -1758,7 +1762,7 @@ public function testGetSequenceSubscriptionsWithAddedBeforeParam()
17581762
*/
17591763
public function testGetSequenceSubscriptionsWithCreatedAfterParam()
17601764
{
1761-
$date = new \DateTime('2024-01-01');
1765+
$date = new \DateTime('2022-01-01');
17621766
$result = $this->api->get_sequence_subscriptions(
17631767
sequence_id: (int) $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
17641768
created_after: $date
@@ -1846,7 +1850,7 @@ public function testGetSequenceSubscriptionsPagination()
18461850

18471851
// Assert has_previous_page and has_next_page are correct.
18481852
$this->assertTrue($result->pagination->has_previous_page);
1849-
$this->assertTrue($result->pagination->has_next_page);
1853+
$this->assertFalse($result->pagination->has_next_page);
18501854

18511855
// Use pagination to fetch previous page.
18521856
$result = $this->api->get_sequence_subscriptions(
@@ -2058,7 +2062,7 @@ public function testCreateTagBlank()
20582062
}
20592063

20602064
/**
2061-
* Test that create_tag() throws a ClientException when creating
2065+
* Test that create_tag() returns the expected data when creating
20622066
* a tag that already exists.
20632067
*
20642068
* @since 1.0.0
@@ -2067,8 +2071,14 @@ public function testCreateTagBlank()
20672071
*/
20682072
public function testCreateTagThatExists()
20692073
{
2070-
$this->expectException(ClientException::class);
20712074
$result = $this->api->create_tag($_ENV['CONVERTKIT_API_TAG_NAME']);
2075+
2076+
// Assert response contains correct data.
2077+
$tag = get_object_vars($result->tag);
2078+
$this->assertArrayHasKey('id', $tag);
2079+
$this->assertArrayHasKey('name', $tag);
2080+
$this->assertArrayHasKey('created_at', $tag);
2081+
$this->assertEquals($tag['name'], $_ENV['CONVERTKIT_API_TAG_NAME']);
20722082
}
20732083

20742084
/**
@@ -2141,13 +2151,17 @@ public function testCreateTagsBlank()
21412151
*/
21422152
public function testCreateTagsThatExist()
21432153
{
2144-
$result = $this->api->create_tags([
2145-
$_ENV['CONVERTKIT_API_TAG_NAME'],
2146-
$_ENV['CONVERTKIT_API_TAG_NAME_2'],
2147-
]);
2154+
$result = $this->api->create_tags(
2155+
[
2156+
$_ENV['CONVERTKIT_API_TAG_NAME'],
2157+
$_ENV['CONVERTKIT_API_TAG_NAME_2'],
2158+
]
2159+
);
21482160

2149-
// Assert failures.
2150-
$this->assertCount(2, $result->failures);
2161+
// Assert existing tags are returned.
2162+
$this->assertCount(2, $result->tags);
2163+
$this->assertEquals($result->tags[1]->name, $_ENV['CONVERTKIT_API_TAG_NAME']);
2164+
$this->assertEquals($result->tags[0]->name, $_ENV['CONVERTKIT_API_TAG_NAME_2']);
21512165
}
21522166

21532167
/**
@@ -2530,7 +2544,7 @@ public function testGetTagSubscriptionsWithBouncedSubscriberState()
25302544
*/
25312545
public function testGetTagSubscriptionsWithTaggedAfterParam()
25322546
{
2533-
$date = new \DateTime('2024-01-01');
2547+
$date = new \DateTime('2022-01-01');
25342548
$result = $this->api->get_tag_subscriptions(
25352549
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
25362550
tagged_after: $date
@@ -2586,7 +2600,7 @@ public function testGetTagSubscriptionsWithTaggedBeforeParam()
25862600
*/
25872601
public function testGetTagSubscriptionsWithCreatedAfterParam()
25882602
{
2589-
$date = new \DateTime('2024-01-01');
2603+
$date = new \DateTime('2022-01-01');
25902604
$result = $this->api->get_tag_subscriptions(
25912605
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
25922606
created_after: $date
@@ -3396,7 +3410,7 @@ public function testGetSubscribersWithBouncedSubscriberState()
33963410
*/
33973411
public function testGetSubscribersWithCreatedAfterParam()
33983412
{
3399-
$date = new \DateTime('2024-01-01');
3413+
$date = new \DateTime('2022-01-01');
34003414
$result = $this->api->get_subscribers(
34013415
created_after: $date
34023416
);
@@ -3448,7 +3462,7 @@ public function testGetSubscribersWithCreatedBeforeParam()
34483462
*/
34493463
public function testGetSubscribersWithUpdatedAfterParam()
34503464
{
3451-
$date = new \DateTime('2024-01-01');
3465+
$date = new \DateTime('2022-01-01');
34523466
$result = $this->api->get_subscribers(
34533467
updated_after: $date
34543468
);

0 commit comments

Comments
 (0)