Module: DiscountNetworkApi

Defined in:
lib/discountnetwork/testing/discountnetwork_api.rb

Instance Method Summary collapse

Instance Method Details

#stub_account_find_api(auth_token) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 85

def (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) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 95

def (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) ⇒ Object



115
116
117
118
119
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 115

def stub_activation_activate_api(token, attributes)
  (
    "activation", token, "user", user: attributes
  )
end

#stub_activation_find_api(token) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 106

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) ⇒ Object



2
3
4
5
6
# 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) ⇒ Object



76
77
78
79
80
81
82
83
# 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:) ⇒ Object



28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



131
132
133
134
135
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 131

def stub_password_create_api(token, attributes)
  (
    "passwords", token, "empty", account: attributes
  )
end

#stub_password_forgot_api(email) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 121

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) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 137

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) ⇒ Object



175
176
177
178
179
180
181
182
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 175

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) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 165

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) ⇒ Object



66
67
68
69
70
71
72
73
74
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
# 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) ⇒ Object



38
39
40
41
42
43
44
45
# 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:) ⇒ Object



57
58
59
60
61
62
63
64
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
# 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) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 8

def stub_session_create_api()
  stub_api_response(
    :post,
    "sessions",
    data: { login:  },
    filename: "session_created",
    status: 200
  )
end

#stub_supplementary_create_api(attributes) ⇒ Object



155
156
157
158
159
160
161
162
163
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 155

def stub_supplementary_create_api(attributes)
  stub_api_response(
    :post,
    "supplementaries",
    data: { subscriber: attributes },
    filename: "supplementary",
    status: 200,
  )
end

#stub_supplementary_list_apiObject



146
147
148
149
150
151
152
153
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 146

def stub_supplementary_list_api
  stub_api_response(
    :get,
    "supplementaries",
    filename: "supplementaries",
    status: 200,
  )
end

#stub_unauthorized_dn_api_reqeust(end_point) ⇒ Object



184
185
186
187
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 184

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) ⇒ Object



189
190
191
192
# File 'lib/discountnetwork/testing/discountnetwork_api.rb', line 189

def stub_unprocessable_dn_api_request(end_point)
  stub_request(:any, api_end_point(end_point)).
    to_return(status: 422, body: "")
end