Skip to content

Commit 7b5bc1b

Browse files
authored
Merge pull request #22 from LibreCodeCoop/test/lc116-query-contract-coverage
test: expand lc116 services controller contracts
2 parents 51243a3 + 8015622 commit 7b5bc1b

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/Unit/Http/Controllers/SettingsControllerTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,5 +519,67 @@ protected function storeCertificate(string $cnpj, string $pfxContent, string $pa
519519
self::assertSame(1, ControllerIsolationState::$savedCount);
520520
self::assertSame('44444444000144', ControllerIsolationState::$settings['nfse.cnpj_prestador'] ?? null);
521521
}
522+
523+
public function testLc116ServicesReturnsFilteredCatalogData(): void
524+
{
525+
$controller = new class () extends SettingsController {
526+
protected function jsonResponse(array $payload, int $status = 200): JsonResponse
527+
{
528+
return new JsonResponse($payload, $status);
529+
}
530+
};
531+
532+
$request = new Request([
533+
'q' => 'contabilidade',
534+
'limit' => 10,
535+
]);
536+
537+
$response = $controller->lc116Services($request, new \Modules\Nfse\Support\Lc116Catalog());
538+
539+
self::assertSame(200, $response->getStatusCode());
540+
self::assertCount(1, $response->getData(true)['data']);
541+
self::assertSame('1719', $response->getData(true)['data'][0]['code']);
542+
}
543+
544+
public function testLc116ServicesEnforcesMinimumLimitWhenProvidedLimitIsZero(): void
545+
{
546+
$controller = new class () extends SettingsController {
547+
protected function jsonResponse(array $payload, int $status = 200): JsonResponse
548+
{
549+
return new JsonResponse($payload, $status);
550+
}
551+
};
552+
553+
$request = new Request([
554+
'q' => '',
555+
'limit' => 0,
556+
]);
557+
558+
$response = $controller->lc116Services($request, new \Modules\Nfse\Support\Lc116Catalog());
559+
560+
self::assertSame(200, $response->getStatusCode());
561+
self::assertCount(1, $response->getData(true)['data']);
562+
}
563+
564+
public function testLc116ServicesUsesNullQueryWhenRequestQueryValueIsNotString(): void
565+
{
566+
$controller = new class () extends SettingsController {
567+
protected function jsonResponse(array $payload, int $status = 200): JsonResponse
568+
{
569+
return new JsonResponse($payload, $status);
570+
}
571+
};
572+
573+
$request = new Request([
574+
'q' => ['unexpected'],
575+
'limit' => 2,
576+
]);
577+
578+
$response = $controller->lc116Services($request, new \Modules\Nfse\Support\Lc116Catalog());
579+
580+
self::assertSame(200, $response->getStatusCode());
581+
self::assertCount(2, $response->getData(true)['data']);
582+
self::assertSame('0101', $response->getData(true)['data'][0]['code']);
583+
}
522584
}
523585
}

0 commit comments

Comments
 (0)