@server @create
Feature: create server

  <% providers = @formatter.get_fixture('providers/without_static').map {|provider| "@#{provider}"} %>
  <%= providers.join(" ") %>
  Scenario: Get servers list before create
    When I send GET '/v3/servers' query
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array
    And the servers list should be saved

  <% @formatter.get_fixture('providers/without_static').each do |provider| %>
  <% server = @formatter.get_fixture(provider + '/server') %>

  <% generate_406 "Create server", "POST", "/v3/server", server, provider %>

  <% generate_mandatory_fields_validation "POST", "Create server", "/v3/server", server, @formatter.get_fixture(provider + '/server_mandatory_fields'), provider %>

  <%= "@#{provider}" %>
  Scenario: Create server
    When I send POST '/v3/server' query with JSON body
    """
<%= JSON.pretty_generate(server) %>

    """
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array
    And waiting background task

  <%= "@#{provider}" %>
  Scenario: Get servers list after create
    When I send GET '/v3/servers' query
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array
    And the servers list should contains new <%= provider %> server

  <%= "@#{provider}" %>
  Scenario: Create server (second time)
    When I send POST '/v3/server' query with JSON body
    """
<%= JSON.pretty_generate(server) %>

    """
    Then response should be '422'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Get <%= provider %> server id
    When I send GET '/v3/server/id/<%= server["name"] %>' query
    Then response should be '200'
    And store id in variable '<%= provider %>_server_id'

  <%= "@#{provider}" %>
  Scenario: Pause new <%= provider %> server
    When I pause new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Pause new <%= provider %> server (second time)
    When I pause new '<%= provider %>' server
    Then response should be '409'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Unpause new <%= provider %> server
    When I unpause new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Unpause new <%= provider %> server (second time)
    When I unpause new '<%= provider %>' server
    Then response should be '409'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Reserve new <%= provider %> server
    When I reserve new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Reserve new <%= provider %> server (second time)
    When I reserve new '<%= provider %>' server
    Then response should be '409'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Deploy new <%= provider %> server
    When I deploy new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array
    And waiting background task

  <%= "@#{provider}" %>
  Scenario: Unreserve new <%= provider %> server
    When I unreserve new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Unreserve new <%= provider %> server (second time)
    When I unreserve new '<%= provider %>' server
    Then response should be '409'
    And the Content-Type header should include 'application/json'

  <%= "@#{provider}" %>
  Scenario: Unbootstrap new <%= provider %> server
    When I unbootstrap new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array

  <%= "@#{provider}" %>
  Scenario: Bootstrap new <%= provider %> server
    When I bootstrap new '<%= provider %>' server
    Then response should be '200'
    And the Content-Type header should include 'application/json'
    And the JSON response should be an array
    And waiting background task

  <% end %>
