generated from worksome/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23ae996
commit feb1758
Showing
2 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\GraphQLHelpers\Tests; | ||
|
||
use GraphQL\Type\Definition\Description; | ||
use GraphQL\Type\Definition\EnumValueDefinition; | ||
use Illuminate\Support\Collection; | ||
use Worksome\GraphQLHelpers\Definition\PhpEnumType; | ||
|
||
/** @codingStandardsIgnoreStart */ | ||
#[Description('Dummy enum description')] | ||
enum DummyEnum: string | ||
{ | ||
|
||
#[Description('PascalCase description')] | ||
case PascalCase = 'pascal-case'; | ||
#[Description('SCREAMING_SNAKE_CASE description')] | ||
case SCREAMING_SNAKE_CASE = 'screaming-snake-case'; | ||
#[Description('snake_case description')] | ||
case snake_case = 'snake-case'; | ||
} | ||
|
||
/** @codingStandardsIgnoreEnd */ | ||
|
||
it( | ||
'generates correct GQL name from enum cases', | ||
function () { | ||
$type = new PhpEnumType(DummyEnum::class); | ||
expect($type->name)->toBe("DummyEnum"); | ||
|
||
$name = Collection::make($type->getValues()) | ||
->map(fn(EnumValueDefinition $definition) => $definition->name) | ||
->all(); | ||
expect($name)->toBe( | ||
[ | ||
'PASCAL_CASE', | ||
'SCREAMING_SNAKE_CASE', | ||
'SNAKE_CASE', | ||
], | ||
); | ||
}, | ||
); | ||
|
||
it( | ||
'generates correct GQL value from enum cases', | ||
function () { | ||
$type = new PhpEnumType(DummyEnum::class); | ||
|
||
$values = Collection::make($type->getValues()) | ||
->map(fn(EnumValueDefinition $definition) => $definition->value) | ||
->all(); | ||
|
||
expect($values)->toBe( | ||
[ | ||
DummyEnum::PascalCase->value, | ||
DummyEnum::SCREAMING_SNAKE_CASE->value, | ||
DummyEnum::snake_case->value, | ||
], | ||
); | ||
}, | ||
); | ||
|
||
it( | ||
'extracts description from php attribute', | ||
function () { | ||
$type = new PhpEnumType(DummyEnum::class); | ||
|
||
$descriptions = Collection::make($type->getValues())->map( | ||
fn(EnumValueDefinition $definition) => $definition->description, | ||
)->all(); | ||
|
||
expect($type->description)->toBe('Dummy enum description') | ||
->and($descriptions)->toBe( | ||
[ | ||
'PascalCase description', | ||
'SCREAMING_SNAKE_CASE description', | ||
'snake_case description', | ||
], | ||
); | ||
}, | ||
); |