Add new enterprise customers search API

This commit is contained in:
Bing Xie
2016-08-31 14:25:30 +10:00
parent fd32152e88
commit bc798504e0
5 changed files with 39 additions and 9 deletions

View File

@@ -31,5 +31,29 @@ describe Spree::Admin::SearchController do
end
end
end
describe 'searching for customers' do
let!(:customer_1) { create(:customer, enterprise: enterprise, email: 'test1@email.com') }
let!(:customer_2) { create(:customer, enterprise: enterprise, name: 'test2') }
let!(:customer_3) { create(:customer, email: 'test3@email.com') }
before do
spree_get :customers, q: "test", distributor_id: enterprise.id
@results = JSON.parse(response.body)
end
describe 'when search query matches the email or name' do
it 'returns a list of customers of the enterprise' do
expect(@results.size).to eq 2
expect(@results.find { |c| c['id'] == customer_1.id}).to be_true
expect(@results.find { |c| c['id'] == customer_2.id}).to be_true
end
it 'does not return the customer of other enterprises' do
expect(@results.find { |c| c['id'] == customer_3.id}).to be_false
end
end
end
end
end