Skip to content

Commit 01814a1

Browse files
committed
Added more API Key override tests
1 parent b8b25b0 commit 01814a1

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<testsuites>
44
<testsuite name="ConvertKit API Tests">
55
<directory>tests</directory>
6+
<exclude>tests/ConvertKitAPITest.php</exclude>
67
</testsuite>
78
</testsuites>
89
</phpunit>

tests/ConvertKitAPIKeyTest.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,5 +560,204 @@ public function testCreateCustomFields()
560560
];
561561
$result = $this->api->create_custom_fields($labels);
562562
}
563+
564+
/**
565+
* Test that get_purchases() throws a ClientException
566+
* as this is only supported using OAuth.
567+
*
568+
* @since 2.2.0
569+
*
570+
* @return void
571+
*/
572+
public function testGetPurchases()
573+
{
574+
$this->expectException(ClientException::class);
575+
$result = $this->api->get_purchases();
576+
}
577+
578+
/**
579+
* Test that get_purchases() throws a ClientException
580+
* when the total count is included, as this is only
581+
* supported using OAuth.
582+
*
583+
* @since 2.2.0
584+
*
585+
* @return void
586+
*/
587+
public function testGetPurchasesWithTotalCount()
588+
{
589+
$this->expectException(ClientException::class);
590+
$result = $this->api->get_purchases(
591+
include_total_count: true
592+
);
593+
}
594+
595+
/**
596+
* Test that get_purchases() throws a ClientException
597+
* when pagination parameters and per_page limits are specified,
598+
* as this is only supported using OAuth.
599+
*
600+
* @since 2.2.0
601+
*
602+
* @return void
603+
*/
604+
public function testGetPurchasesPagination()
605+
{
606+
$this->expectException(ClientException::class);
607+
$result = $this->api->get_purchases(
608+
per_page: 1
609+
);
610+
}
611+
612+
/**
613+
* Test that get_purchases() throws a ClientException
614+
* when a purchase ID is specified, as this is only
615+
* supported using OAuth.
616+
*
617+
* @since 2.2.0
618+
*
619+
* @return void
620+
*/
621+
public function testGetPurchase()
622+
{
623+
$this->expectException(ClientException::class);
624+
$result = $this->api->get_purchase(12345);
625+
}
626+
627+
/**
628+
* Test that get_purchases() throws a ClientException when an invalid
629+
* purchase ID is specified, as this is only supported
630+
* using OAuth.
631+
*
632+
* @since 2.2.0
633+
*
634+
* @return void
635+
*/
636+
public function testGetPurchaseWithInvalidID()
637+
{
638+
$this->expectException(ClientException::class);
639+
$this->api->get_purchase(12345);
640+
}
641+
642+
/**
643+
* Test that create_purchase() throws a ClientException
644+
* as this is only supported using OAuth.
645+
*
646+
* @since 2.2.0
647+
*
648+
* @return void
649+
*/
650+
public function testCreatePurchase()
651+
{
652+
$this->expectException(ClientException::class);
653+
$purchase = $this->api->create_purchase(
654+
// Required fields.
655+
email_address: $this->generateEmailAddress(),
656+
transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'),
657+
currency: 'usd',
658+
products: [
659+
[
660+
'name' => 'Floppy Disk (512k)',
661+
'sku' => '7890-ijkl',
662+
'pid' => 9999,
663+
'lid' => 7777,
664+
'quantity' => 2,
665+
'unit_price' => 5.00,
666+
],
667+
[
668+
'name' => 'Telephone Cord (data)',
669+
'sku' => 'mnop-1234',
670+
'pid' => 5555,
671+
'lid' => 7778,
672+
'quantity' => 1,
673+
'unit_price' => 10.00,
674+
],
675+
],
676+
// Optional fields.
677+
first_name: 'Tim',
678+
status: 'paid',
679+
subtotal: 20.00,
680+
tax: 2.00,
681+
shipping: 2.00,
682+
discount: 3.00,
683+
total: 21.00,
684+
transaction_time: new DateTime('now'),
685+
);
686+
}
687+
688+
/**
689+
* Test that create_purchase() throws a ClientException when an invalid
690+
* email address is specified, as this is only supported using OAuth.
691+
*
692+
* @since 2.2.0
693+
*
694+
* @return void
695+
*/
696+
public function testCreatePurchaseWithInvalidEmailAddress()
697+
{
698+
$this->expectException(ClientException::class);
699+
$this->api->create_purchase(
700+
email_address: 'not-an-email-address',
701+
transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'),
702+
currency: 'usd',
703+
products: [
704+
[
705+
'name' => 'Floppy Disk (512k)',
706+
'sku' => '7890-ijkl',
707+
'pid' => 9999,
708+
'lid' => 7777,
709+
'quantity' => 2,
710+
'unit_price' => 5.00,
711+
],
712+
],
713+
);
714+
}
715+
716+
/**
717+
* Test that create_purchase() throws a ClientException when a blank
718+
* transaction ID is specified, as this is only supported using OAuth.
719+
*
720+
* @since 2.2.0
721+
*
722+
* @return void
723+
*/
724+
public function testCreatePurchaseWithBlankTransactionID()
725+
{
726+
$this->expectException(ClientException::class);
727+
$this->api->create_purchase(
728+
email_address: $this->generateEmailAddress(),
729+
transaction_id: '',
730+
currency: 'usd',
731+
products: [
732+
[
733+
'name' => 'Floppy Disk (512k)',
734+
'sku' => '7890-ijkl',
735+
'pid' => 9999,
736+
'lid' => 7777,
737+
'quantity' => 2,
738+
'unit_price' => 5.00,
739+
],
740+
],
741+
);
742+
}
743+
744+
/**
745+
* Test that create_purchase() throws a ClientException when no products
746+
* are specified, as this is only supported using OAuth.
747+
*
748+
* @since 2.2.0
749+
*
750+
* @return void
751+
*/
752+
public function testCreatePurchaseWithNoProducts()
753+
{
754+
$this->expectException(ClientException::class);
755+
$this->api->create_purchase(
756+
email_address: $this->generateEmailAddress(),
757+
transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'),
758+
currency: 'usd',
759+
products: [],
760+
);
761+
}
563762

564763
}

0 commit comments

Comments
 (0)