Skip to content

Commit

Permalink
Merge branch 'MGF-680-un-eleve-de-seconde-ne-peut-pas-postuler-pour-d…
Browse files Browse the repository at this point in the history
…es-offres-de-3-eme-et-inversement' into MGF-561-mise-a-jour-de-la-barre-de-filtre
  • Loading branch information
fitchMitch committed Jan 23, 2025
2 parents 32ead63 + 80875c2 commit e90e1ee
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/controllers/internship_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ def alternative_internship_offers
priority_offers = Finders::InternshipOfferConsumer.new(
params: params.permit(*priority),
user: current_user_or_visitor
).all_with_grade(current_user_or_visitor).to_a
).all.with_grade(current_user_or_visitor).to_a

if priority_offers.count < 5 && priority == %i[latitude longitude radius]
priority_offers = Finders::InternshipOfferConsumer.new(
params: params.permit(*priority).merge(radius: Nearbyable::DEFAULT_NEARBY_RADIUS_IN_METER + 40_000),
user: current_user_or_visitor
).all_with_grade(current_user_or_visitor).to_a
).all.with_grade(current_user_or_visitor).to_a
end

alternative_offers << priority_offers
Expand Down
1 change: 0 additions & 1 deletion app/libs/finders/context_typable_internship_offer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ContextTypableInternshipOffer
:previous_from,
:all,
:all_without_page,
:all_with_grade,
to: :listable_query_builder

def base_query
Expand Down
8 changes: 0 additions & 8 deletions app/libs/finders/listable_internship_offer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ def all_without_page
finder.base_query_without_page
end

def all_with_grade(user)
if user.present? && user.student? && user.grade.present?
finder.base_query.with_grade(student.grade)
else
finder.base_query
end
end

private

attr_reader :finder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ShowClassRoomsTest < ActionDispatch::IntegrationTest

get dashboard_school_class_room_students_path(school, class_room)
assert_response :success
assert_select 'li a[href=?]', dashboard_school_class_rooms_path(school), count: 2
assert_select 'li a[href=?]', dashboard_school_class_rooms_path(school), count: 1
assert_select 'li a[href=?]', dashboard_school_users_path(school), count: 1
assert_select 'li a[href=?]', dashboard_internship_agreements_path, count: 1
assert_select 'li a[href=?]', dashboard_school_information_path(school), count: 1
Expand Down
12 changes: 6 additions & 6 deletions test/controllers/internship_offers/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def create_offers

