Skip to content

Commit

Permalink
Merge pull request #46 from ConvertKit/v4-api-tests-email-templates
Browse files Browse the repository at this point in the history
v4 API: Tests: Email Templates
  • Loading branch information
n7studios authored Apr 22, 2024
2 parents 15b1ffc + 4a7a9ba commit ae93617
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tests/wpunit/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,96 @@ public function testGetSubscriberTagsPagination()
$this->assertCount(1, $result['tags']);
}

/**
* Test that get_email_templates() returns the expected data.
*
* @since 2.0.0
*
* @return void
*/
public function testGetEmailTemplates()
{
$result = $this->api->get_email_templates();

// Assert email templates and pagination exist.
$this->assertDataExists($result, 'email_templates');
$this->assertPaginationExists($result);
}

/**
* Test that get_email_templates() returns the expected data
* when the total count is included.
*
* @since 1.0.0
*
* @return void
*/
public function testGetEmailTemplatesWithTotalCount()
{
$result = $this->api->get_email_templates(true);

// Assert email templates and pagination exist.
$this->assertDataExists($result, 'email_templates');
$this->assertPaginationExists($result);

// Assert total count is included.
$this->assertArrayHasKey('total_count', $result['pagination']);
$this->assertGreaterThan(0, $result['pagination']['total_count']);
}

/**
* Test that get_email_templates() returns the expected data
* when pagination parameters and per_page limits are specified.
*
* @since 2.0.0
*
* @return void
*/
public function testGetEmailTemplatesPagination()
{
// Return one broadcast.
$result = $this->api->get_email_templates(false, '', '', 1);

// Assert email templates and pagination exist.
$this->assertDataExists($result, 'email_templates');
$this->assertPaginationExists($result);

// Assert a single email template was returned.
$this->assertCount(1, $result['email_templates']);

// Assert has_previous_page and has_next_page are correct.
$this->assertFalse($result['pagination']['has_previous_page']);
$this->assertTrue($result['pagination']['has_next_page']);

// Use pagination to fetch next page.
$result = $this->api->get_email_templates(false, $result['pagination']['end_cursor'], '', 1);

// Assert email templates and pagination exist.
$this->assertDataExists($result, 'email_templates');
$this->assertPaginationExists($result);

// Assert a single email template was returned.
$this->assertCount(1, $result['email_templates']);

// Assert has_previous_page and has_next_page are correct.
$this->assertTrue($result['pagination']['has_previous_page']);
$this->assertTrue($result['pagination']['has_next_page']);

// Use pagination to fetch previous page.
$result = $this->api->get_email_templates(false, '', $result['pagination']['start_cursor'], 1);

// Assert email templates and pagination exist.
$this->assertDataExists($result, 'email_templates');
$this->assertPaginationExists($result);

// Assert a single email template was returned.
$this->assertCount(1, $result['email_templates']);

// Assert has_previous_page and has_next_page are correct.
$this->assertFalse($result['pagination']['has_previous_page']);
$this->assertTrue($result['pagination']['has_next_page']);
}

/**
* Test that get_broadcasts() returns the expected data
* when pagination parameters and per_page limits are specified.
Expand Down

0 comments on commit ae93617

Please sign in to comment.