Skip to content

Commit

Permalink
Added email template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n7studios committed Apr 19, 2024
1 parent e61fa5c commit 8a88734
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/wpunit/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,95 @@ public function testUnsubscribeWithInvalidEmail()
$this->assertEquals('Not Found: The entity you were trying to find doesn\'t exist', $result->get_error_message());
}

/**
* 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
Expand Down

0 comments on commit 8a88734

Please sign in to comment.