school = create(:school)
class_room = create(:class_room, school:)
student = create(:student, school:, class_room:)
student = create(:student, :seconde, school:, class_room:)
internship_offer_with_application = create(
:weekly_internship_offer_2nde,
max_candidates: 2,
Expand Down Expand Up @@ -243,10 +243,10 @@ def create_offers

test 'GET #index as student. ignores internship offers not published' do
travel_to(Date.new(2024, 3, 1)) do
api_internship_offer = create(:api_internship_offer_2nde)
api_internship_offer = create(:api_internship_offer_3eme)
internship_offer_published = create(:weekly_internship_offer_3eme)
internship_offer_unpublished = create(:weekly_internship_offer_3eme, :unpublished)
student = create(:student)
student = create(:student, :troisieme)
sign_in(student)
InternshipOffer.stub :nearby, InternshipOffer.all do
InternshipOffer.stub :by_weeks, InternshipOffer.all do
Expand Down Expand Up @@ -345,7 +345,7 @@ def create_offers
# Api offers are ordered by creation date, so we can't test pagination with cities
travel_to(Date.new(2024, 3, 1)) do
# Student school is in Paris
sign_in(create(:student))
sign_in(create(:student, :seconde))
internship_offers = InternshipOffer::PAGE_SIZE.times.map do
create(:api_internship_offer_2nde, coordinates: Coordinates.bordeaux, city: 'Bordeaux')
end
Expand Down Expand Up @@ -417,7 +417,7 @@ def create_offers
travel_to(Date.new(2024, 3, 1)) do
week = Week.find_by(year: 2019, number: 10)
school_at_paris = create(:school, :at_paris)
student = create(:student, school: school_at_paris)
student = create(:student, :seconde, school: school_at_paris)
internship_offer_at_paris = create(:weekly_internship_offer_2nde,
coordinates: Coordinates.paris)
internship_offer_at_bordeaux = create(:weekly_internship_offer_2nde,
Expand All @@ -439,7 +439,7 @@ def create_offers
test 'GET #index as student ignores internship_offer farther than 60 km nearby school coordinates' do
week = Week.find_by(year: 2019, number: 10)
school_at_bordeaux = create(:school, :at_bordeaux)
student = create(:student, school: school_at_bordeaux)
student = create(:student, :troisieme, school: school_at_bordeaux)
create(:weekly_internship_offer_3eme, coordinates: Coordinates.paris)

InternshipOffer.stub :by_weeks, InternshipOffer.all do
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/internship_offers/show_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ShowTest < ActionDispatch::IntegrationTest
current = create(:weekly_internship_offer_2nde, title: 'current')
next_in_page = create(:weekly_internship_offer_2nde, title: 'next')
# next_out = create(:weekly_internship_offer_2nde, title: 'next_out')
student = create(:student, school: create(:school))
student = create(:student, :seconde, school: create(:school))

InternshipOffer.stub :nearby, InternshipOffer.all do
sign_in(student)
Expand All @@ -179,7 +179,7 @@ class ShowTest < ActionDispatch::IntegrationTest
current = create(:weekly_internship_offer_2nde, title: 'current')
next_in_page = create(:weekly_internship_offer_2nde, title: 'next')
next_out = create(:weekly_internship_offer_2nde, title: 'next_out')
student = create(:student, school: create(:school))
student = create(:student, :seconde, school: create(:school))

InternshipOffer.stub :nearby, InternshipOffer.all do
InternshipOffer.stub :by_weeks, InternshipOffer.all do
Expand All @@ -199,7 +199,7 @@ class ShowTest < ActionDispatch::IntegrationTest
previous_out = create(:weekly_internship_offer_2nde, title: 'previous_out')
previous_in_page = create(:weekly_internship_offer_2nde, title: 'previous')
current = create(:weekly_internship_offer_2nde, title: 'current')
student = create(:student, school: create(:school))
student = create(:student, :seconde, school: create(:school))

InternshipOffer.stub :nearby, InternshipOffer.all do
InternshipOffer.stub :by_weeks, InternshipOffer.all do
Expand All @@ -219,7 +219,7 @@ class ShowTest < ActionDispatch::IntegrationTest
previous_in_page = create(:weekly_internship_offer_2nde, title: 'previous')
current = create(:weekly_internship_offer_2nde, title: 'current')
next_in_page = create(:weekly_internship_offer_2nde, title: 'next')
student = create(:student, school: create(:school))
student = create(:student, :seconde, school: create(:school))

InternshipOffer.stub :nearby, InternshipOffer.all do
InternshipOffer.stub :by_weeks, InternshipOffer.all do
Expand Down
10 changes: 5 additions & 5 deletions test/controllers/navbar_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NavbarTest < ActionDispatch::IntegrationTest
class_room: create(:class_room, school: @school))
sign_in(main_teacher)
get main_teacher.custom_dashboard_path
assert_select('li a.fr-link.text-decoration-none.active', count: 1)
assert_select('li a.fr-link.text-decoration-none.active', text: 'Accueil' ,count: 1)
assert_select('li a.fr-link.mr-4', text: 'Accueil', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Ma classe', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Mon profil', count: 1)
Expand All @@ -37,13 +37,12 @@ class NavbarTest < ActionDispatch::IntegrationTest
end

test 'other' do
skip "since no 'other' status anymore"
other = create(:other, school: @school)
create(:class_room, school: @school)
sign_in(other)
get other.custom_dashboard_path

assert_select('#classes-panel a[href=?]',
new_dashboard_school_class_room_path)
assert_select('a.small.fr-raw-link.fr-tag.fr-tag--sm[href=?]',
dashboard_school_class_room_students_path(@school, @school.class_rooms.first))
assert_select('li a.fr-link.text-decoration-none.active', text: 'Mon établissement', count: 1)
Expand All @@ -69,7 +68,7 @@ class NavbarTest < ActionDispatch::IntegrationTest
sign_in(school_manager)
get school_manager.custom_dashboard_path

assert_select('li a.fr-link.text-decoration-none.active', count: 1)
assert_select('li a.fr-link.text-decoration-none.active',text: 'Accueil' , count: 1)
assert_select('li a.fr-link.text-decoration-none.active', text: 'Mon établissement', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Accueil', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Mon établissement', count: 1)
Expand All @@ -96,7 +95,8 @@ class NavbarTest < ActionDispatch::IntegrationTest
class_room: create(:class_room, school: @school))
sign_in(teacher)
get teacher.custom_dashboard_path
assert_select('li a.fr-link.text-decoration-none.active', count: 1)

