package <%= fullDomainPackage %>.infrastructure

import <%= pkg %>.domain.infrastructure.ControllerSpecificationBase
import <%= fullDomainPackage %>.<%= domain %>FactoryService
import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.micronaut.test.annotation.MicronautTest

import javax.inject.Inject

import static io.micronaut.http.HttpStatus.NOT_FOUND

@MicronautTest(transactional = false)
class <%= domain %>ControllerSpecification extends ControllerSpecificationBase {
   private static final String path = "/<%= table %>"

   @Inject <%= domain %>FactoryService <%= repository %>FactoryService

   void "fetch one <%= table.replace('_', ' ') %> by id" () {
      given:
      final def saved<%= domain %> = <%= repository %>FactoryService.single()

      when:
      def result = get("$path/${saved<%= domain %>.id}")

      then:
      result.id == saved<%= domain %>.id
      // TODO more testing of the result
   }

   void "fetch one <%= table.replace('_', ' ') %> by id not found" () {
      when:
      get("$path/0")

      then:
      final HttpClientResponseException exception = thrown(HttpClientResponseException)
      exception.response.status == NOT_FOUND
      def response = exception.response.body().with { parseResponse(it) }
      response.size() == 1
      response.message == "Resource 0 was unable to be found"
   }
}
