Skip to content

Commit

Permalink
Merge pull request #90 from ConvertKit/v4-api-mock-create-tag-tests
Browse files Browse the repository at this point in the history
v4 API: Mock Create Tag Tests
  • Loading branch information
n7studios authored Apr 1, 2024
2 parents b82e8de + 1ffa58e commit 7e8b632
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,24 @@ public function testGetTagsPagination()
public function testCreateTag()
{
$tagName = 'Tag Test ' . mt_rand();

// Add mock handler for this API request, as the API doesn't provide
// a method to delete tags to cleanup the test.
$this->api = $this->mockResponse(
api: $this->api,
responseBody: [
'tag' => [
'id' => 12345,
'name' => $tagName,
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
]
);

// Send request.
$result = $this->api->create_tag($tagName);

// Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
// Assert response contains correct data.
$tag = get_object_vars($result->tag);
$this->assertArrayHasKey('id', $tag);
$this->assertArrayHasKey('name', $tag);
Expand Down Expand Up @@ -1678,6 +1693,28 @@ public function testCreateTags()
'Tag Test ' . mt_rand(),
'Tag Test ' . mt_rand(),
];

// Add mock handler for this API request, as the API doesn't provide
// a method to delete tags to cleanup the test.
$this->api = $this->mockResponse(
api: $this->api,
responseBody: [
'tags' => [
[
'id' => 12345,
'name' => $tagNames[0],
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
[
'id' => 23456,
'name' => $tagNames[1],
'created_at' => date('Y-m-d') . 'T' . date('H:i:s') . 'Z',
],
],
'failures' => [],
]
);

$result = $this->api->create_tags($tagNames);

// Assert no failures.
Expand Down

0 comments on commit 7e8b632

Please sign in to comment.