pdo()->exec('DELETE FROM repo_configs'); $this->controller = new RepoConfigController(new RepoConfigRepository($db)); } public function testIndexReturnsEmptyListInitially(): void { $response = $this->controller->index(Request::create('GET', '/api/v1/repo-configs')); self::assertSame(200, $response->status); self::assertSame([], $response->body()['repos']); } public function testCreateReturns201WithNewRepo(): void { $response = $this->controller->create(Request::create('POST', '/api/v1/repo-configs', body: [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04', ])); self::assertSame(201, $response->status); self::assertSame('fds2610', $response->body()['repo']['owner']); } public function testCreateRejectsInvalidColorWith422(): void { $response = $this->controller->create(Request::create('POST', '/api/v1/repo-configs', body: [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => 'nope', ])); self::assertSame(422, $response->status); } public function testUpdateReturnsUpdatedRepo(): void { $created = $this->controller->create(Request::create('POST', '/api/v1/repo-configs', body: [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04', ]))->body()['repo']; $response = $this->controller->update( Request::create('PATCH', '/api/v1/repo-configs/' . $created['id'], body: [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#000000', ]), ['id' => (string) $created['id']] ); self::assertSame(200, $response->status); self::assertSame('#000000', $response->body()['repo']['color']); } public function testDeleteReturnsDeletedTrue(): void { $created = $this->controller->create(Request::create('POST', '/api/v1/repo-configs', body: [ 'owner' => 'fds2610', 'repo' => 'monitor', 'color' => '#fbca04', ]))->body()['repo']; $response = $this->controller->delete( Request::create('DELETE', '/api/v1/repo-configs/' . $created['id']), ['id' => (string) $created['id']] ); self::assertSame(200, $response->status); self::assertTrue($response->body()['deleted']); } }