discountnetwork 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.hound.yml +3 -0
- data/.rspec +1 -0
- data/.rubocop.yml +629 -0
- data/.sample.pryrc +4 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +405 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/bin/setup +6 -0
- data/discountnetwork.gemspec +28 -0
- data/lib/discountnetwork/account.rb +28 -0
- data/lib/discountnetwork/activation.rb +15 -0
- data/lib/discountnetwork/base.rb +20 -0
- data/lib/discountnetwork/booking.rb +23 -0
- data/lib/discountnetwork/client.rb +54 -0
- data/lib/discountnetwork/configuration.rb +17 -0
- data/lib/discountnetwork/destination.rb +9 -0
- data/lib/discountnetwork/password.rb +21 -0
- data/lib/discountnetwork/provider.rb +15 -0
- data/lib/discountnetwork/response.rb +19 -0
- data/lib/discountnetwork/result.rb +15 -0
- data/lib/discountnetwork/rspec.rb +5 -0
- data/lib/discountnetwork/search.rb +15 -0
- data/lib/discountnetwork/session.rb +9 -0
- data/lib/discountnetwork/supplementary.rb +15 -0
- data/lib/discountnetwork/testing/discountnetwork_api.rb +240 -0
- data/lib/discountnetwork/version.rb +3 -0
- data/lib/discountnetwork.rb +16 -0
- data/spec/discountnetwork/account_spec.rb +36 -0
- data/spec/discountnetwork/activation_spec.rb +46 -0
- data/spec/discountnetwork/booking_spec.rb +70 -0
- data/spec/discountnetwork/client_spec.rb +40 -0
- data/spec/discountnetwork/configuration_spec.rb +30 -0
- data/spec/discountnetwork/destination_spec.rb +16 -0
- data/spec/discountnetwork/password_spec.rb +41 -0
- data/spec/discountnetwork/provider_spec.rb +26 -0
- data/spec/discountnetwork/response_spec.rb +16 -0
- data/spec/discountnetwork/result_spec.rb +30 -0
- data/spec/discountnetwork/search_spec.rb +37 -0
- data/spec/discountnetwork/session_spec.rb +18 -0
- data/spec/discountnetwork/supplementary_spec.rb +40 -0
- data/spec/fixtures/booking.json +86 -0
- data/spec/fixtures/destinations.json +22 -0
- data/spec/fixtures/empty.json +0 -0
- data/spec/fixtures/ping.json +3 -0
- data/spec/fixtures/provider.json +16 -0
- data/spec/fixtures/providers.json +32 -0
- data/spec/fixtures/result.json +89 -0
- data/spec/fixtures/results.json +121 -0
- data/spec/fixtures/search.json +19 -0
- data/spec/fixtures/search_created.json +19 -0
- data/spec/fixtures/session_created.json +31 -0
- data/spec/fixtures/supplementaries.json +33 -0
- data/spec/fixtures/supplementary.json +21 -0
- data/spec/fixtures/user.json +31 -0
- data/spec/spec_helper.rb +12 -0
- metadata +189 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module DiscountNetwork
|
4
|
+
class Response
|
5
|
+
attr_reader :response
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@response = response
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
JSON.parse(response, object_class: ResponseObject)
|
13
|
+
rescue JSON::ParserError => error
|
14
|
+
ResponseObject.new(error: error, content: "")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ResponseObject < OpenStruct; end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DiscountNetwork
|
2
|
+
class Result
|
3
|
+
def self.where(search_id:, **attributes)
|
4
|
+
DiscountNetwork.get_resource(
|
5
|
+
["searches", search_id, "results"].join("/"), attributes
|
6
|
+
).result
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find_by(search_id:, hotel_id:, **attributes)
|
10
|
+
DiscountNetwork.get_resource(
|
11
|
+
["searches", search_id, "results", hotel_id].join("/"), attributes
|
12
|
+
).result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DiscountNetwork
|
2
|
+
class Search
|
3
|
+
def self.create(search_params)
|
4
|
+
DiscountNetwork.post_resource(
|
5
|
+
"searches", search: search_params
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find(search_id)
|
10
|
+
DiscountNetwork.get_resource(
|
11
|
+
["searches", search_id].join("/")
|
12
|
+
).search
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DiscountNetwork
|
2
|
+
class Supplementary < Base
|
3
|
+
def list
|
4
|
+
DiscountNetwork.get_resource(
|
5
|
+
"supplementaries",
|
6
|
+
).supplementaries
|
7
|
+
end
|
8
|
+
|
9
|
+
def create(attributes)
|
10
|
+
DiscountNetwork.post_resource(
|
11
|
+
"supplementaries", subscriber: attributes
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
module DiscountNetworkApi
|
2
|
+
def stub_api_response(method, end_point, filename:, status: 200, data: nil)
|
3
|
+
stub_request(method, api_end_point(end_point)).
|
4
|
+
with(api_request_headers(data: data)).
|
5
|
+
to_return(response_with(filename: filename, status: status))
|
6
|
+
end
|
7
|
+
|
8
|
+
def stub_session_create_api(login_params)
|
9
|
+
stub_api_response(
|
10
|
+
:post,
|
11
|
+
"sessions",
|
12
|
+
data: { login: login_params },
|
13
|
+
filename: "session_created",
|
14
|
+
status: 200
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_search_create_api(search_params)
|
19
|
+
stub_api_response(
|
20
|
+
:post,
|
21
|
+
"searches",
|
22
|
+
data: { search: search_params},
|
23
|
+
filename: "search_created",
|
24
|
+
status: 200
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def stub_destination_list_api(term:)
|
29
|
+
stub_api_response(
|
30
|
+
:get,
|
31
|
+
"destinations",
|
32
|
+
data: { term: term },
|
33
|
+
filename: "destinations",
|
34
|
+
status: 200
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def stub_search_find_api(search_id)
|
39
|
+
stub_api_response(
|
40
|
+
:get,
|
41
|
+
["searches", search_id].join("/"),
|
42
|
+
filename: "search",
|
43
|
+
status: 200
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def stub_search_results_api(search_id:)
|
48
|
+
stub_api_response(
|
49
|
+
:get,
|
50
|
+
["searches", search_id, "results"].join("/"),
|
51
|
+
filename: "results",
|
52
|
+
status: 200
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def stub_search_result_api(search_id:, hotel_id:)
|
57
|
+
stub_api_response(
|
58
|
+
:get,
|
59
|
+
["searches", search_id, "results", hotel_id].join("/"),
|
60
|
+
filename: "result",
|
61
|
+
status: 200
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def stub_search_booking_create_api(booking_params)
|
66
|
+
stub_api_response(
|
67
|
+
:post,
|
68
|
+
"bookings",
|
69
|
+
data: { booking: build_booking_data(booking_params) },
|
70
|
+
filename: "booking",
|
71
|
+
status: 200
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def stub_booking_find_api(booking_id)
|
76
|
+
stub_api_response(
|
77
|
+
:get,
|
78
|
+
["bookings", booking_id].join("/"),
|
79
|
+
filename: "booking",
|
80
|
+
status: 200
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def stub_account_find_api(auth_token)
|
85
|
+
DiscountNetwork.configuration.auth_token = auth_token
|
86
|
+
stub_api_response(
|
87
|
+
:get,
|
88
|
+
"account",
|
89
|
+
filename: "user",
|
90
|
+
status: 200,
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def stub_account_update_api(auth_token, attributes)
|
95
|
+
DiscountNetwork.configuration.auth_token = auth_token
|
96
|
+
stub_api_response(
|
97
|
+
:put,
|
98
|
+
"account",
|
99
|
+
data: { subscriber: attributes },
|
100
|
+
filename: "empty",
|
101
|
+
status: 204,
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
def stub_activation_find_api(token)
|
106
|
+
stub_api_response(
|
107
|
+
:get,
|
108
|
+
["account", "activation", token].join("/"),
|
109
|
+
filename: "user",
|
110
|
+
status: 200,
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def stub_activation_activate_api(token, attributes)
|
115
|
+
update_nested_account_resource(
|
116
|
+
"activation", token, "user", user: attributes
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def stub_password_forgot_api(email)
|
121
|
+
stub_api_response(
|
122
|
+
:post,
|
123
|
+
"account/resets",
|
124
|
+
data: { account: { email: email } },
|
125
|
+
filename: "empty",
|
126
|
+
status: 204,
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def stub_password_create_api(token, attributes)
|
131
|
+
update_nested_account_resource(
|
132
|
+
"passwords", token, "empty", account: attributes
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
def stub_password_validate_api(token)
|
137
|
+
stub_api_response(
|
138
|
+
:get,
|
139
|
+
["account", "resets", token].join("/"),
|
140
|
+
filename: "empty",
|
141
|
+
status: 204,
|
142
|
+
)
|
143
|
+
end
|
144
|
+
|
145
|
+
def stub_supplementary_list_api
|
146
|
+
stub_api_response(
|
147
|
+
:get,
|
148
|
+
"supplementaries",
|
149
|
+
filename: "supplementaries",
|
150
|
+
status: 200,
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
def stub_supplementary_create_api(attributes)
|
155
|
+
stub_api_response(
|
156
|
+
:post,
|
157
|
+
"supplementaries",
|
158
|
+
data: { subscriber: attributes },
|
159
|
+
filename: "supplementary",
|
160
|
+
status: 200,
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def stub_provider_listing_api(provider_type)
|
165
|
+
stub_api_response(
|
166
|
+
:get,
|
167
|
+
"providers",
|
168
|
+
data: { type: provider_type },
|
169
|
+
filename: "providers",
|
170
|
+
status: 200,
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def stub_provider_find_by_slug_api(slug)
|
175
|
+
stub_api_response(
|
176
|
+
:get,
|
177
|
+
["providers", slug].join("/"),
|
178
|
+
filename: "provider",
|
179
|
+
status: 200,
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
183
|
+
def stub_unauthorized_dn_api_reqeust(end_point)
|
184
|
+
stub_request(:any, api_end_point(end_point)).
|
185
|
+
to_return(status: 401, body: "")
|
186
|
+
end
|
187
|
+
|
188
|
+
def stub_unprocessable_dn_api_request(end_point)
|
189
|
+
stub_request(:any, api_end_point(end_point)).
|
190
|
+
to_return(status: 422, body: "")
|
191
|
+
end
|
192
|
+
|
193
|
+
private
|
194
|
+
|
195
|
+
def build_booking_data(search_id:, hotel_id:, travellers:, properties:, **opt)
|
196
|
+
opt.merge(
|
197
|
+
search_id: search_id.to_s,
|
198
|
+
travellers_attributes: [travellers],
|
199
|
+
properties_attributes: [
|
200
|
+
properties.merge(property_id: hotel_id.to_s)
|
201
|
+
]
|
202
|
+
)
|
203
|
+
end
|
204
|
+
|
205
|
+
def update_nested_account_resource(resource, token, filename, data_hash)
|
206
|
+
stub_api_response(
|
207
|
+
:put,
|
208
|
+
["account", resource, token].join("/"),
|
209
|
+
data: data_hash,
|
210
|
+
filename: filename,
|
211
|
+
status: 200,
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
215
|
+
def api_end_point(end_point)
|
216
|
+
[DiscountNetwork.configuration.api_host, end_point].join("/")
|
217
|
+
end
|
218
|
+
|
219
|
+
def response_with(filename:, status:)
|
220
|
+
{ body: fixture_file(filename), status: status }
|
221
|
+
end
|
222
|
+
|
223
|
+
def fixture_file(filename)
|
224
|
+
file_name = [filename, "json"].join(".")
|
225
|
+
file_path = ["../../../../", "spec", "fixtures", file_name].join("/")
|
226
|
+
|
227
|
+
File.read(File.expand_path(file_path, __FILE__))
|
228
|
+
end
|
229
|
+
|
230
|
+
def api_request_headers(data:)
|
231
|
+
Hash.new.tap do |request_headers|
|
232
|
+
request_headers[:body] = data
|
233
|
+
request_headers[:headers] = api_authorization_headers
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def api_authorization_headers
|
238
|
+
{ "DN-API-KEY" => DiscountNetwork.configuration.api_key }
|
239
|
+
end
|
240
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "discountnetwork/version"
|
2
|
+
require "discountnetwork/client"
|
3
|
+
require "discountnetwork/base"
|
4
|
+
require "discountnetwork/session"
|
5
|
+
require "discountnetwork/account"
|
6
|
+
require "discountnetwork/search"
|
7
|
+
require "discountnetwork/result"
|
8
|
+
require "discountnetwork/booking"
|
9
|
+
require "discountnetwork/provider"
|
10
|
+
require "discountnetwork/password"
|
11
|
+
require "discountnetwork/activation"
|
12
|
+
require "discountnetwork/destination"
|
13
|
+
require "discountnetwork/supplementary"
|
14
|
+
|
15
|
+
module DiscountNetwork
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Account do
|
4
|
+
describe ".find" do
|
5
|
+
it "returns the subscriber's profile" do
|
6
|
+
auth_token = "ABCD_123"
|
7
|
+
stub_account_find_api(auth_token)
|
8
|
+
set_account_auth_token(auth_token)
|
9
|
+
|
10
|
+
account = DiscountNetwork::Account.find(auth_token)
|
11
|
+
set_account_auth_token(nil)
|
12
|
+
|
13
|
+
expect(account.name).not_to be_nil
|
14
|
+
expect(account.status).to eq("Active")
|
15
|
+
expect(account.token).to eq(auth_token)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".update" do
|
20
|
+
it "updates the subscriber account" do
|
21
|
+
auth_token = "ABCD_123"
|
22
|
+
set_account_auth_token(auth_token)
|
23
|
+
new_attributes = { first_name: "John", last_name: "Doe" }
|
24
|
+
|
25
|
+
stub_account_update_api(auth_token, new_attributes)
|
26
|
+
account = DiscountNetwork::Account.update(new_attributes)
|
27
|
+
|
28
|
+
expect(account).not_to be_nil
|
29
|
+
expect(account.class).to eq(DiscountNetwork::ResponseObject)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_account_auth_token(token)
|
34
|
+
DiscountNetwork.configuration.auth_token = token
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Activation do
|
4
|
+
describe ".find" do
|
5
|
+
it "retruns the subscriber account" do
|
6
|
+
token = "ABCD_123"
|
7
|
+
stub_activation_find_api(token)
|
8
|
+
account = DiscountNetwork::Activation.find(token)
|
9
|
+
|
10
|
+
expect(account.name).not_to be_nil
|
11
|
+
expect(account.token).to eq(token)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".activate" do
|
16
|
+
it "activates the subscriber account" do
|
17
|
+
token = "ABCD_123"
|
18
|
+
stub_activation_activate_api(token, subscriber_attributes)
|
19
|
+
account = DiscountNetwork::Activation.activate(
|
20
|
+
token, subscriber_attributes
|
21
|
+
)
|
22
|
+
|
23
|
+
expect(account.name).not_to be_nil
|
24
|
+
expect(account.status).to eq("Active")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def subscriber_attributes
|
29
|
+
@subscriber_attributes ||= {
|
30
|
+
first_name: "John",
|
31
|
+
last_name: "Doe",
|
32
|
+
sex: "Male",
|
33
|
+
address: "123 Main Street",
|
34
|
+
city: "New York",
|
35
|
+
zip: "NY123",
|
36
|
+
state: "New York",
|
37
|
+
phone: "+1 123 456 789 0123",
|
38
|
+
mobile: "+1 012 345 678 9012",
|
39
|
+
username: "john.doe",
|
40
|
+
email: "john.doe@example.com",
|
41
|
+
country: "US",
|
42
|
+
password: "secret_password",
|
43
|
+
password_confirmation: "secret_password",
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Booking do
|
4
|
+
describe ".create" do
|
5
|
+
it "creates a new booking request" do
|
6
|
+
search_id = 123_456_789
|
7
|
+
hotel_id = 456_789_012
|
8
|
+
booking_params = build_booking_attributes(search_id, hotel_id)
|
9
|
+
stub_search_booking_create_api(booking_params)
|
10
|
+
|
11
|
+
booking = DiscountNetwork::Booking.create(booking_params)
|
12
|
+
traveller = booking.travellers.first
|
13
|
+
property = booking.properties.first
|
14
|
+
|
15
|
+
expect(booking.code).not_to be_nil
|
16
|
+
expect(booking.travel_criteria.id).to eq(search_id)
|
17
|
+
expect(property.name).to eq(property_attributes[:name])
|
18
|
+
expect(traveller.email).to eq(traveller_attributes[:email])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".find" do
|
23
|
+
it "finds the booking details" do
|
24
|
+
booking_id = 123_456_789
|
25
|
+
stub_booking_find_api(booking_id)
|
26
|
+
booking = DiscountNetwork::Booking.find(booking_id)
|
27
|
+
|
28
|
+
expect(booking.id).to eq(booking_id)
|
29
|
+
expect(booking.travel_criteria).not_to be_nil
|
30
|
+
expect(booking.travellers.first).not_to be_nil
|
31
|
+
expect(booking.properties.first).not_to be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_booking_attributes(search_id, hotel_id)
|
36
|
+
{
|
37
|
+
search_id: search_id,
|
38
|
+
hotel_id: hotel_id,
|
39
|
+
travellers: traveller_attributes,
|
40
|
+
properties: property_attributes,
|
41
|
+
note: "This is a special requets"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def traveller_attributes
|
46
|
+
{
|
47
|
+
first_name: "John",
|
48
|
+
last_name: "Doe",
|
49
|
+
phone: "012 345 6789",
|
50
|
+
email: "john.doe@example.com",
|
51
|
+
address: "123 Main Street",
|
52
|
+
city: "Huai Khwang",
|
53
|
+
state: "Bangkok",
|
54
|
+
zip: "BK10310"
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def property_attributes
|
59
|
+
{
|
60
|
+
property_id: "property_101",
|
61
|
+
provider_name: "Booking.com",
|
62
|
+
name: "Nasa Vagas, Thailand",
|
63
|
+
price: "100.99",
|
64
|
+
description: "Description",
|
65
|
+
review_score: "90",
|
66
|
+
total_reviews: "10000",
|
67
|
+
currency_code: "USD"
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Client do
|
4
|
+
describe ".post_resource" do
|
5
|
+
it "requests the resource via :post" do
|
6
|
+
stub_discountnetwork_ping_request(:post, request_data)
|
7
|
+
response = DiscountNetwork.post_resource("ping", request_data)
|
8
|
+
|
9
|
+
expect(response.data).to eq("Pong!")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".get_resource" do
|
14
|
+
it "requests the resource via :get" do
|
15
|
+
stub_discountnetwork_ping_request(:get, request_data)
|
16
|
+
response = DiscountNetwork.get_resource("ping", request_data)
|
17
|
+
|
18
|
+
expect(response.data).to eq("Pong!")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ".put_resource" do
|
23
|
+
it "requests the resource via :put" do
|
24
|
+
stub_discountnetwork_ping_request(:put, request_data)
|
25
|
+
response = DiscountNetwork.put_resource("ping", request_data)
|
26
|
+
|
27
|
+
expect(response.data).to eq("Pong!")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_data
|
32
|
+
{ content: "Ping Request" }
|
33
|
+
end
|
34
|
+
|
35
|
+
def stub_discountnetwork_ping_request(method, data, end_point = "ping")
|
36
|
+
stub_api_response(
|
37
|
+
method, end_point, data: data, filename: "ping", status: 200
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Configuration do
|
4
|
+
describe ".configuration" do
|
5
|
+
it "returns the client configuraiton object" do
|
6
|
+
api_host = "https://api.discountnetwork.io/api/v1"
|
7
|
+
configuration = DiscountNetwork.configuration
|
8
|
+
|
9
|
+
expect(configuration.api_host).to eq(api_host)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#api_key" do
|
14
|
+
it "returns the customer specified api_key" do
|
15
|
+
api_key = "secrect_discountnetwork_api_key"
|
16
|
+
DiscountNetwork.configure { |config| config.api_key = api_key }
|
17
|
+
|
18
|
+
expect(DiscountNetwork.configuration.api_key).to eq(api_key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#auth_token" do
|
23
|
+
it "returns the user authentication token" do
|
24
|
+
auth_token = "user_secret_authentication_token"
|
25
|
+
DiscountNetwork.configure { |config| config.auth_token = auth_token }
|
26
|
+
|
27
|
+
expect(DiscountNetwork.configuration.auth_token).to eq(auth_token)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Destination do
|
4
|
+
describe ".list" do
|
5
|
+
it "returns the similar destinations" do
|
6
|
+
search_term = "bang"
|
7
|
+
stub_destination_list_api(term: search_term)
|
8
|
+
|
9
|
+
destinations = DiscountNetwork::Destination.list(term: search_term)
|
10
|
+
destination = destinations.first
|
11
|
+
|
12
|
+
expect(destination.value).to eq(835)
|
13
|
+
expect(destination.label).to eq("Bangkok, Thailand")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Password do
|
4
|
+
describe ".forgot" do
|
5
|
+
it "submits a password resets request" do
|
6
|
+
email = "john.doe@example.com"
|
7
|
+
stub_password_forgot_api(email)
|
8
|
+
password = DiscountNetwork::Password.forgot(email)
|
9
|
+
|
10
|
+
expect(password).not_to be_nil
|
11
|
+
expect(password.class).to eq(DiscountNetwork::ResponseObject)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".create" do
|
16
|
+
it "creates a new password" do
|
17
|
+
token = "ABCD_123"
|
18
|
+
password_attributes = {
|
19
|
+
password: "secret_password",
|
20
|
+
password_confirmation: "secret_password",
|
21
|
+
}
|
22
|
+
|
23
|
+
stub_password_create_api(token, password_attributes)
|
24
|
+
password = DiscountNetwork::Password.create(token, password_attributes)
|
25
|
+
|
26
|
+
expect(password).not_to be_nil
|
27
|
+
expect(password.class).to eq(DiscountNetwork::ResponseObject)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".validate" do
|
32
|
+
it "valides the password reset token" do
|
33
|
+
token = "ABCD_123"
|
34
|
+
stub_password_validate_api(token)
|
35
|
+
password = DiscountNetwork::Password.validate(token)
|
36
|
+
|
37
|
+
expect(password).not_to be_nil
|
38
|
+
expect(password.class).to eq(DiscountNetwork::ResponseObject)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Provider do
|
4
|
+
describe ".where" do
|
5
|
+
it "retrieve all providers for a specific type" do
|
6
|
+
provider_type = "hotel"
|
7
|
+
stub_provider_listing_api(provider_type)
|
8
|
+
providers = DiscountNetwork::Provider.where(type: provider_type)
|
9
|
+
|
10
|
+
expect(providers.count).to eq(2)
|
11
|
+
expect(providers.first.name).not_to be_nil
|
12
|
+
expect(providers.first.images.thumb).not_to be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".find_by_slug" do
|
17
|
+
it "retrieves a specific provider by a slug" do
|
18
|
+
provider_slug = "hotel-one"
|
19
|
+
stub_provider_find_by_slug_api(provider_slug)
|
20
|
+
provider = DiscountNetwork::Provider.find_by_slug(provider_slug)
|
21
|
+
|
22
|
+
expect(provider.name).not_to be_nil
|
23
|
+
expect(provider.slug).to eq(provider_slug)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DiscountNetwork::Response do
|
4
|
+
describe "#parse" do
|
5
|
+
it "parses the json content in object" do
|
6
|
+
response = DiscountNetwork::Response.new(json_data).parse
|
7
|
+
|
8
|
+
expect(response.data).to eq("Pong!")
|
9
|
+
expect(response.class).to eq(DiscountNetwork::ResponseObject)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def json_data
|
14
|
+
@json_content ||= File.read("./spec/fixtures/ping.json")
|
15
|
+
end
|
16
|
+
end
|