VRFS-3036 band search filter tests
This commit is contained in:
parent
9757712977
commit
f66cf79cf2
|
|
@ -7,9 +7,9 @@ module JamRuby
|
|||
serialize :data_blob, JSON
|
||||
|
||||
KEY_BAND_SEARCH_TYPE = 'band_search_type'
|
||||
KEY_BAND_TYPE = 'band_type'
|
||||
KEY_BAND_STATUS = 'band_status'
|
||||
KEY_PLAY_COMMIT = 'play_commitment'
|
||||
KEY_TOUR_OPTION = 'tour_option'
|
||||
KEY_TOUR_OPTION = 'touring_option'
|
||||
KEY_PERF_SAMPLES = 'perform_samples'
|
||||
KEY_HIRE_MAX_COST = 'max_cost'
|
||||
KEY_HIRE_FREE = 'free_gigs'
|
||||
|
|
@ -23,6 +23,8 @@ module JamRuby
|
|||
TO_HIRE => 'search bands to hire',
|
||||
}
|
||||
|
||||
SKILL_VAL_STRS = [ANY_VAL_STR, 'amateur', 'professional']
|
||||
|
||||
SORT_VALS = %W{ distance latency }
|
||||
SORT_ORDERS = {
|
||||
SORT_VALS[0] => 'Distance to Me',
|
||||
|
|
@ -36,14 +38,14 @@ module JamRuby
|
|||
HIRE_SORT_VALS[2] => 'Gig Minimum Price (High to Low)',
|
||||
}
|
||||
|
||||
BAND_TYPE_VALS = [ANY_VAL_STR,
|
||||
BAND_STATUS_VALS = [ANY_VAL_STR,
|
||||
GenrePlayer::VIRTUAL_BAND,
|
||||
GenrePlayer::TRADITIONAL_BAND,
|
||||
]
|
||||
BAND_TYPES = {
|
||||
BAND_TYPE_VALS[0] => 'Any',
|
||||
BAND_TYPE_VALS[1] => 'Virtual Band',
|
||||
BAND_TYPE_VALS[2] => 'Traditional Band',
|
||||
BAND_STATUSS = {
|
||||
BAND_STATUS_VALS[0] => 'Any',
|
||||
BAND_STATUS_VALS[1] => 'Virtual Band',
|
||||
BAND_STATUS_VALS[2] => 'Traditional Band',
|
||||
}
|
||||
|
||||
PLAY_COMMIT_VALS = [ANY_VAL_STR,
|
||||
|
|
@ -77,14 +79,15 @@ module JamRuby
|
|||
return @@jschema if @@jschema
|
||||
@@jschema = {
|
||||
TO_JOIN => BaseSearch.json_schema.merge({
|
||||
KEY_BAND_TYPE => BAND_TYPE_VALS[0],
|
||||
KEY_SKILL => self::SKILL_VAL_STRS[0].to_s,
|
||||
KEY_BAND_STATUS => BAND_STATUS_VALS[0],
|
||||
KEY_PLAY_COMMIT => PLAY_COMMIT_VALS[0],
|
||||
KEY_TOUR_OPTION => TOUR_OPTION_VALS[0],
|
||||
}),
|
||||
TO_HIRE => {
|
||||
KEY_SORT_ORDER => self::HIRE_SORT_VALS[0],
|
||||
KEY_GENRES => [],
|
||||
KEY_SKILL => self::SKILL_VALS[0].to_s,
|
||||
KEY_SKILL => self::SKILL_VAL_STRS[0].to_s,
|
||||
KEY_GIGS => self::GIG_COUNTS[0].to_s,
|
||||
KEY_PERF_SAMPLES => self::PERF_SAMPLES[0].to_s,
|
||||
KEY_HIRE_MAX_COST => 0,
|
||||
|
|
@ -97,7 +100,7 @@ module JamRuby
|
|||
return @@search_meta if @@search_meta
|
||||
toJoinMeta = super(self.json_schema[TO_JOIN])
|
||||
toJoinMeta.merge!({
|
||||
KEY_BAND_TYPE => { keys: BAND_TYPE_VALS, map: BAND_TYPES },
|
||||
KEY_BAND_STATUS => { keys: BAND_STATUS_VALS, map: BAND_STATUSS },
|
||||
KEY_PLAY_COMMIT => { keys: PLAY_COMMIT_VALS, map: PLAY_COMMITS },
|
||||
KEY_TOUR_OPTION => { keys: TOUR_OPTION_VALS, map: TOUR_OPTIONS }
|
||||
})
|
||||
|
|
@ -130,12 +133,12 @@ module JamRuby
|
|||
rel
|
||||
end
|
||||
|
||||
def _band_type(rel, filter)
|
||||
case filter[KEY_BAND_TYPE]
|
||||
def _band_status(rel, filter)
|
||||
case filter[KEY_BAND_STATUS]
|
||||
when GenrePlayer::VIRTUAL_BAND
|
||||
rel.where(band_type: GenrePlayer::VIRTUAL_BAND)
|
||||
rel.where(band_status: GenrePlayer::VIRTUAL_BAND.sub('_band',''))
|
||||
when GenrePlayer::TRADITIONAL_BAND
|
||||
rel.where(band_type: GenrePlayer::TRADITIONAL_BAND)
|
||||
rel.where(band_status: GenrePlayer::TRADITIONAL_BAND.sub('_band',''))
|
||||
else
|
||||
rel
|
||||
end
|
||||
|
|
@ -148,7 +151,7 @@ module JamRuby
|
|||
rel
|
||||
end
|
||||
|
||||
def _tour_option(rel, filter)
|
||||
def _touring_option(rel, filter)
|
||||
case filter[KEY_TOUR_OPTION]
|
||||
when VAL_YES
|
||||
rel.where(touring_option: true)
|
||||
|
|
@ -183,11 +186,11 @@ module JamRuby
|
|||
end
|
||||
|
||||
def _skill_level(rel, filter)
|
||||
case filter[KEY_SKILL].to_i
|
||||
when SKILL_VALS[1]
|
||||
rel.where(free_gigs: true)
|
||||
when SKILL_VALS[2]
|
||||
rel.where(paid_gigs: true)
|
||||
case filter[KEY_SKILL]
|
||||
when SKILL_VAL_STRS[1]
|
||||
rel.where(band_type: SKILL_VAL_STRS[1])
|
||||
when SKILL_VAL_STRS[2]
|
||||
rel.where(band_type: SKILL_VAL_STRS[2])
|
||||
else
|
||||
rel
|
||||
end
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ module JamRuby
|
|||
"instrument_id = '#{inst['instrument_id']}' AND proficiency_level = #{inst['proficiency_level']}"
|
||||
end.join(") OR (")
|
||||
instsql += "))"
|
||||
rel = rel.where("#{self.class.search_target_class.table_name}users.id IN (#{instsql})")
|
||||
rel = rel.where("#{self.class.search_target_class.table_name}.id IN (#{instsql})")
|
||||
end
|
||||
rel
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ module JamRuby
|
|||
|
||||
def _skills(rel)
|
||||
if 0 < (val = json[KEY_SKILL].to_i)
|
||||
rel = rel.where(['skill_level = ?', val])
|
||||
rel = rel.where(skill_level: val)
|
||||
end
|
||||
rel
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,42 +54,93 @@ describe 'Band Search Model' do
|
|||
|
||||
let!(:band) { Band.first }
|
||||
|
||||
it "filters by genre" do
|
||||
filter = to_join
|
||||
band_id = band.id
|
||||
filter[BandSearch::KEY_GENRES] = [band_id]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(Band.all.map(&:genres).flatten.select { |bb| bb.id == band_id }.count)
|
||||
context 'all search keys' do
|
||||
it "filters by gigs" do
|
||||
filter = to_join
|
||||
band.update_attribute(:concert_count, BandSearch::GIG_COUNTS[2])
|
||||
filter[BandSearch::KEY_GIGS] = BandSearch::GIG_COUNTS[2]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
it "filters by genre" do
|
||||
filter = to_join
|
||||
band_id = band.id
|
||||
filter[BandSearch::KEY_GENRES] = [band_id]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(Band.all.map(&:genres).flatten.select { |bb| bb.id == band_id }.count)
|
||||
end
|
||||
|
||||
it "filters by skill level" do
|
||||
filter = to_join
|
||||
band.update_attribute(:band_type, BandSearch::SKILL_VAL_STRS[1])
|
||||
filter[BandSearch::KEY_SKILL] = BandSearch::SKILL_VAL_STRS[1]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
it "filters by instruments" do
|
||||
filter = to_join
|
||||
minst = FactoryGirl.create(:musician_instrument)
|
||||
band.musician_instruments << minst
|
||||
band.save
|
||||
filter[BandSearch::KEY_INSTRUMENTS] = [{'instrument_id' => minst.instrument_id,
|
||||
'proficiency_level' => minst.proficiency_level
|
||||
}]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "filters by free gigs" do
|
||||
filter = to_join
|
||||
band.update_attribute(BandSearch::KEY_HIRE_FREE, true)
|
||||
filter[BandSearch::KEY_HIRE_FREE] = BandSearch::VAL_YES
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
context 'to_join' do
|
||||
|
||||
let!(:filter) { to_join }
|
||||
|
||||
it "filters by play commitment" do
|
||||
band.update_attribute(BandSearch::KEY_PLAY_COMMIT, BandSearch::PLAY_COMMIT_VALS[1].to_i)
|
||||
filter[BandSearch::KEY_PLAY_COMMIT] = BandSearch::PLAY_COMMIT_VALS[1]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
it "filters by tour option" do
|
||||
band.update_attribute(BandSearch::KEY_TOUR_OPTION, true)
|
||||
filter[BandSearch::KEY_TOUR_OPTION] = BandSearch::VAL_YES
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "filters by max cost" do
|
||||
filter = to_join
|
||||
band.update_attribute(:gig_minimum, 10)
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 5
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(0)
|
||||
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 15
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
end
|
||||
context 'to_hire' do
|
||||
|
||||
let!(:filter) { to_hire }
|
||||
|
||||
it "filters by free gigs" do
|
||||
band.update_attribute(BandSearch::KEY_HIRE_FREE, true)
|
||||
filter[BandSearch::KEY_HIRE_FREE] = BandSearch::VAL_YES
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
it "filters by max cost" do
|
||||
band.update_attribute(:gig_minimum, 10)
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 5
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(0)
|
||||
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 15
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
end
|
||||
|
||||
it "filters by play commitment" do
|
||||
filter = to_join
|
||||
band.update_attribute(BandSearch::KEY_PLAY_COMMIT, BandSearch::PLAY_COMMIT_VALS[1].to_i)
|
||||
filter[BandSearch::KEY_PLAY_COMMIT] = BandSearch::PLAY_COMMIT_VALS[1]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue