mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-05 07:19:14 +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
|
||||
|
||||
@@ -498,7 +498,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "should have the ability to search for users which share management of its enterprises" do
|
||||
should have_ability([:admin, :known_users, :users], for: :search)
|
||||
should have_ability([:admin, :known_users, :customers], for: :search)
|
||||
should_not have_ability([:users], for: :search)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user