Skip to content

Commit

Permalink
Merge pull request #34 from daniel-de-wit/feature/verify-email-valida…
Browse files Browse the repository at this point in the history
…tion-tests

Add tests for verify email input validation
  • Loading branch information
daniel-de-wit committed Apr 24, 2021
2 parents 05100e5 + b03ce2b commit 5fa68bc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions graphql/sanctum.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type EmailVerificationResponse {
}

input VerifyEmailInput {
id: ID! @rules(apply: ["required"])
hash: String! @rules(apply: ["required", "string"])
id: ID!
hash: String!
}

input RegisterInput {
Expand Down
66 changes: 66 additions & 0 deletions tests/Integration/GraphQL/Mutations/VerifyEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,70 @@ public function it_returns_an_error_if_the_hash_is_incorrect(): void
}
')->assertGraphQLErrorMessage('The provided id and hash are incorrect.');
}

/**
* @test
*/
public function it_returns_an_error_if_the_id_field_is_missing(): void
{
$this->graphQL(/** @lang GraphQL */ '
mutation {
verifyEmail(input: {
hash: "foobar"
}) {
status
}
}
')->assertGraphQLErrorMessage('Field VerifyEmailInput.id of required type ID! was not provided.');
}

/**
* @test
*/
public function it_returns_an_error_if_the_id_field_is_not_an_id(): void
{
$this->graphQL(/** @lang GraphQL */ '
mutation {
verifyEmail(input: {
id: true,
hash: "foobar"
}) {
status
}
}
')->assertGraphQLErrorMessage('Field "verifyEmail" argument "input" requires type ID!, found true.');
}

/**
* @test
*/
public function it_returns_an_error_if_the_hash_field_is_missing(): void
{
$this->graphQL(/** @lang GraphQL */ '
mutation {
verifyEmail(input: {
id: 123,
}) {
status
}
}
')->assertGraphQLErrorMessage('Field VerifyEmailInput.hash of required type String! was not provided.');
}

/**
* @test
*/
public function it_returns_an_error_if_the_has_field_is_not_a_string(): void
{
$this->graphQL(/** @lang GraphQL */ '
mutation {
verifyEmail(input: {
id: 123,
hash: 12345
}) {
status
}
}
')->assertGraphQLErrorMessage('Field "verifyEmail" argument "input" requires type String!, found 12345.');
}
}

0 comments on commit 5fa68bc

Please sign in to comment.