shopifydev 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 785668246d41b9b1d42b825d56301349a927c401
4
- data.tar.gz: aacb6f74df0612dbdad4144a62e14813416ac5f2
3
+ metadata.gz: 24048d7d7f0c6fb857ade82e23a0bab4f8467d9d
4
+ data.tar.gz: 72f5702fadc38edbfcb7071a328fde8967d5db6c
5
5
  SHA512:
6
- metadata.gz: 17abcb331fdd2ef6c990cd2a2bb799270e7c1b4dd63f37b0a7dfda03d9857e2b874a2607796ba8159ff03903a9d76829dd6b4c537f35127a4fb4765dc2f1ecbc
7
- data.tar.gz: a5c99d5fc8680cc352c41564e8e073dcbb31da35bac1d5c37540f2d2489c3265180d9dbba3d21537e792ca3acdde1b463758c4ba7ff73b62243097b01de52b92
6
+ metadata.gz: ced6bc6eeee626d57d3c2afa71471c30992e57fd4acc8fa860a77bd9d5c3b3e8133f061c5d27aa05b0c8820514530ddccbce35b944a019c670973541edd37749
7
+ data.tar.gz: b40e579b8d5e39e46deebac68d4443d6397d4a5b9473ce0efd1b538bf0978bde939160ed2e56d745f451205d3f1bd89ce621af493d9677e394c8bb1441b6ad37
@@ -44,6 +44,7 @@ module Shopifydev
44
44
 
45
45
  if opts[:variant_id]
46
46
  variant = variants.find{|v| v.id.to_s == opts[:variant_id].to_s}
47
+ variant ||= product.variants.sample if product
47
48
  raise "don't know about a variant with id #{opts[:variant_id]}" if variant.nil?
48
49
  end
49
50
  variant ||= products.sample.variants.sample
@@ -73,29 +74,83 @@ module Shopifydev
73
74
  out
74
75
  end
75
76
 
76
- def address_attrs
77
+ def us_address_attrs(opts={})
77
78
  require_relative 'valid_zip'
78
79
  place = ValidZip.valid_place
79
80
  first_name = ::Faker::Name.first_name
80
81
  last_name = ::Faker::Name.last_name
81
- {
82
+ attrs = {
82
83
  first_name: first_name,
83
84
  last_name: last_name,
84
- name: [first_name, last_name].join(' '),
85
85
  address1: ::Faker::AddressUS.street_address,
86
86
  phone: ::Faker::PhoneNumber.phone_number,
87
87
  city: place[:city],
88
88
  province: place[:state],
89
89
  country: "US",
90
90
  zip: place[:zip]
91
- }.deep_merge(@address_defaults)
91
+ }.deep_merge(@address_defaults).deep_merge(opts)
92
+ attrs[:name] ||= [first_name, last_name].join(' ')
93
+ attrs
94
+ end
95
+
96
+ def cad_address_attrs(opts={})
97
+ require_relative 'valid_postal_code'
98
+ place = ValidPostalCode.valid_place
99
+ first_name = ::Faker::Name.first_name
100
+ last_name = ::Faker::Name.last_name
101
+ attrs = {
102
+ first_name: first_name,
103
+ last_name: last_name,
104
+ address1: ::Faker::AddressCA.street_address,
105
+ phone: ::Faker::PhoneNumber.phone_number,
106
+ city: place[:city],
107
+ province: place[:province],
108
+ country: "CA",
109
+ zip: place[:postal_code]
110
+ }.deep_merge(@address_defaults).deep_merge(opts)
111
+ attrs[:name] ||= [first_name, last_name].join(' ')
112
+ attrs
92
113
  end
93
114
 
115
+ def address_attrs(opts=nil)
116
+ case opts
117
+ when 'cad', 'CAD', 'ca', 'CA', :cad
118
+ cad_address_opts(opts)
119
+ when 'us', 'US', :us
120
+ cad_address_opts(opts)
121
+ when Hash
122
+ country = opts[:country]
123
+ case country.downcase
124
+ when 'ca', 'cad', 'canada'
125
+ cad_address_attrs(opts)
126
+ when 'us', 'united states'
127
+ us_address_attrs(opts)
128
+ else
129
+ [cad_address_attrs(opts), us_address_attrs(opts)].sample
130
+ end
131
+ else
132
+ [cad_address_attrs, us_address_attrs].sample
133
+ end
134
+ end
135
+
94
136
  def order_attrs(opts={})
137
+ address = opts.delete(:address)
138
+ address = address_attrs(address) if address
139
+ billing_address = opts.delete(:billing_address)
140
+ billing_address = address_attrs(billing_address) if billing_address
141
+ billing_address ||= address
142
+ billing_address ||= address_attrs
143
+
144
+ shipping_address = opts.delete(:shipping_address)
145
+ shipping_address = address_attrs(shipping_address) if shipping_address
146
+ shipping_address ||= address
147
+ shipping_address ||= address_attrs
148
+
149
+ opts.delete(:address)
95
150
  {
96
151
  line_items: line_items_attrs(opts),
97
- billing_address: address_attrs,
98
- shipping_address: address_attrs,
152
+ billing_address: billing_address,
153
+ shipping_address: shipping_address,
99
154
  financial_status: 'paid',
100
155
  email: ::Faker::Internet.email
101
156
  }.deep_merge(@order_defaults).deep_merge(opts)