expressly 2.0.32.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +51 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +65 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +5 -0
- data/Rakefile +2 -0
- data/app/controllers/expressly/api_controller.rb +79 -0
- data/config/routes.rb +11 -0
- data/expressly.gemspec +29 -0
- data/lib/expressly.rb +49 -0
- data/lib/expressly/api.rb +126 -0
- data/lib/expressly/domain.rb +480 -0
- data/lib/expressly/engine.rb +3 -0
- data/lib/expressly/plugin_provider.rb +60 -0
- data/lib/expressly/util.rb +98 -0
- data/lib/expressly/version.rb +10 -0
- data/spec/expressly/domain_spec.rb +597 -0
- data/spec/expressly_spec.rb +11 -0
- data/spec/spec_helper.rb +13 -0
- metadata +125 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module Expressly
|
2
|
+
##
|
3
|
+
# This "interface" should be "implemented" by you and provided to the Expressly::Configuration constructor.
|
4
|
+
# It is the bridge between the expressly domain and your platform.
|
5
|
+
#
|
6
|
+
class MerchantPluginProvider
|
7
|
+
include AbstractInterface
|
8
|
+
|
9
|
+
##
|
10
|
+
# The popup_handler is called when a prospective customer has clicked on a campaign promotion
|
11
|
+
# and been directed to your shop. You are required to make a call to retrieve the expressly popup html
|
12
|
+
# and embed it on the landing page of your choice.
|
13
|
+
#
|
14
|
+
def popup_handler(controller, campaign_customer_uuid)
|
15
|
+
MerchantPluginProvider.api_not_implemented(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def customer_register(primary_email, customer)
|
19
|
+
MerchantPluginProvider.api_not_implemented(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def customer_send_password_reset_email(customer_reference)
|
23
|
+
MerchantPluginProvider.api_not_implemented(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def customer_update_cart(customer_reference, cart)
|
27
|
+
MerchantPluginProvider.api_not_implemented(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def customer_login(customer_reference)
|
31
|
+
MerchantPluginProvider.api_not_implemented(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def customer_migrated_redirect_url(success, customer_reference)
|
35
|
+
MerchantPluginProvider.api_not_implemented(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Some documentation on the check_customer_statuses method
|
40
|
+
# return Expressly::Customer
|
41
|
+
def get_customer(email)
|
42
|
+
MerchantPluginProvider.api_not_implemented(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Some documentation on the check_customer_statuses method
|
47
|
+
def check_customer_statuses(email_list)
|
48
|
+
MerchantPluginProvider.api_not_implemented(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Some documentation on the get_order_details method
|
53
|
+
# Returns ...
|
54
|
+
def get_customer_invoices(customer_invoice_request_list)
|
55
|
+
MerchantPluginProvider.api_not_implemented(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
module Expressly
|
3
|
+
module Helper
|
4
|
+
def blank?(obj)
|
5
|
+
obj.nil? or obj == ""
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ObjectHelper
|
10
|
+
def ObjectHelper.equals(this, that)
|
11
|
+
if this.equal?(that) then return true end
|
12
|
+
if !this.instance_of?(that.class) then return false end
|
13
|
+
|
14
|
+
allVars = Set.new(this.instance_variables).merge(that.instance_variables)
|
15
|
+
allVars.each { |v|
|
16
|
+
return false unless this.instance_variable_get(v) == that.instance_variable_get(v)
|
17
|
+
}
|
18
|
+
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
class Enumeration
|
25
|
+
|
26
|
+
def Enumeration.const_missing(key)
|
27
|
+
value = @hash[key]
|
28
|
+
|
29
|
+
if value
|
30
|
+
return value
|
31
|
+
end
|
32
|
+
|
33
|
+
raise("illegal enumeration key #{key}")
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def Enumeration.each
|
38
|
+
@hash.each {|key,value| yield(key,value)}
|
39
|
+
end
|
40
|
+
|
41
|
+
def Enumeration.values
|
42
|
+
@hash.values || []
|
43
|
+
end
|
44
|
+
|
45
|
+
def Enumeration.keys
|
46
|
+
@hash.keys || []
|
47
|
+
end
|
48
|
+
|
49
|
+
def Enumeration.[](key)
|
50
|
+
@hash[key]
|
51
|
+
end
|
52
|
+
|
53
|
+
def Enumeration.assertValidValue(value)
|
54
|
+
|
55
|
+
if value == nil
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
(@hash.values || []).each do |item|
|
60
|
+
if value == item
|
61
|
+
return
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
throw("illegal enumeration value #{value}")
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
def Enumeration.add_item(key,value)
|
71
|
+
@hash ||= {}
|
72
|
+
@hash[key]=value
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
module AbstractInterface
|
78
|
+
|
79
|
+
class InterfaceNotImplementedError < NoMethodError
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.included(klass)
|
83
|
+
klass.send(:include, AbstractInterface::Methods)
|
84
|
+
klass.send(:extend, AbstractInterface::Methods)
|
85
|
+
end
|
86
|
+
|
87
|
+
module Methods
|
88
|
+
|
89
|
+
def api_not_implemented(klass)
|
90
|
+
caller.first.match(/in \`(.+)\'/)
|
91
|
+
method_name = $1
|
92
|
+
raise AbstractInterface::InterfaceNotImplementedError.new("#{klass.class.name} needs to implement '#{method_name}' for interface #{self.name}!")
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,597 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'expressly/domain'
|
3
|
+
|
4
|
+
module Expressly
|
5
|
+
describe "CustomerImport" do
|
6
|
+
it "initialises correctly using a hashmap and be immutable once initialised" do
|
7
|
+
entityMap = {
|
8
|
+
:metadata => {:sender => 'me'},
|
9
|
+
:primary_email => 'p@test.com',
|
10
|
+
:cart => Cart.new( { :coupon_code => 'coupon', :product_id => 'product'}),
|
11
|
+
:customer => Customer.new({:first_name => 'adam'})
|
12
|
+
}
|
13
|
+
entity = CustomerImport.new(entityMap)
|
14
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
15
|
+
expect { entity.primary_email = '2345@test.com' }.to raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can be constructed from the json payload and generate a payload" do
|
19
|
+
payload = JSON.generate( {
|
20
|
+
:migration => {
|
21
|
+
:meta => { :sender => 'me' },
|
22
|
+
:data => {
|
23
|
+
:email => 'p@test.com',
|
24
|
+
:customerData => {
|
25
|
+
:firstName => 'adam'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
:cart => {
|
30
|
+
:couponCode => 'coupon',
|
31
|
+
:productId => 'product'
|
32
|
+
}
|
33
|
+
})
|
34
|
+
|
35
|
+
entity = CustomerImport.from_json(JSON.parse(payload))
|
36
|
+
entity.metadata['sender'].should == 'me'
|
37
|
+
entity.primary_email.should == 'p@test.com'
|
38
|
+
entity.customer.first_name.should == 'adam'
|
39
|
+
entity.cart.coupon_code == 'coupon'
|
40
|
+
entity.cart.product_id.should == 'product'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "CustomerExport" do
|
45
|
+
it "initialises correctly using a hashmap and be immutable once initialised" do
|
46
|
+
entityMap = {
|
47
|
+
:metadata => {:sender => 'me'},
|
48
|
+
:primary_email => 'p@test.com',
|
49
|
+
:customer => Customer.new({:first_name => 'adam'})
|
50
|
+
}
|
51
|
+
entity = CustomerExport.new(entityMap)
|
52
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
53
|
+
expect { entity.primary_email = '2345@test.com' }.to raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
it "can generate the json payload" do
|
57
|
+
entityMap = {
|
58
|
+
:metadata => {:sender => 'me'},
|
59
|
+
:primary_email => 'p@test.com',
|
60
|
+
:customer => Customer.new({:first_name => 'adam'})
|
61
|
+
}
|
62
|
+
payload = JSON.parse(CustomerExport.new(entityMap).to_json())
|
63
|
+
payload['meta']['sender'].should == 'me'
|
64
|
+
payload['data']['email'].should == 'p@test.com'
|
65
|
+
payload['data']['customerData']['firstName'].should == 'adam'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "Cart" do
|
70
|
+
it "initialises correctly using a hashmap" do
|
71
|
+
entityMap = { :coupon_code => 'coupon', :product_id => 'product'}
|
72
|
+
entity = Cart.new(entityMap)
|
73
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be immutable once initialised" do
|
77
|
+
entityMap = { :coupon_code => 'coupon', :product_id => 'product'}
|
78
|
+
entity = Cart.new(entityMap)
|
79
|
+
expect { entity.coupon_code = '2345' }.to raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can be constructed from the json payload and generate a payload" do
|
83
|
+
payload = JSON.generate({ :couponCode => 'coupon', :productId => 'product' })
|
84
|
+
entity = Cart.from_json(JSON.parse(payload))
|
85
|
+
entity.coupon_code.should == 'coupon'
|
86
|
+
entity.product_id.should == 'product'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "Phone" do
|
91
|
+
it "initialises correctly using a hashmap" do
|
92
|
+
entityMap = { :type => PhoneType::Work, :number => '1234', :country_code => 44 }
|
93
|
+
entity = Phone.new(entityMap)
|
94
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be immutable once initialised" do
|
98
|
+
entityMap = { :type => PhoneType::Work, :number => '1234' }
|
99
|
+
entity = Phone.new(entityMap)
|
100
|
+
expect { entity.number = '2345' }.to raise_error
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should raise an error if phone type is not valid" do
|
104
|
+
expect { Phone.new({ :type => "CellHomeWork" }) }.to raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should raise an error if country_code is not an integer" do
|
108
|
+
expect { Phone.new({ :country_code => "44" }) }.to raise_error
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should not raise an error if country_code is supplied but blank" do
|
112
|
+
Phone.new({ :country_code => '' })
|
113
|
+
Phone.new({ :country_code => nil })
|
114
|
+
end
|
115
|
+
|
116
|
+
it "implements equals correctly" do
|
117
|
+
phone1 = Phone.new({ :type => PhoneType::Work, :number => '1234' })
|
118
|
+
phone2 = Phone.new({ :type => PhoneType::Work, :number => '1234' })
|
119
|
+
phone1.should == phone2
|
120
|
+
phone2.should == phone1
|
121
|
+
|
122
|
+
phone3 = Phone.new({ :type => PhoneType::Home, :number => '1234' })
|
123
|
+
phone1.should_not == phone3
|
124
|
+
phone3.should_not == phone1
|
125
|
+
|
126
|
+
phone4 = Phone.new({ :type => PhoneType::Work, :number => '2345' })
|
127
|
+
phone1.should_not == phone4
|
128
|
+
phone4.should_not == phone1
|
129
|
+
|
130
|
+
phone5 = Phone.new({ :type => PhoneType::Work })
|
131
|
+
phone1.should_not == phone5
|
132
|
+
phone5.should_not == phone1
|
133
|
+
|
134
|
+
phone6 = Phone.new({ :number => '1234' })
|
135
|
+
phone1.should_not == phone6
|
136
|
+
phone6.should_not == phone1
|
137
|
+
|
138
|
+
phone7 = Phone.new({ :type => PhoneType::Work, :number => nil })
|
139
|
+
phone8 = Phone.new({ :type => PhoneType::Work })
|
140
|
+
phone7.should == phone8
|
141
|
+
phone8.should == phone7
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
it "can be constructed from the json payload and generate a payload" do
|
146
|
+
payload = JSON.generate({ :type => 'W', :number => '1234', :countryCode => 44 })
|
147
|
+
entity = Phone.from_json(JSON.parse(payload))
|
148
|
+
entity.type.should == PhoneType::Work
|
149
|
+
entity.number.should == '1234'
|
150
|
+
entity.country_code.should == 44
|
151
|
+
|
152
|
+
entityCopy = Phone.from_json(JSON.parse(entity.to_json))
|
153
|
+
entityCopy.type.should == PhoneType::Work
|
154
|
+
entityCopy.number.should == '1234'
|
155
|
+
entityCopy.country_code.should == 44
|
156
|
+
entity.should == entityCopy
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "EmailAddress" do
|
161
|
+
it "initialises correctly using a hashmap" do
|
162
|
+
entityMap = { :email => 'm@test.com', :alias => 'personal' }
|
163
|
+
entity = EmailAddress.new(entityMap)
|
164
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should be immutable once initialised" do
|
168
|
+
entityMap = { :email => 'm@test.com', :alias => 'personal' }
|
169
|
+
entity = EmailAddress.new(entityMap)
|
170
|
+
expect { entity.email = 'n@test.com' }.to raise_error
|
171
|
+
end
|
172
|
+
|
173
|
+
it "implements equals correctly" do
|
174
|
+
email1 = EmailAddress.new({ :email => 'm@test.com', :alias => 'personal' })
|
175
|
+
email2 = EmailAddress.new({ :email => 'm@test.com', :alias => 'personal' })
|
176
|
+
email3 = EmailAddress.new({ :email => 'n@test.com', :alias => 'personal' })
|
177
|
+
email1.should == email2
|
178
|
+
email2.should == email1
|
179
|
+
email1.should_not == email3
|
180
|
+
end
|
181
|
+
|
182
|
+
it "can be constructed from the json payload and generate a payload" do
|
183
|
+
payload = JSON.generate({ :email => 'm@test.com', :alias => 'personal' })
|
184
|
+
entity = EmailAddress.from_json(JSON.parse(payload))
|
185
|
+
entity.email.should == 'm@test.com'
|
186
|
+
entity.alias.should == 'personal'
|
187
|
+
|
188
|
+
entityCopy = EmailAddress.from_json(JSON.parse(entity.to_json))
|
189
|
+
entity.email.should == 'm@test.com'
|
190
|
+
entity.alias.should == 'personal'
|
191
|
+
entity.should == entityCopy
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "Customer" do
|
196
|
+
it "initialises correctly using a hashmap" do
|
197
|
+
entityMap = {
|
198
|
+
:first_name => 'First',
|
199
|
+
:last_name => 'Last',
|
200
|
+
:gender => Gender::Male,
|
201
|
+
:billing_address_index => 0,
|
202
|
+
:shipping_address_index => 1,
|
203
|
+
:company_name => 'Company',
|
204
|
+
:date_of_birth => Date.parse('1975-08-14'),
|
205
|
+
:tax_number => 'Tax#',
|
206
|
+
:last_updated => DateTime.now,
|
207
|
+
|
208
|
+
:online_identity_list => [
|
209
|
+
OnlineIdentity.new({ :type => OnlineIdentityType::Twitter, :identity => '@ev' }),
|
210
|
+
OnlineIdentity.new({ :type => OnlineIdentityType::Facebook, :identity => 'fb.ev' })],
|
211
|
+
|
212
|
+
:phone_list => [
|
213
|
+
Phone.new({ :type => PhoneType::Work, :number => '12345' }),
|
214
|
+
Phone.new({ :type => PhoneType::Mobile, :number => '56789' })],
|
215
|
+
|
216
|
+
:email_list => [
|
217
|
+
EmailAddress.new({ :email => 'm@test.com', :alias => 'personal' }),
|
218
|
+
EmailAddress.new({ :email => 'w@test.com', :alias => 'work' })],
|
219
|
+
|
220
|
+
:address_list => [
|
221
|
+
Address.new({:first_name => 'f1', :address_1 => 'one'}),
|
222
|
+
Address.new({:first_name => 'f2', :address_1 => 'two'})],
|
223
|
+
|
224
|
+
:last_order_date => Date.parse('2015-09-14'),
|
225
|
+
:number_of_orders => 2
|
226
|
+
}
|
227
|
+
entity = Customer.new(entityMap)
|
228
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
229
|
+
|
230
|
+
expect { entity.first_name = 'Donald' }.to raise_error
|
231
|
+
entity.should == Customer.new(entityMap)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should raise an error if phone_index is not an integer" do
|
235
|
+
expect { Address.new({ :phone_index => "1" }) }.to raise_error
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should not raise an error if country_code is supplied but blank" do
|
239
|
+
Address.new({ :phone_index => '' })
|
240
|
+
Address.new({ :phone_index => nil })
|
241
|
+
end
|
242
|
+
|
243
|
+
it "can be constructed from the json payload and generate a payload" do
|
244
|
+
payload = JSON.generate({
|
245
|
+
:firstName => 'First',
|
246
|
+
:lastName => 'Last',
|
247
|
+
:gender => 'M',
|
248
|
+
:billingAddress => 1,
|
249
|
+
:shippingAddress => 0,
|
250
|
+
:company => 'Company',
|
251
|
+
:dob => '1975-08-14',
|
252
|
+
:taxNumber => 'Tax#',
|
253
|
+
:dateUpdated => '2015-08-14T08:00:00',
|
254
|
+
|
255
|
+
:onlinePresence => [
|
256
|
+
{ :field => 'twitter', :value => '@ev' },
|
257
|
+
{ :field => 'facebook', :value => 'fb.ev' }],
|
258
|
+
|
259
|
+
:phones => [
|
260
|
+
{ :type => 'W', :number => '12345' },
|
261
|
+
{ :type => 'M', :number => '56789' }],
|
262
|
+
|
263
|
+
:emails => [
|
264
|
+
{ :email => 'm@test.com', :alias => 'personal' },
|
265
|
+
{ :email => 'w@test.com', :alias => 'work' } ],
|
266
|
+
|
267
|
+
:addresses => [
|
268
|
+
{:firstName => 'f1', :address1 => 'one'},
|
269
|
+
{:firstName => 'f2', :address1 => 'two'}],
|
270
|
+
|
271
|
+
:dateLastOrder => '2015-09-14',
|
272
|
+
:numberOrdered => 2 })
|
273
|
+
|
274
|
+
entity = Customer.from_json(JSON.parse(payload))
|
275
|
+
entity.first_name.should == 'First'
|
276
|
+
entity.last_name.should == 'Last'
|
277
|
+
entity.gender.should == Gender::Male
|
278
|
+
entity.billing_address_index.should == 1
|
279
|
+
entity.shipping_address_index.should == 0
|
280
|
+
entity.company_name.should == 'Company'
|
281
|
+
entity.date_of_birth.should == Date.parse('1975-08-14')
|
282
|
+
entity.tax_number.should == 'Tax#'
|
283
|
+
entity.last_updated.should == DateTime.parse('2015-08-14T08:00:00')
|
284
|
+
entity.last_order_date.should == Date.parse('2015-09-14')
|
285
|
+
entity.number_of_orders.should == 2
|
286
|
+
|
287
|
+
entity.online_identity_list.length.should == 2
|
288
|
+
entity.phone_list.length.should == 2
|
289
|
+
entity.email_list.length.should == 2
|
290
|
+
entity.address_list.length.should == 2
|
291
|
+
|
292
|
+
entityCopy = Customer.from_json(JSON.parse(entity.to_json))
|
293
|
+
entity.should == entityCopy
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "OnlineIdentity" do
|
298
|
+
it "initialises correctly using a hashmap" do
|
299
|
+
entityMap = { :type => OnlineIdentityType::Twitter, :identity => '@ev' }
|
300
|
+
entity = OnlineIdentity.new(entityMap)
|
301
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should be immutable once initialised" do
|
305
|
+
entityMap = { :type => OnlineIdentityType::Twitter, :identity => '@ev' }
|
306
|
+
entity = OnlineIdentity.new(entityMap)
|
307
|
+
expect { entity.identity = '@who' }.to raise_error
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should raise an error if phone type is not valid" do
|
311
|
+
expect { OnlineIdentity.new({ :type => "AOL" }) }.to raise_error
|
312
|
+
end
|
313
|
+
|
314
|
+
it "implements equals correctly" do
|
315
|
+
entity1 = OnlineIdentity.new({ :type => OnlineIdentityType::Twitter, :identity => '@ev' })
|
316
|
+
entity2 = OnlineIdentity.new({ :type => OnlineIdentityType::Twitter, :identity => '@ev' })
|
317
|
+
entity3 = OnlineIdentity.new({ :type => OnlineIdentityType::Twitter, :identity => '@who' })
|
318
|
+
entity1.should == entity2
|
319
|
+
entity2.should == entity1
|
320
|
+
entity1.should_not == entity3
|
321
|
+
end
|
322
|
+
|
323
|
+
it "can be constructed from the json payload and generate a payload" do
|
324
|
+
payload = JSON.generate({ :field => 'twitter', :value => '@ev' })
|
325
|
+
entity = OnlineIdentity.from_json(JSON.parse(payload))
|
326
|
+
entity.type.should == OnlineIdentityType::Twitter
|
327
|
+
entity.identity.should == '@ev'
|
328
|
+
|
329
|
+
entityCopy = OnlineIdentity.from_json(JSON.parse(entity.to_json))
|
330
|
+
entity.should == entityCopy
|
331
|
+
end
|
332
|
+
|
333
|
+
it "can be constructed from the json list payload" do
|
334
|
+
payload = JSON.generate([{ :field => 'twitter', :value => '@ev' }, { :field => 'facebook', :value => 'http://fb.com/ev' }])
|
335
|
+
entity_list = OnlineIdentity.from_json_list(JSON.parse(payload))
|
336
|
+
entity_list[0].type.should == OnlineIdentityType::Twitter
|
337
|
+
entity_list[0].identity.should == '@ev'
|
338
|
+
entity_list[1].type.should == OnlineIdentityType::Facebook
|
339
|
+
entity_list[1].identity.should == 'http://fb.com/ev'
|
340
|
+
end
|
341
|
+
|
342
|
+
it "nil json list payload produces an empty list" do
|
343
|
+
entity_list = OnlineIdentity.from_json_list(nil)
|
344
|
+
entity_list.length.should == 0
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "Address" do
|
350
|
+
it "initialises correctly using a hashmap" do
|
351
|
+
entityMap = {
|
352
|
+
:first_name => 'Mickey',
|
353
|
+
:last_name => 'Duck',
|
354
|
+
:address_1 => 'The House',
|
355
|
+
:address_2 => 'My Street',
|
356
|
+
:city => 'Town',
|
357
|
+
:company_name => 'Dosney',
|
358
|
+
:zip => 'SW18 1AL',
|
359
|
+
:phone_index => 1,
|
360
|
+
:address_alias => 'alternative',
|
361
|
+
:state_province => 'Bucks',
|
362
|
+
:country => 'UK' }
|
363
|
+
entity = Address.new(entityMap)
|
364
|
+
entityMap.map { |(k, v)| entity.public_send("#{k}").should == v }
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should be immutable once initialised" do
|
368
|
+
entityMap = { :first_name => 'Mickey'}
|
369
|
+
entity = Address.new(entityMap)
|
370
|
+
expect { entity.first_name = 'Donald' }.to raise_error
|
371
|
+
end
|
372
|
+
|
373
|
+
it "should raise an error if phone_index is not an integer" do
|
374
|
+
expect { Address.new({ :phone_index => "1" }) }.to raise_error
|
375
|
+
end
|
376
|
+
|
377
|
+
it "should not raise an error if country_code is supplied but blank" do
|
378
|
+
Address.new({ :phone_index => '' })
|
379
|
+
Address.new({ :phone_index => nil })
|
380
|
+
end
|
381
|
+
|
382
|
+
it "implements equals correctly" do
|
383
|
+
entityMap = {
|
384
|
+
:first_name => 'Mickey',
|
385
|
+
:last_name => 'Duck',
|
386
|
+
:address_1 => 'The House',
|
387
|
+
:address_2 => 'My Street',
|
388
|
+
:city => 'Town',
|
389
|
+
:company_name => 'Dosney',
|
390
|
+
:zip => 'SW18 1AL',
|
391
|
+
:phone_index => 1,
|
392
|
+
:address_alias => 'alternative',
|
393
|
+
:state_province => 'Bucks',
|
394
|
+
:country => 'UK' }
|
395
|
+
entity1 = Address.new(entityMap)
|
396
|
+
entity2 = Address.new(entityMap)
|
397
|
+
entity1.should == entity2
|
398
|
+
entity2.should == entity1
|
399
|
+
|
400
|
+
entityMap[:first_name] = 'Who'
|
401
|
+
entity3 = Address.new(entityMap)
|
402
|
+
entity1.should_not == entity3
|
403
|
+
end
|
404
|
+
|
405
|
+
it "can be constructed from the json payload and generate a payload" do
|
406
|
+
payload = JSON.generate({
|
407
|
+
:firstName => 'Mickey',
|
408
|
+
:lastName => 'Duck',
|
409
|
+
:address1 => 'The House',
|
410
|
+
:address2 => 'My Street',
|
411
|
+
:city => 'Town',
|
412
|
+
:companyName => 'Dosney',
|
413
|
+
:zip => 'SW18 1AL',
|
414
|
+
:phone => 1,
|
415
|
+
:alias => 'alternative',
|
416
|
+
:stateProvince => 'Bucks',
|
417
|
+
:country => 'UK' })
|
418
|
+
entity = Address.from_json(JSON.parse(payload))
|
419
|
+
entity.first_name.should == 'Mickey'
|
420
|
+
entity.last_name.should == 'Duck'
|
421
|
+
entity.address_1.should == 'The House'
|
422
|
+
entity.address_2.should == 'My Street'
|
423
|
+
entity.company_name.should == 'Dosney'
|
424
|
+
entity.zip.should == 'SW18 1AL'
|
425
|
+
entity.phone_index.should == 1
|
426
|
+
entity.address_alias.should == 'alternative'
|
427
|
+
entity.state_province.should == 'Bucks'
|
428
|
+
entity.country.should == 'UK'
|
429
|
+
|
430
|
+
entityCopy = Address.from_json(JSON.parse(entity.to_json))
|
431
|
+
entity.should == entityCopy
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
describe "CustomerStatuses" do
|
436
|
+
it "initialises correctly and emails can be added" do
|
437
|
+
entity = CustomerStatuses.new()
|
438
|
+
entity.add_existing("e1@test.com")
|
439
|
+
entity.add_existing("e2@test.com")
|
440
|
+
entity.add_pending("p1@test.com")
|
441
|
+
entity.add_deleted("d1@test.com")
|
442
|
+
|
443
|
+
entity.existing.should == ["e1@test.com", "e2@test.com"]
|
444
|
+
entity.pending.should == ["p1@test.com"]
|
445
|
+
entity.deleted.should == ["d1@test.com"]
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
describe "CustomerInvoiceRequest" do
|
450
|
+
it "initialises correctly" do
|
451
|
+
entity = CustomerInvoiceRequest.new("m@test.com", "2015-06-12", "2015-07-12")
|
452
|
+
entity.email.should == "m@test.com"
|
453
|
+
entity.from.should == Date.parse("2015-06-12")
|
454
|
+
entity.to.should == Date.parse("2015-07-12")
|
455
|
+
end
|
456
|
+
|
457
|
+
it "can be constructed from the json payload and generate a payload" do
|
458
|
+
payload = JSON.generate({ :email => 'm@test.com', :from => '2015-06-12', :to => '2015-07-12' })
|
459
|
+
entity = CustomerInvoiceRequest.from_json(JSON.parse(payload))
|
460
|
+
entity.email.should == "m@test.com"
|
461
|
+
entity.from.should == Date.parse("2015-06-12")
|
462
|
+
entity.to.should == Date.parse("2015-07-12")
|
463
|
+
end
|
464
|
+
|
465
|
+
it "can be constructed from the json list payload" do
|
466
|
+
payload = JSON.generate([
|
467
|
+
{ :email => 'm@test.com', :from => '2015-06-12', :to => '2015-07-12' },
|
468
|
+
{ :email => 'n@test.com', :from => '2016-06-12', :to => '2016-07-12' }])
|
469
|
+
|
470
|
+
entity_list = CustomerInvoiceRequest.from_json_list(JSON.parse(payload))
|
471
|
+
entity_list[0].email.should == "m@test.com"
|
472
|
+
entity_list[0].from.should == Date.parse("2015-06-12")
|
473
|
+
entity_list[0].to.should == Date.parse("2015-07-12")
|
474
|
+
entity_list[1].email.should == "n@test.com"
|
475
|
+
entity_list[1].from.should == Date.parse("2016-06-12")
|
476
|
+
entity_list[1].to.should == Date.parse("2016-07-12")
|
477
|
+
end
|
478
|
+
|
479
|
+
it "nil json list payload produces an empty list" do
|
480
|
+
entity_list = CustomerInvoiceRequest.from_json_list(nil)
|
481
|
+
entity_list.length.should == 0
|
482
|
+
end
|
483
|
+
|
484
|
+
end
|
485
|
+
|
486
|
+
describe "CustomerOrder" do
|
487
|
+
it "initialises correctly" do
|
488
|
+
entity_map = {
|
489
|
+
:order_id => 'orderid',
|
490
|
+
:order_date => '2015-08-14',
|
491
|
+
:item_count => 5,
|
492
|
+
:coupon_code => 'coupon',
|
493
|
+
:currency => 'GBP',
|
494
|
+
:pre_tax_total => 100.15,
|
495
|
+
:post_tax_total => 120.65,
|
496
|
+
:tax => 20.50 }
|
497
|
+
entity = CustomerOrder.new(entity_map)
|
498
|
+
entity.order_id.should == "orderid"
|
499
|
+
entity.order_date.should == Date.parse("2015-08-14")
|
500
|
+
entity.item_count.should == 5
|
501
|
+
entity.coupon_code.should == "coupon"
|
502
|
+
entity.currency.should == "GBP"
|
503
|
+
entity.pre_tax_total.should == 100.15
|
504
|
+
entity.post_tax_total.should == 120.65
|
505
|
+
entity.tax.should == 20.50
|
506
|
+
end
|
507
|
+
|
508
|
+
it "it can generate the expected json payload" do
|
509
|
+
entity_map = {
|
510
|
+
:order_id => 'orderid',
|
511
|
+
:order_date => '2015-08-14',
|
512
|
+
:item_count => "5",
|
513
|
+
:coupon_code => 'coupon',
|
514
|
+
:currency => 'GBP',
|
515
|
+
:pre_tax_total => '100.15',
|
516
|
+
:post_tax_total => '120.65',
|
517
|
+
:tax => '20.50' }
|
518
|
+
json = CustomerOrder.new(entity_map).to_json()
|
519
|
+
payload = JSON.parse(json)
|
520
|
+
|
521
|
+
payload['id'].should == "orderid"
|
522
|
+
payload['date'].should == "2015-08-14"
|
523
|
+
payload['itemCount'].should == 5
|
524
|
+
payload['coupon'].should == "coupon"
|
525
|
+
payload['currency'].should == "GBP"
|
526
|
+
payload['preTaxTotal'].should == 100.15
|
527
|
+
payload['postTaxTotal'].should == 120.65
|
528
|
+
payload['tax'].should == 20.50
|
529
|
+
end
|
530
|
+
|
531
|
+
end
|
532
|
+
|
533
|
+
describe "CustomerInvoice" do
|
534
|
+
it "initialises correctly" do
|
535
|
+
entity = CustomerInvoice.new('email@test.com')
|
536
|
+
entity.email.should == 'email@test.com'
|
537
|
+
end
|
538
|
+
|
539
|
+
it "it can generate the expected json payload" do
|
540
|
+
entity = CustomerInvoice.new('email@test.com')
|
541
|
+
|
542
|
+
entity.add_order(CustomerOrder.new({
|
543
|
+
:order_id => 'orderid',
|
544
|
+
:order_date => '2015-08-14',
|
545
|
+
:item_count => 5,
|
546
|
+
:coupon_code => 'coupon',
|
547
|
+
:currency => 'GBP',
|
548
|
+
:pre_tax_total => '100.15',
|
549
|
+
:post_tax_total => '120.65',
|
550
|
+
:tax => '20.50' }))
|
551
|
+
|
552
|
+
entity.add_order(CustomerOrder.new({
|
553
|
+
:order_id => 'orderid1',
|
554
|
+
:order_date => '2015-08-14',
|
555
|
+
:item_count => 2,
|
556
|
+
:coupon_code => 'coupon',
|
557
|
+
:currency => 'GBP',
|
558
|
+
:pre_tax_total => '50.15',
|
559
|
+
:post_tax_total => '60.65',
|
560
|
+
:tax => '10.50' }))
|
561
|
+
|
562
|
+
payload = JSON.parse(entity.to_json())
|
563
|
+
payload['email'].should == 'email@test.com'
|
564
|
+
payload['orderCount'].should == 2
|
565
|
+
payload['preTaxTotal'].should == 150.30
|
566
|
+
payload['postTaxTotal'].should == 181.30
|
567
|
+
payload['tax'].should == 31.0
|
568
|
+
|
569
|
+
order1 = payload['orders'][0]
|
570
|
+
order1['id'].should == "orderid"
|
571
|
+
order1['date'].should == "2015-08-14"
|
572
|
+
order1['itemCount'].should == 5
|
573
|
+
order1['coupon'].should == "coupon"
|
574
|
+
order1['currency'].should == "GBP"
|
575
|
+
order1['preTaxTotal'].should == 100.15
|
576
|
+
order1['postTaxTotal'].should == 120.65
|
577
|
+
order1['tax'].should == 20.50
|
578
|
+
|
579
|
+
order2 = payload['orders'][1]
|
580
|
+
order2['id'].should == "orderid1"
|
581
|
+
order2['date'].should == "2015-08-14"
|
582
|
+
order2['itemCount'].should == 2
|
583
|
+
order2['coupon'].should == "coupon"
|
584
|
+
order2['currency'].should == "GBP"
|
585
|
+
order2['preTaxTotal'].should == 50.15
|
586
|
+
order2['postTaxTotal'].should == 60.65
|
587
|
+
order2['tax'].should == 10.50
|
588
|
+
|
589
|
+
payload_list = JSON.parse(CustomerInvoice.to_json_from_list([entity, entity]))
|
590
|
+
payload_list['invoices'].length.should == 2
|
591
|
+
payload_list['invoices'][0]['postTaxTotal'].should == 181.30
|
592
|
+
payload_list['invoices'][0]['orders'][0]['id'].should == 'orderid'
|
593
|
+
end
|
594
|
+
|
595
|
+
end
|
596
|
+
|
597
|
+
end
|