module DiscountNetworkApi

Public Instance Methods

stub_account_create_api(attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 106
def stub_account_create_api(attributes)
  stub_api_response(
    :post,
    "account",
    data: { subscriber: attributes },
    filename: "user",
  )
end
stub_account_find_api(auth_token) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 85
def stub_account_find_api(auth_token)
  DiscountNetwork.configuration.auth_token = auth_token
  stub_api_response(
    :get,
    "account",
    filename: "user",
    status: 200,
  )
end
stub_account_update_api(auth_token, attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 95
def stub_account_update_api(auth_token, attributes)
  DiscountNetwork.configuration.auth_token = auth_token
  stub_api_response(
    :put,
    "account",
    data: { subscriber: attributes },
    filename: "empty",
    status: 204,
  )
end
stub_activation_activate_api(token, attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 124
def stub_activation_activate_api(token, attributes)
  update_nested_account_resource(
    "activation", token, "user", user: attributes
  )
end
stub_activation_find_api(token) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 115
def stub_activation_find_api(token)
  stub_api_response(
    :get,
    ["account", "activation", token].join("/"),
    filename: "user",
    status: 200,
  )
end
stub_api_response(method, end_point, filename:, status: 200, data: nil) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 2
def stub_api_response(method, end_point, filename:, status: 200, data: nil)
  stub_request(method, api_end_point(end_point)).
    with(api_request_headers(data: data)).
    to_return(response_with(filename: filename, status: status))
end
stub_booking_find_api(booking_id) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 76
def stub_booking_find_api(booking_id)
  stub_api_response(
    :get,
    ["bookings", booking_id].join("/"),
    filename: "booking",
    status: 200
  )
end
stub_destination_list_api(term:) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 28
def stub_destination_list_api(term:)
  stub_api_response(
    :get,
    "destinations",
    data: { term: term },
    filename: "destinations",
    status: 200
  )
end
stub_password_create_api(token, attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 140
def stub_password_create_api(token, attributes)
  update_nested_account_resource(
    "passwords", token, "empty", account: attributes
  )
end
stub_password_forgot_api(email) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 130
def stub_password_forgot_api(email)
  stub_api_response(
    :post,
    "account/resets",
    data: { account: { email: email } },
    filename: "empty",
    status: 204,
  )
end
stub_password_validate_api(token) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 146
def stub_password_validate_api(token)
  stub_api_response(
    :get,
    ["account", "resets", token].join("/"),
    filename: "empty",
    status: 204,
  )
end
stub_provider_find_by_slug_api(slug) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 184
def stub_provider_find_by_slug_api(slug)
  stub_api_response(
    :get,
    ["providers", slug].join("/"),
    filename: "provider",
    status: 200,
  )
end
stub_provider_listing_api(provider_type) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 174
def stub_provider_listing_api(provider_type)
  stub_api_response(
    :get,
    "providers",
    data: { type: provider_type },
    filename: "providers",
    status: 200,
  )
end
stub_search_booking_create_api(booking_params) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 66
def stub_search_booking_create_api(booking_params)
  stub_api_response(
    :post,
    "bookings",
    data: { booking: build_booking_data(booking_params) },
    filename: "booking",
    status: 200
  )
end
stub_search_create_api(search_params) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 18
def stub_search_create_api(search_params)
  stub_api_response(
    :post,
    "searches",
    data: { search: search_params},
    filename: "search_created",
    status: 200
  )
end
stub_search_find_api(search_id) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 38
def stub_search_find_api(search_id)
  stub_api_response(
    :get,
    ["searches", search_id].join("/"),
    filename: "search",
    status: 200
  )
end
stub_search_result_api(search_id:, hotel_id:) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 57
def stub_search_result_api(search_id:, hotel_id:)
  stub_api_response(
    :get,
    ["searches", search_id, "results", hotel_id].join("/"),
    filename: "result",
    status: 200
  )
end
stub_search_results_api(search_id:, **attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 47
def stub_search_results_api(search_id:, **attributes)
  stub_api_response(
    :get,
    ["searches", search_id, "results"].join("/"),
    data: attributes,
    filename: "results",
    status: 200
  )
end
stub_session_create_api(login_params) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 8
def stub_session_create_api(login_params)
  stub_api_response(
    :post,
    "sessions",
    data: { login: login_params },
    filename: "session_created",
    status: 200
  )
end
stub_supplementary_create_api(attributes) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 164
def stub_supplementary_create_api(attributes)
  stub_api_response(
    :post,
    "supplementaries",
    data: { subscriber: attributes },
    filename: "supplementary",
    status: 200,
  )
end
stub_supplementary_list_api() click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 155
def stub_supplementary_list_api
  stub_api_response(
    :get,
    "supplementaries",
    filename: "supplementaries",
    status: 200,
  )
end
stub_unauthorized_dn_api_reqeust(end_point) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 193
def stub_unauthorized_dn_api_reqeust(end_point)
  stub_request(:any, api_end_point(end_point)).
    to_return(status: 401, body: "")
end
stub_unprocessable_dn_api_request(end_point) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 198
def stub_unprocessable_dn_api_request(end_point)
  stub_request(:any, api_end_point(end_point)).
    to_return(status: 422, body: "")
end

Private Instance Methods

api_authorization_headers() click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 247
def api_authorization_headers
  { "DN-API-KEY" => DiscountNetwork.configuration.api_key }
end
api_end_point(end_point) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 225
def api_end_point(end_point)
  [DiscountNetwork.configuration.api_host, end_point].join("/")
end
api_request_headers(data:) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 240
def api_request_headers(data:)
  Hash.new.tap do |request_headers|
    request_headers[:body] = data
    request_headers[:headers] = api_authorization_headers
  end
end
build_booking_data(search_id:, hotel_id:, travellers:, properties:, **opt) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 205
def build_booking_data(search_id:, hotel_id:, travellers:, properties:, **opt)
  opt.merge(
    search_id: search_id.to_s,
    travellers_attributes: [travellers],
    properties_attributes: [
      properties.merge(property_id: hotel_id.to_s)
    ]
  )
end
fixture_file(filename) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 233
def fixture_file(filename)
  file_name = [filename, "json"].join(".")
  file_path = ["../../../../", "spec", "fixtures", file_name].join("/")

  File.read(File.expand_path(file_path, __FILE__))
end
response_with(filename:, status:) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 229
def response_with(filename:, status:)
  { body: fixture_file(filename), status: status }
end
update_nested_account_resource(resource, token, filename, data_hash) click to toggle source
# File lib/discountnetwork/testing/discountnetwork_api.rb, line 215
def update_nested_account_resource(resource, token, filename, data_hash)
  stub_api_response(
    :put,
    ["account", resource, token].join("/"),
    data: data_hash,
    filename: filename,
    status: 200,
  )
end