assert_select('li a.fr-link.text-decoration-none.active', text: 'Accueil' , count: 1)
assert_select('li a.fr-link.text-decoration-none.active', text: 'Ma classe', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Accueil', count: 1)
assert_select('li a.fr-link.mr-4', text: 'Ma classe', count: 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AplicationFlowTest < ApplicationSystemTestCase
test 'first and uniq test before submitting when email was missing' do
school = create(:school, :with_school_manager)
employer, internship_offer = create_employer_and_offer_2nde
student = create(:student, phone: '+2620625852585', school:, email: nil)
student = create(:student, :seconde, phone: '+2620625852585', school:, email: nil)
new_email = '[email protected]'

sign_in(student)
Expand All @@ -32,7 +32,7 @@ class AplicationFlowTest < ApplicationSystemTestCase
employer, internship_offer = create_employer_and_offer_2nde
second_internship_offer = create(:weekly_internship_offer_2nde, employer:)
former_student_email = '[email protected]'
student = create(:student, :registered_with_phone)
student = create(:student, :seconde, :registered_with_phone)
internship_application = create(:weekly_internship_application,
:submitted,
internship_offer:,
Expand All @@ -51,7 +51,7 @@ class AplicationFlowTest < ApplicationSystemTestCase
employer, internship_offer = create_employer_and_offer_2nde
second_internship_offer = create(:weekly_internship_offer_2nde, employer:)
former_student_phone = '+330623055441'
student = create(:student)
student = create(:student, :seconde)
assert_nil student.phone
internship_application = create(:weekly_internship_application,
:submitted,
Expand Down
2 changes: 1 addition & 1 deletion test/system/favorite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SchoolsTest < ApplicationSystemTestCase

test 'can add favorite as a student' do
internship_offer = create(:weekly_internship_offer_2nde)
student = create(:student)
student = create(:student, :seconde)
sign_in student
visit internship_offers_path
# June_flower
Expand Down
6 changes: 3 additions & 3 deletions test/system/internship_offer_index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def assert_absence_of(internship_offer:)

test 'navigation & interaction works' do
school = create(:school)
student = create(:student, school:)
student = create(:student, :seconde, school:)
internship_offer = create(:weekly_internship_offer_2nde)
sign_in(student)
InternshipOffer.stub :nearby, InternshipOffer.all do
Expand All @@ -39,7 +39,7 @@ def assert_absence_of(internship_offer:)
create(:weekly_internship_offer_2nde, city: 'Paris', coordinates: Coordinates.paris, zipcode: '75000')
create(:api_internship_offer, city: 'Paris', coordinates: Coordinates.paris, zipcode: '75000')
end
student = create(:student)
student = create(:student, :seconde)
assert_equal 'Paris', student.school.city
sign_in(student)
visit internship_offers_path
Expand All @@ -61,7 +61,7 @@ def assert_absence_of(internship_offer:)
2.times do
create(:weekly_internship_offer_2nde, city: 'Montmorency', coordinates: Coordinates.montmorency)
end
student = create(:student)
student = create(:student, :seconde)
assert_equal 'Paris', student.school.city
sign_in(student)
visit internship_offers_path(latitude: 48.8589, longitude: 2.347, city: 'paris', radius: 5_000)
Expand Down

0 comments on commit e90e1ee

Please sign in to comment.