about summary refs log tree commit diff stats
path: root/tests_integration
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-16 07:06:59 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-16 07:06:59 +0300
commite1128c3161b7d535a237bb6db48032dd4959a71c (patch)
tree7128ddca316222fc8b55f359a70e5f4794f159d2 /tests_integration
parent53d6a4c6d03aad45e9b382ad0370fb5b23af9e8f (diff)
downloadthe-epube-e1128c3161b7d535a237bb6db48032dd4959a71c.tar.gz
the-epube-e1128c3161b7d535a237bb6db48032dd4959a71c.tar.xz
missing tests for ids=
Diffstat (limited to 'tests_integration')
-rw-r--r--tests_integration/ListTest.php146
1 files changed, 146 insertions, 0 deletions
diff --git a/tests_integration/ListTest.php b/tests_integration/ListTest.php
index 267a4b2..0dde8b8 100644
--- a/tests_integration/ListTest.php
+++ b/tests_integration/ListTest.php
@@ -233,4 +233,150 @@ final class ListTest extends TestCase
 		$this->assertEquals(0, $body['total']);
 		$this->assertCount(0, $body['books']);
 	}
+
+	// ── Selecting books by ids ──────────────────────────────────────────────
+
+	/**
+	 * Fetch book IDs from a full list so we can reference real IDs in subsequent tests.
+	 */
+	private function getAllBookIds(): array
+	{
+		$this->loginAs('test', 'test');
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'    => 'list',
+			'limit' => 100,
+		]);
+
+		$this->assertEquals(200, $status);
+		return array_map(fn($b) => (int) $b['id'], $body['books']);
+	}
+
+	public function test_list_by_ids_single(): void
+	{
+		$ids = $this->getAllBookIds();
+		$this->assertGreaterThan(0, count($ids), 'Test data should contain at least one book');
+
+		$singleId = $ids[0];
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => (string) $singleId,
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertEquals(1, $body['total']);
+		$this->assertCount(1, $body['books']);
+		$this->assertEquals($singleId, (int) $body['books'][0]['id']);
+	}
+
+	public function test_list_by_ids_multiple(): void
+	{
+		$ids = $this->getAllBookIds();
+		$this->assertGreaterThanOrEqual(3, count($ids), 'Test data should contain at least 3 books');
+
+		$selectedIds = [$ids[0], $ids[1], $ids[2]];
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => implode(',', $selectedIds),
+		]);
+
+		$this->assertEquals(200, $status);
+		$expectedTotal = count($selectedIds);
+		$this->assertEquals($expectedTotal, $body['total']);
+		$this->assertCount($expectedTotal, $body['books']);
+
+		$foundIds = array_map(fn($b) => (int) $b['id'], $body['books']);
+		sort($foundIds);
+		$sortedSelected = $selectedIds;
+		sort($sortedSelected);
+		$this->assertEquals($sortedSelected, $foundIds);
+	}
+
+	public function test_list_by_ids_nonexistent(): void
+	{
+		$this->loginAs('test', 'test');
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => '999999',
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertEquals(0, $body['total']);
+		$this->assertCount(0, $body['books']);
+	}
+
+	public function test_list_by_ids_mixed_existing_and_nonexistent(): void
+	{
+		$ids = $this->getAllBookIds();
+		$this->assertGreaterThan(0, count($ids));
+
+		$selectedIds = [$ids[0], 999999, $ids[1]];
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => implode(',', $selectedIds),
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertEquals(2, $body['total']);
+		$this->assertCount(2, $body['books']);
+
+		$foundIds = array_map(fn($b) => (int) $b['id'], $body['books']);
+		$this->assertContains((int) $ids[0], $foundIds);
+		$this->assertContains((int) $ids[1], $foundIds);
+	}
+
+	public function test_list_by_ids_overrides_query(): void
+	{
+		$ids = $this->getAllBookIds();
+		$this->assertGreaterThan(0, count($ids));
+
+		// Use a query that would match many books, but restrict to a single id
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'    => 'list',
+			'ids'   => (string) $ids[0],
+			'query' => 'the',
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertEquals(1, $body['total']);
+		$this->assertCount(1, $body['books']);
+		$foundIds = array_map(fn($b) => (int) $b['id'], $body['books']);
+		$this->assertContains((int) $ids[0], $foundIds);
+	}
+
+	public function test_list_by_ids_empty_string_returns_all(): void
+	{
+		$this->loginAs('test', 'test');
+
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => '',
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertGreaterThan(0, $body['total']);
+		$this->assertIsArray($body['books']);
+	}
+
+	public function test_list_by_ids_with_invalid_values(): void
+	{
+		$ids = $this->getAllBookIds();
+		$this->assertGreaterThan(0, count($ids));
+
+		// Mix of valid and invalid (non-numeric) values; intval should filter them out
+		[$status, $body] = $this->authenticatedPost($this->apiUrl, [
+			'op'  => 'list',
+			'ids' => (string) $ids[0] . ',abc,0,',
+		]);
+
+		$this->assertEquals(200, $status);
+		$this->assertEquals(1, $body['total']);
+		$this->assertCount(1, $body['books']);
+		$foundIds = array_map(fn($b) => (int) $b['id'], $body['books']);
+		$this->assertContains((int) $ids[0], $foundIds);
+	}
 }