Skip to content

Commit

Permalink
Display addresses from countries supported in the current store
Browse files Browse the repository at this point in the history
  • Loading branch information
v10110 committed Aug 20, 2021
1 parent c48e1ac commit ba24aae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -4,6 +4,8 @@ module V2
module Storefront
module Account
class AddressesController < ::Spree::Api::V2::ResourceController
include Spree::BaseHelper

before_action :require_spree_current_user

def create
Expand Down Expand Up @@ -37,7 +39,7 @@ def collection
end

def scope
super.where(user: spree_current_user).not_deleted
super.where(user: spree_current_user, country: available_countries).not_deleted
end

def model_class
Expand Down
Expand Up @@ -67,6 +67,23 @@
end
end

context 'when address from countries that are supported in the current store' do
let!(:country) { create(:country, name: 'France') }
let!(:zone) { create(:zone, name: 'EU_VAT', countries: [country], kind: 'country') }
let!(:eu_address) { create(:address, user_id: user.id, country: country) }

before do
Spree::Config[:checkout_zone] = zone.name
get '/api/v2/storefront/account/addresses', headers: headers_bearer
end

it 'should return addresses from supported countries' do
expect(user.addresses.size).to eq 4
expect(json_response['data'].size).to eq 1
expect(json_response['data'][0]).to have_attribute(:country_name).with_value(eu_address.country.name)
end
end

context 'when address without user exists' do
let!(:address) { create(:address, user_id: nil) }

Expand Down

0 comments on commit ba24aae

Please sign in to comment.