mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-24 05:38:52 +00:00
Add new enterprise customers search API
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user