<commit_before>Feature: Error handling
  In order to be able to handle error client side
  As a client software developer
  I need to retrieve an Hydra serialization of errors

  Scenario: Get an error
    When I send a "POST" request to "/dummies" with body:
    """
    {}
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON should be equal to:
    """
    {
      "@context": "/contexts/ConstraintViolationList",
      "@type": "ConstraintViolationList",
      "hydra:title": "An error occurred",
      "hydra:description": "name: This value should not be blank.\n",
      "violations": [
        {
          "propertyPath": "name",
          "message": "This value should not be blank."
        }
      ]
    }
    """

  Scenario: Get an error during deserialization of simple relation
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
      "relatedDummy": {
        "name": "bar"
      }
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should be equal to 'Nested objects for attribute "relatedDummy" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\Dummy" are not enabled. Use serialization groups to change that behavior.'
    And the JSON node "trace" should exist

  Scenario: Get an error during deserialization of collection
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
      "relatedDummies": [{
        "name": "bar"
      }]
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should be equal to 'Nested objects for attribute "relatedDummies" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\Dummy" are not enabled. Use serialization groups to change that behavior.'
    And the JSON node "trace" should exist

  Scenario: Get an error because of an invalid JSON
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should be equal to 'Syntax error'
    And the JSON node "trace" should exist

  Scenario: I can't normalize unknown resources
    Given I send a "POST" request to "/related_dummies" with body:
    """
    {
      "unknown": "foo"
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:description" should be equal to 'IRI  not supported (found "foo" in "unknown" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\RelatedDummy")'
<commit_msg>Change assertion as the message could differ<commit_after>Feature: Error handling
  In order to be able to handle error client side
  As a client software developer
  I need to retrieve an Hydra serialization of errors

  Scenario: Get an error
    When I send a "POST" request to "/dummies" with body:
    """
    {}
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON should be equal to:
    """
    {
      "@context": "/contexts/ConstraintViolationList",
      "@type": "ConstraintViolationList",
      "hydra:title": "An error occurred",
      "hydra:description": "name: This value should not be blank.\n",
      "violations": [
        {
          "propertyPath": "name",
          "message": "This value should not be blank."
        }
      ]
    }
    """

  Scenario: Get an error during deserialization of simple relation
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
      "relatedDummy": {
        "name": "bar"
      }
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should be equal to 'Nested objects for attribute "relatedDummy" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\Dummy" are not enabled. Use serialization groups to change that behavior.'
    And the JSON node "trace" should exist

  Scenario: Get an error during deserialization of collection
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
      "relatedDummies": [{
        "name": "bar"
      }]
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should be equal to 'Nested objects for attribute "relatedDummies" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\Dummy" are not enabled. Use serialization groups to change that behavior.'
    And the JSON node "trace" should exist

  Scenario: Get an error because of an invalid JSON
    When I send a "POST" request to "/dummies" with body:
    """
    {
      "name": "Foo",
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the header "Content-Type" should be equal to "application/ld+json"
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:title" should be equal to "An error occurred"
    And the JSON node "hydra:description" should exist
    And the JSON node "trace" should exist

  Scenario: I can't normalize unknown resources
    Given I send a "POST" request to "/related_dummies" with body:
    """
    {
      "unknown": "foo"
    }
    """
    Then the response status code should be 400
    And the response should be in JSON
    And the JSON node "@context" should be equal to "/contexts/Error"
    And the JSON node "@type" should be equal to "Error"
    And the JSON node "hydra:description" should be equal to 'IRI  not supported (found "foo" in "unknown" of "Dunglas\ApiBundle\Tests\Behat\TestBundle\Entity\RelatedDummy")'

{'fraction_non_alphanumeric': 0.08916863362182009, 'fraction_numerical': 0.003933910306845004, 'mean_word_length': 2.925373134328358, 'pattern_counts': {'":': 30, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7631604', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2136, 'n_words': 980}