Given(/^valid file upload details and token available for an? (user|admin)$/) do |rights|
  case rights
  when "admin"
    @token_details = retrieve_upload_token(OA_USER_SERVICE_HEADERS).freeze
    assert_equal(200, @token_details[:code])
  when "user"
    @token_details = retrieve_upload_token.freeze
    assert_equal(200, @token_details[:code])
  end
end

When(/^a (jpg|wav|tif|flac|m4a) file is uploaded$/) do |filetype|
  parsed_response = JSON.parse(@token_details[:response])
  response_bucket = parsed_response["bucket"]

  file_path = case filetype
              when "jpg"
                RELATIVE_PATH + JPG_FILENAME
              when "wav"
                RELATIVE_PATH + WAV_FILENAME
              when "tif"
                RELATIVE_PATH + TIF_FILENAME
              when "flac"
                RELATIVE_PATH + FLAC_FILENAME
              when "m4a"
                RELATIVE_PATH + M4A_FILENAME
              end
  @s3_response = upload_file_to_s3(parsed_response,
                                   response_bucket,
                                   file_path,
                                   ".#{filetype}")
end

Then(/^valid response should be obtained from s3$/) do
  assert(@s3_response.successful?, "File was not uploaded. Response was not successful")
  refute_empty(@s3_response.data[:etag].tr('"', ""), "[etag] field was empty")
end

Given(/^the client has uploaded a valid (.*) file to s3$/) do |asset_ext|
  step "valid file upload details and token available for a user"
  step "a #{asset_ext} file is uploaded"
  step "valid response should be obtained from s3"
end

When(/^a file is uploaded to the wrong bucket$/) do
  parsed_response = JSON.parse(@token_details[:response])
  @s3_response = upload_file_to_s3(parsed_response,
                                   "wrong_bucket",
                                   FULL_PATH,
                                   DEFAULT_FILE_EXT,
                                   true)
end

Then(/^access denied response should be obtained from s3$/) do
  assert_equal("Access Denied", @s3_response)
end

When(/^a file is uploaded with no file extension$/) do
  parsed_response = JSON.parse(@token_details[:response])
  @s3_response = upload_file_to_s3(parsed_response,
                                   parsed_response["bucket"],
                                   RELATIVE_PATH + JPG_FILENAME,
                                   "",
                                   true)
end
