Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 API: Tests: Segments #47

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions tests/wpunit/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3216,6 +3216,95 @@ public function testPurchaseCreate()
$this->assertEquals($result['transaction_id'], '99999');
}

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

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

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

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

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

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

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

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

// 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_segments(false, $result['pagination']['end_cursor'], '', 1);

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

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

// 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_segments(false, '', $result['pagination']['start_cursor'], 1);

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

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

// 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 the `recommendations_script()` function returns expected data
* for a ConvertKit account that has the Creator Network enabled.
Expand Down
Loading