4
4
5
5
module Spree ::Api
6
6
describe 'Stores' , type : :request do
7
+ let ( :country ) { create :country , states_required : true }
8
+ let ( :country_without_states ) { create :country , states_required : false }
9
+ let ( :state ) { create :state , name : 'maryland' , abbr : 'md' , country : }
10
+ let! ( :base_attributes ) { Spree ::Api ::Config . store_attributes }
11
+
7
12
let! ( :store ) do
8
13
create ( :store , name : "My Spree Store" , url : "spreestore.example.com" )
9
14
end
@@ -22,6 +27,58 @@ module Spree::Api
22
27
default : false )
23
28
end
24
29
30
+ describe "store state validation" do
31
+ context "when store country has states_required" do
32
+ it "is invalid without a state" do
33
+ store = Spree ::Store . new ( name : "Test Store" , country : country , state : nil , url : "spreestore.example.com" ,
34
+ mail_from_address :
"[email protected] " , code :
"test-store" , )
35
+ expect ( store ) . not_to be_valid
36
+ expect ( store . errors [ :state ] ) . to include ( "can't be blank" )
37
+ end
38
+
39
+ it "is valid with a state" do
40
+ store = Spree ::Store . new ( name : "Test Store" , country : country , state : state , url : "spreestore.example.com" ,
41
+ mail_from_address :
"[email protected] " , code :
"test-store" , )
42
+ expect ( store ) . to be_valid
43
+ end
44
+ end
45
+
46
+ context "when store country has no states" do
47
+ it "is valid without a state" do
48
+ store = Spree ::Store . new ( name : "Test Store" , country : country_without_states , state : nil , url : "spreestore.example.com" ,
49
+ mail_from_address :
"[email protected] " , code :
"test-store" , )
50
+ expect ( store ) . to be_valid
51
+ end
52
+ end
53
+
54
+ it "is valid without an address and without country/state" do
55
+ expect ( store ) . to be_valid
56
+ end
57
+
58
+ it "is valid with only correct country and state" do
59
+ store = Spree ::Store . create! (
60
+ name : "Test Store" ,
61
+ url : "spreestore.example.com" ,
62
+ mail_from_address : "spreestore.example.com" ,
63
+ code : "test-store" ,
64
+ address1 : "123 Main St" ,
65
+ city : "New York" ,
66
+ zipcode : "10001" ,
67
+ state : state ,
68
+ country : country ,
69
+ )
70
+ expect ( store ) . to be_valid
71
+ end
72
+ end
73
+
74
+ describe "#index" do
75
+ it "ensures the API store attributes match the expected attributes" do
76
+ get spree . api_stores_path
77
+ first_store = json_response [ "stores" ] . first
78
+ expect ( first_store . keys ) . to include ( *base_attributes . map ( &:to_s ) )
79
+ end
80
+ end
81
+
25
82
it "can list the available stores" do
26
83
get spree . api_stores_path
27
84
expect ( json_response [ "stores" ] ) . to match_array ( [
@@ -37,7 +94,20 @@ module Spree::Api
37
94
"default_currency" => nil ,
38
95
"code" => store . code ,
39
96
"default" => true ,
40
- "available_locales" => [ "en" ]
97
+ "available_locales" => [ "en" ] ,
98
+ "legal_name" => nil ,
99
+ "contact_email" => nil ,
100
+ "contact_phone" => nil ,
101
+ "description" => nil ,
102
+ "tax_id" => nil ,
103
+ "vat_id" => nil ,
104
+ "address1" => nil ,
105
+ "address2" => nil ,
106
+ "city" => nil ,
107
+ "zipcode" => nil ,
108
+ "country_id" => nil ,
109
+ "state_id" => nil ,
110
+ "state_name" => nil
41
111
} ,
42
112
{
43
113
"id" => non_default_store . id ,
@@ -51,7 +121,20 @@ module Spree::Api
51
121
"default_currency" => nil ,
52
122
"code" => non_default_store . code ,
53
123
"default" => false ,
54
- "available_locales" => [ "en" ]
124
+ "available_locales" => [ "en" ] ,
125
+ "legal_name" => nil ,
126
+ "contact_email" => nil ,
127
+ "contact_phone" => nil ,
128
+ "description" => nil ,
129
+ "tax_id" => nil ,
130
+ "vat_id" => nil ,
131
+ "address1" => nil ,
132
+ "address2" => nil ,
133
+ "city" => nil ,
134
+ "zipcode" => nil ,
135
+ "country_id" => nil ,
136
+ "state_id" => nil ,
137
+ "state_name" => nil
55
138
}
56
139
] )
57
140
end
@@ -70,7 +153,20 @@ module Spree::Api
70
153
"default_currency" => nil ,
71
154
"code" => store . code ,
72
155
"default" => true ,
73
- "available_locales" => [ "en" ]
156
+ "available_locales" => [ "en" ] ,
157
+ "legal_name" => nil ,
158
+ "contact_email" => nil ,
159
+ "contact_phone" => nil ,
160
+ "description" => nil ,
161
+ "tax_id" => nil ,
162
+ "vat_id" => nil ,
163
+ "address1" => nil ,
164
+ "address2" => nil ,
165
+ "city" => nil ,
166
+ "zipcode" => nil ,
167
+ "country_id" => nil ,
168
+ "state_id" => nil ,
169
+ "state_name" => nil
74
170
)
75
171
end
76
172
@@ -79,7 +175,14 @@ module Spree::Api
79
175
code : "spree123" ,
80
176
name : "Hack0rz" ,
81
177
url : "spree123.example.com" ,
82
- mail_from_address :
"[email protected] "
178
+ mail_from_address :
"[email protected] " ,
179
+ legal_name : 'ABC Corp' ,
180
+ address1 : "123 Main St" ,
181
+ city : 'San Francisco' ,
182
+ country_id : country . id ,
183
+ state_id : state . id ,
184
+ phone : "123-456-7890" ,
185
+ zipcode : "12345"
83
186
}
84
187
post spree . api_stores_path , params : { store : store_hash }
85
188
expect ( response . status ) . to eq ( 201 )
@@ -89,13 +192,34 @@ module Spree::Api
89
192
store_hash = {
90
193
url : "spree123.example.com" ,
91
194
mail_from_address :
"[email protected] " ,
92
-
195
+
196
+ legal_name : 'XYZ Corp' ,
197
+ description : "Leading provider of high-quality tech accessories, offering the latest gadgets, peripherals, and electronics to enhance your digital lifestyle." ,
198
+ tax_id : "TX-987654321" ,
199
+ vat_id : "VAT-123456789" ,
200
+ address1 : "123 Innovation Drive" ,
201
+ address2 : "Suite 456" ,
202
+ city : "New York" ,
203
+ country_id : country . id ,
204
+ state_id : state . id ,
205
+ contact_phone : "123-456-7888" ,
206
+ zipcode : "10001"
93
207
}
94
208
put spree . api_store_path ( store ) , params : { store : store_hash }
95
209
expect ( response . status ) . to eq ( 200 )
96
210
expect ( store . reload . url ) . to eql "spree123.example.com"
97
211
expect ( store . reload . mail_from_address ) . to eql "[email protected] "
98
212
expect ( store . reload . bcc_email ) . to eql "[email protected] "
213
+ expect ( store . reload . legal_name ) . to eql "XYZ Corp"
214
+ expect ( store . reload . tax_id ) . to eql "TX-987654321"
215
+ expect ( store . reload . vat_id ) . to eql "VAT-123456789"
216
+ expect ( store . reload . address1 ) . to eql "123 Innovation Drive"
217
+ expect ( store . reload . address2 ) . to eql "Suite 456"
218
+ expect ( store . reload . city ) . to eql "New York"
219
+ expect ( store . reload . country_id ) . to eql country . id
220
+ expect ( store . reload . state_id ) . to eql state . id
221
+ expect ( store . reload . contact_phone ) . to eql "123-456-7888"
222
+ expect ( store . reload . zipcode ) . to eql "10001"
99
223
end
100
224
101
225
context "deleting a store" do
0 commit comments