@image @project
Feature: Update images

  <% providers = @formatter.get_fixture('providers/without_static') %>
  <% providers.each do |provider| %>
    <% image = @formatter.get_fixture(provider + '/image') %>
    <% other_providers = providers.clone - [provider] %>
    <% other_providers.each do |oprovider| %>
  @<%= provider %>
  Scenario: Update <%= provider %> image with '<%= oprovider %>' provider (invalid image id for provider)
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {value: {"provider" => oprovider}}) %>
    """
    Then response should be '422'

    <% end #other providers%>

    <% (image.keys - ["id", "name"]).each do |key| %>
    <% [[], {}].each do |invalid_value| %>
  @<%= provider %>
  Scenario: Update <%= provider %> image with invalid <%= key %> value: '<%= invalid_value %>'
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {value: {key => invalid_value}}) %>
    """
    Then response should be '400'

    <% end #invalid values%>

    <% end # keys%>
    <% (image.keys - ["id"]).each do |key| %>
  @<%= provider %>
  Scenario: Update <%= provider %> image with invalid <%= key %> value: 'nil'
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {value: {key => nil}}) %>
    """
    Then response should be '400'

    <% end %>

    <% (image.keys - ["name", "remote_user", "id"]).each do |key| %>
  @<%= provider %>
  Scenario: Update <%= provider %> image with invalid <%= key %> value: 'foo'
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {value: {key => "foo"}}) %>
    """
    Then response should be '422'

    <% end %>

  @<%= provider %>
  Scenario: Update <%= provider %> image with invalid image_id value: 'foo'
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {value: {"id" => "foo"}}) %>
    """
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an object
    And response should be JSON object like:
    """
    {
      "message" : "Image '<%= image["id"] %>' has been updated"
    }
    """

  Scenario: Update <%= provider %> image without id
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image', {without_field: "id"}) %>
    """
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an object
    And response should be JSON object like:
    """
    {
      "message" : "Image '<%= image["id"] %>' has been updated"
    }
    """

  @<%= provider %>
  Scenario: Update <%= provider %> image
    When I send PUT '/v3/image/<%= image["id"] %>' query with JSON body
    """
    <%= @formatter.json(provider + '/image') %>
    """
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an object
    And response should be JSON object like:
    """
    {
      "message" : "Image '<%= image["id"] %>' has been updated"
    }
    """

  <% end #providers %>

