@@ -3791,7 +3791,102 @@ public function testDestroyBroadcastWithInvalidBroadcastID()
3791
3791
}
3792
3792
3793
3793
/**
3794
- * Test that create_webhook() and destroy_webhook() works.
3794
+ * Test that get_webhooks() returns the expected data.
3795
+ *
3796
+ * @since 2.0.0
3797
+ *
3798
+ * @return void
3799
+ */
3800
+ public function testGetWebhooks ()
3801
+ {
3802
+ $ result = $ this ->api ->get_webhooks ();
3803
+
3804
+ // Assert webhooks and pagination exist.
3805
+ $ this ->assertDataExists ($ result , 'webhooks ' );
3806
+ $ this ->assertPaginationExists ($ result );
3807
+ }
3808
+
3809
+ /**
3810
+ * Test that get_webhooks() returns the expected data
3811
+ * when the total count is included.
3812
+ *
3813
+ * @since 2.0.0
3814
+ *
3815
+ * @return void
3816
+ */
3817
+ public function testGetWebhooksWithTotalCount ()
3818
+ {
3819
+ $ result = $ this ->api ->get_webhooks (
3820
+ include_total_count: true
3821
+ );
3822
+
3823
+ // Assert webhooks and pagination exist.
3824
+ $ this ->assertDataExists ($ result , 'webhooks ' );
3825
+ $ this ->assertPaginationExists ($ result );
3826
+
3827
+ // Assert total count is included.
3828
+ $ this ->assertArrayHasKey ('total_count ' , get_object_vars ($ result ->pagination ));
3829
+ $ this ->assertGreaterThan (0 , $ result ->pagination ->total_count );
3830
+ }
3831
+
3832
+ /**
3833
+ * Test that get_webhooks() returns the expected data
3834
+ * when pagination parameters and per_page limits are specified.
3835
+ *
3836
+ * @since 2.0.0
3837
+ *
3838
+ * @return void
3839
+ */
3840
+ public function testGetWebhooksPagination ()
3841
+ {
3842
+ $ result = $ this ->api ->get_webhooks (
3843
+ per_page: 1
3844
+ );
3845
+
3846
+ // Assert webhooks and pagination exist.
3847
+ $ this ->assertDataExists ($ result , 'webhooks ' );
3848
+ $ this ->assertPaginationExists ($ result );
3849
+
3850
+ // Assert a single webhook was returned.
3851
+ $ this ->assertCount (1 , $ result ->webhooks );
3852
+
3853
+ // Assert has_previous_page and has_next_page are correct.
3854
+ $ this ->assertFalse ($ result ->pagination ->has_previous_page );
3855
+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
3856
+
3857
+ // Use pagination to fetch next page.
3858
+ $ result = $ this ->api ->get_webhooks (
3859
+ per_page: 1 ,
3860
+ after_cursor: $ result ->pagination ->end_cursor
3861
+ );
3862
+
3863
+ // Assert webhooks and pagination exist.
3864
+ $ this ->assertDataExists ($ result , 'webhooks ' );
3865
+ $ this ->assertPaginationExists ($ result );
3866
+
3867
+ // Assert a single webhook was returned.
3868
+ $ this ->assertCount (1 , $ result ->webhooks );
3869
+
3870
+ // Assert has_previous_page and has_next_page are correct.
3871
+ $ this ->assertTrue ($ result ->pagination ->has_previous_page );
3872
+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
3873
+
3874
+ // Use pagination to fetch previous page.
3875
+ $ result = $ this ->api ->get_webhooks (
3876
+ per_page: 1 ,
3877
+ before_cursor: $ result ->pagination ->start_cursor
3878
+ );
3879
+
3880
+ // Assert webhooks and pagination exist.
3881
+ $ this ->assertDataExists ($ result , 'webhooks ' );
3882
+ $ this ->assertPaginationExists ($ result );
3883
+
3884
+ // Assert a single webhook was returned.
3885
+ $ this ->assertCount (1 , $ result ->webhooks );
3886
+ }
3887
+
3888
+ /**
3889
+ * Test that create_webhook() and delete_webhook() works.
3795
3890
*
3796
3891
* We do both, so we don't end up with unnecessary webhooks remaining
3797
3892
* on the ConvertKit account when running tests.
@@ -3800,24 +3895,22 @@ public function testDestroyBroadcastWithInvalidBroadcastID()
3800
3895
*
3801
3896
* @return void
3802
3897
*/
3803
- public function testCreateAndDestroyWebhook ()
3898
+ public function testCreateAndDeleteWebhook ()
3804
3899
{
3805
- $ this ->markTestIncomplete ();
3806
-
3807
3900
// Create a webhook first.
3808
3901
$ result = $ this ->api ->create_webhook (
3809
3902
url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
3810
3903
event: 'subscriber.subscriber_activate ' ,
3811
3904
);
3812
3905
$ ruleID = $ result ->rule ->id ;
3813
3906
3814
- // Destroy the webhook.
3815
- $ result = $ this ->api ->destroy_webhook ($ ruleID );
3907
+ // Delete the webhook.
3908
+ $ result = $ this ->api ->delete_webhook ($ ruleID );
3816
3909
$ this ->assertEquals ($ result ->success , true );
3817
3910
}
3818
3911
3819
3912
/**
3820
- * Test that create_webhook() and destroy_webhook () works with an event parameter.
3913
+ * Test that create_webhook() and delete_webhook () works with an event parameter.
3821
3914
*
3822
3915
* We do both, so we don't end up with unnecessary webhooks remaining
3823
3916
* on the ConvertKit account when running tests.
@@ -3826,10 +3919,8 @@ public function testCreateAndDestroyWebhook()
3826
3919
*
3827
3920
* @return void
3828
3921
*/
3829
- public function testCreateAndDestroyWebhookWithEventParameter ()
3922
+ public function testCreateAndDeleteWebhookWithEventParameter ()
3830
3923
{
3831
- $ this ->markTestIncomplete ();
3832
-
3833
3924
// Create a webhook first.
3834
3925
$ result = $ this ->api ->create_webhook (
3835
3926
url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
@@ -3838,8 +3929,8 @@ public function testCreateAndDestroyWebhookWithEventParameter()
3838
3929
);
3839
3930
$ ruleID = $ result ->rule ->id ;
3840
3931
3841
- // Destroy the webhook.
3842
- $ result = $ this ->api ->destroy_webhook ($ ruleID );
3932
+ // Delete the webhook.
3933
+ $ result = $ this ->api ->delete_webhook ($ ruleID );
3843
3934
$ this ->assertEquals ($ result ->success , true );
3844
3935
}
3845
3936
@@ -3853,8 +3944,6 @@ public function testCreateAndDestroyWebhookWithEventParameter()
3853
3944
*/
3854
3945
public function testCreateWebhookWithInvalidEvent ()
3855
3946
{
3856
- $ this ->markTestIncomplete ();
3857
-
3858
3947
$ this ->expectException (InvalidArgumentException::class);
3859
3948
$ this ->api ->create_webhook (
3860
3949
url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
@@ -3863,19 +3952,17 @@ public function testCreateWebhookWithInvalidEvent()
3863
3952
}
3864
3953
3865
3954
/**
3866
- * Test that destroy_webhook () throws a ClientException when an invalid
3955
+ * Test that delete_webhook () throws a ClientException when an invalid
3867
3956
* rule ID is specified.
3868
3957
*
3869
3958
* @since 1.0.0
3870
3959
*
3871
3960
* @return void
3872
3961
*/
3873
- public function testDestroyWebhookWithInvalidRuleID ()
3962
+ public function testsDeleteWebhookWithInvalidRuleID ()
3874
3963
{
3875
- $ this ->markTestIncomplete ();
3876
-
3877
3964
$ this ->expectException (ClientException::class);
3878
- $ this ->api ->destroy_webhook (12345 );
3965
+ $ this ->api ->delete_webhook (12345 );
3879
3966
}
3880
3967
3881
3968
/**
0 commit comments