|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bakery\Tests\Types; |
| 4 | + |
| 5 | +use Bakery\Tests\TestCase; |
| 6 | +use Bakery\Types\CollectionSearchType; |
| 7 | +use Bakery\Tests\Stubs\Schemas\ArticleSchema; |
| 8 | +use Bakery\Tests\Fixtures\IntegrationTestSchema; |
| 9 | + |
| 10 | +class CollectionSearchTypeTest extends TestCase |
| 11 | +{ |
| 12 | + /** @test */ |
| 13 | + public function it_generates_search_fields_for_string_scalar_fields() |
| 14 | + { |
| 15 | + $schema = new IntegrationTestSchema(); |
| 16 | + $schema->toGraphQLSchema(); |
| 17 | + $type = new CollectionSearchType($schema->getRegistry(), new ArticleSchema($schema->getRegistry())); |
| 18 | + |
| 19 | + $actual = $type->resolveFields(); |
| 20 | + $this->assertArrayHasKey('title', $actual); |
| 21 | + $this->assertArrayHasKey('content', $actual); |
| 22 | + |
| 23 | + $this->assertArrayNotHasKey('slug', $actual); |
| 24 | + $this->assertArrayNotHasKey('created_at', $actual); |
| 25 | + } |
| 26 | + |
| 27 | + /** @test */ |
| 28 | + public function it_generates_search_fields_for_relation_fields() |
| 29 | + { |
| 30 | + $schema = new IntegrationTestSchema(); |
| 31 | + $schema->toGraphQLSchema(); |
| 32 | + $type = new CollectionSearchType($schema->getRegistry(), new ArticleSchema($schema->getRegistry())); |
| 33 | + |
| 34 | + $actual = $type->resolveFields(); |
| 35 | + $this->assertArrayHasKey('user', $actual); |
| 36 | + |
| 37 | + $this->assertArrayNotHasKey('tags', $actual); |
| 38 | + $this->assertArrayNotHasKey('category', $actual); |
| 39 | + $this->assertArrayNotHasKey('comments', $actual); |
| 40 | + $this->assertArrayNotHasKey('upvotes', $actual); |
| 41 | + } |
| 42 | +} |
0 commit comments