diff --git a/Gemfile.lock b/Gemfile.lock index 7bc762f5d2d38bf20f70172f112b20353a54a7f3..c3bd4d1f7a42ce219d896052fbaac53ae33ffc30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,9 +9,9 @@ GIT GIT remote: https://github.com/noesya/two_factor_authentication.git - revision: 4574ece65da41397dd852001e22a0c3b9ee3d01e + revision: 852a0ea0b1c755fdf52a423aea0538e7013773b1 specs: - two_factor_authentication (4.0.0) + two_factor_authentication (4.1.0) devise encryptor rails (>= 3.1.1) @@ -103,7 +103,7 @@ GEM autoprefixer-rails (10.4.7.0) execjs (~> 2) aws-eventstream (1.2.0) - aws-partitions (1.688.0) + aws-partitions (1.689.0) aws-sdk-core (3.168.4) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.651.0) @@ -187,7 +187,7 @@ GEM ethon (0.16.0) ffi (>= 1.15.0) execjs (2.8.1) - faceted_search (3.5.16) + faceted_search (3.6.0) font-awesome-sass rails (>= 5.2.0) faraday (2.7.2) @@ -456,7 +456,7 @@ GEM snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) - spring (4.1.0) + spring (4.1.1) sprockets (4.2.0) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) diff --git a/app/models/university/with_identifier.rb b/app/models/university/with_identifier.rb index 1e7815b69b4d3f25356d8101dfb5ed53141a0515..32133d44f8743770c75eaf4e8521e068606ef87a 100644 --- a/app/models/university/with_identifier.rb +++ b/app/models/university/with_identifier.rb @@ -35,6 +35,10 @@ module University::WithIdentifier ENV['OSUNY_STAGING'] || '.osuny.dev' end + def self.test_domain + ENV['OSUNY_TEST'] || '.osuny.test' + end + def self.development_domain ENV['OSUNY_DEV'] || '.osuny' end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/test/controllers/extranet/academic_years_controller_test.rb b/test/controllers/extranet/academic_years_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..f4b820116447d53bb1a019315143d3bc0b6cb0e6 --- /dev/null +++ b/test/controllers/extranet/academic_years_controller_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class Extranet::AcademicYearsControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_index + get education_academic_years_path + assert_response(:success) + end + + def test_show + get education_academic_year_path(education_academic_years(:twenty_two)) + assert_response(:success) + end +end diff --git a/test/controllers/extranet/account_controller_test.rb b/test/controllers/extranet/account_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..058100d742c8be09e59726de228462d0a0beaae2 --- /dev/null +++ b/test/controllers/extranet/account_controller_test.rb @@ -0,0 +1,27 @@ +require "test_helper" + +class Extranet::AccountControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_show + get account_path + assert_response(:success) + end + + def test_edit + get edit_account_path + assert_response(:success) + end + + def test_update + assert_equal("Alumnus", alumnus.first_name) + patch account_path, params: { user: { first_name: "New Alumnus" } } + assert_redirected_to(account_path) + assert_equal("New Alumnus", alumnus.first_name) + end + + def test_update_password + patch account_path, params: { user: { password: "NewPassw0rd!" } } + assert_redirected_to(account_path) + end +end diff --git a/test/controllers/extranet/cohorts_controller_test.rb b/test/controllers/extranet/cohorts_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..f925d1782d23748fa6b6020908755153d2a9ae4e --- /dev/null +++ b/test/controllers/extranet/cohorts_controller_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class Extranet::CohortsControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_index + get education_cohorts_path + assert_response(:success) + end + + def test_show + get education_cohort_path(education_cohorts(:default_cohort)) + assert_response(:success) + end +end diff --git a/test/controllers/extranet/experiences_controller_test.rb b/test/controllers/extranet/experiences_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..a46eed81b602b6568defc4d0c932d42e116ba143 --- /dev/null +++ b/test/controllers/extranet/experiences_controller_test.rb @@ -0,0 +1,67 @@ +require "test_helper" + +class Extranet::ExperiencesControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_new + get new_experience_path + assert_response(:success) + end + + def test_create + assert_difference("alumnus.experiences.count") do + post experiences_path, params: { + university_person_experience: { + description: "Stage", + from_year: 2022, + to_year: 2022, + organization_id: university_organizations(:default_organization).id + } + } + assert_redirected_to(account_path) + end + end + + def test_create_invalid + assert_no_difference("alumnus.experiences.count") do + post experiences_path, params: { + university_person_experience: { + description: "Stage", + from_year: 2022, + to_year: 2022 + } + } + assert_response(:success) + end + end + + def test_edit + get edit_experience_path(university_person_experiences(:default_experience)) + assert_response(:success) + end + + def test_update + experience = university_person_experiences(:default_experience) + + assert(experience.description.blank?) + patch experience_path(experience), params: { + university_person_experience: { + description: "Alternance" + } + } + assert_redirected_to(account_path) + assert_equal("Alternance", experience.reload.description) + end + + def test_update_invalid + experience = university_person_experiences(:default_experience) + + patch experience_path(experience), params: { + university_person_experience: { + organization_id: "" + } + } + assert_response(:success) + end + +end diff --git a/test/controllers/extranet/home_controller_test.rb b/test/controllers/extranet/home_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..4d0456ec3316500ff4e40d45ecfed9690e6f0fe1 --- /dev/null +++ b/test/controllers/extranet/home_controller_test.rb @@ -0,0 +1,21 @@ +require "test_helper" + +class Extranet::HomeControllerTest < ActionDispatch::IntegrationTest + def test_index_unknown_context + get(root_path) + assert_response(:forbidden) + end + + def test_index_unauthenticated + host! "extranet.osuny.test" + get(root_path) + assert_redirected_to(new_user_session_path) + end + + def test_index + host! "extranet.osuny.test" + sign_in_with_2fa(alumnus) + get(root_path) + assert_response(:success) + end +end diff --git a/test/controllers/extranet/organizations_controller_test.rb b/test/controllers/extranet/organizations_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..5e3edacefa33e6b2a66bae06b287bad50dad458b --- /dev/null +++ b/test/controllers/extranet/organizations_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class Extranet::OrganizationsControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_index + get university_organizations_path + assert_response(:success) + end + + def test_search + get search_university_organizations_path(term: "Organisation de test") + assert_response(:success) + results = JSON.parse(response.body) + assert_equal(1, results.size) + assert_equal("Organisation de test", results.first["label"]) + end + + def test_show + get university_organization_path(university_organizations(:default_organization)) + assert_response(:success) + end +end diff --git a/test/controllers/extranet/pages_controller_test.rb b/test/controllers/extranet/pages_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..54c8e76d31aa3ecc66d7f763b0121e6511554efa --- /dev/null +++ b/test/controllers/extranet/pages_controller_test.rb @@ -0,0 +1,25 @@ +require "test_helper" + +class Extranet::PagesControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_terms + get terms_path + assert_response(:success) + end + + def test_cookies_policy + get cookies_policy_path + assert_response(:success) + end + + def test_privacy_policy + get privacy_policy_path + assert_response(:success) + end + + def test_data + get data_path + assert_response(:success) + end +end diff --git a/test/controllers/extranet/personal_data_controller_test.rb b/test/controllers/extranet/personal_data_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..493849e3cc7a0127d6177cca7c147786e65f9c68 --- /dev/null +++ b/test/controllers/extranet/personal_data_controller_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +class Extranet::PersonalDataControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_edit + get edit_personal_data_path + assert_response(:success) + end + + def test_update + assert(alumnus_person.biography.blank?) + patch personal_data_path, params: { university_person: { biography: "<p>Je suis un ancien étudiant.</p>" } } + assert_redirected_to(account_path) + assert(alumnus_person.reload.biography.to_s.include?("Je suis un ancien étudiant.")) + end +end diff --git a/test/controllers/extranet/persons_controller_test.rb b/test/controllers/extranet/persons_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..1b4d10523048015f6f3f1f3d6abcdcf8f7c227d4 --- /dev/null +++ b/test/controllers/extranet/persons_controller_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class Extranet::PersonsControllerTest < ActionDispatch::IntegrationTest + include ExtranetSetup + + def test_index + get university_persons_path + assert_response(:success) + end + + def test_show + get university_person_path(university_people(:alumnus)) + assert_response(:success) + end +end diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml index fa530b05dc39e3bba0a50ce627f0bc81732644ee..c11ef9e9fbf6dbb1fcb38a1d4f7106c7ca2c0d8b 100644 --- a/test/fixtures/communication/extranets.yml +++ b/test/fixtures/communication/extranets.yml @@ -33,12 +33,8 @@ # fk_rails_c2268c7ebd (university_id => universities.id) # -one: - name: MyString - university: default_university - host: MyString - -two: - name: MyString - university: default_university - host: MyString +default_extranet: + name: Extranet de test + host: extranet.osuny.test + about: default_program (Education::Program) + university: default_university \ No newline at end of file diff --git a/test/fixtures/education/academic_years.yml b/test/fixtures/education/academic_years.yml index ede802b5266f17befabe1b26fffb7af3fb9d08bf..569a5d2a15640f8f57b39d42e0f039f4bfa7c53f 100644 --- a/test/fixtures/education/academic_years.yml +++ b/test/fixtures/education/academic_years.yml @@ -17,10 +17,10 @@ # fk_rails_7d376afe35 (university_id => universities.id) # -one: +twenty_two: university: default_university year: 2022 -two: +twenty_three: university: default_university year: 2023 diff --git a/test/fixtures/education/cohorts.yml b/test/fixtures/education/cohorts.yml index 9299e067deb71190564efb9f5b0f2d3db370e8c4..7e9d752e8762e39a1ea0717787f8d49c454d6e3a 100644 --- a/test/fixtures/education/cohorts.yml +++ b/test/fixtures/education/cohorts.yml @@ -26,16 +26,9 @@ # fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) # -one: +default_cohort: + name: Formation de test 2022 university: default_university school: default_school - program: one - academic_year: one - name: MyString - -two: - university: default_university - school: default_school - program: two - academic_year: two - name: MyString + program: default_program + academic_year: twenty_two diff --git a/test/fixtures/education/diplomas.yml b/test/fixtures/education/diplomas.yml index 03ebcb6c3c2b335da001641ef79b055312b49ed7..9c46a831c5b29066e9e054d15b6adddd093f8e0e 100644 --- a/test/fixtures/education/diplomas.yml +++ b/test/fixtures/education/diplomas.yml @@ -23,16 +23,7 @@ # fk_rails_6cb2e9fa90 (university_id => universities.id) # -one: +default_diploma: + name: Diplôme de test + short_name: DT university: default_university - name: MyString - short_name: MyString - level: 1 - slug: MyString - -two: - university: default_university - name: MyString - short_name: MyString - level: 1 - slug: MyString diff --git a/test/fixtures/education/programs.yml b/test/fixtures/education/programs.yml new file mode 100644 index 0000000000000000000000000000000000000000..d44de7e29daf5df3a813dcfc4860679c778d51de --- /dev/null +++ b/test/fixtures/education/programs.yml @@ -0,0 +1,59 @@ +# == Schema Information +# +# Table name: education_programs +# +# id :uuid not null, primary key +# accessibility :text +# apprenticeship :boolean +# capacity :integer +# contacts :text +# content :text +# continuing :boolean +# description :text +# description_short :text +# duration :text +# evaluation :text +# featured_image_alt :string +# featured_image_credit :text +# initial :boolean +# name :string +# objectives :text +# opportunities :text +# other :text +# path :string +# pedagogy :text +# position :integer default(0) +# prerequisites :text +# presentation :text +# pricing :text +# published :boolean default(FALSE) +# registration :text +# registration_url :string +# results :text +# short_name :string +# slug :string +# created_at :datetime not null +# updated_at :datetime not null +# diploma_id :uuid indexed +# parent_id :uuid indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_education_programs_on_diploma_id (diploma_id) +# index_education_programs_on_parent_id (parent_id) +# index_education_programs_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_08b351087c (university_id => universities.id) +# fk_rails_ec1f16f607 (parent_id => education_programs.id) +# + +default_program: + name: Formation de test + published: true + diploma: default_diploma + schools: + - default_school + university: default_university diff --git a/test/fixtures/education/schools.yml b/test/fixtures/education/schools.yml index c8a131ca199b79365c37ff32222a464da85f073b..e0f957684160759345546501322ce012c2156cb4 100644 --- a/test/fixtures/education/schools.yml +++ b/test/fixtures/education/schools.yml @@ -25,4 +25,8 @@ # default_school: name: École de test - university: default_university + address: 1 Rue Jacques Ellul + zipcode: 33080 + city: Bordeaux + country: FR + university: default_university \ No newline at end of file diff --git a/test/fixtures/universities.yml b/test/fixtures/universities.yml index e51e10e50f4ca8868060a634b4aaa7e0562acc38..e5a7e044a4fd7d76f0288ae1b6e004fe3fec68fb 100644 --- a/test/fixtures/universities.yml +++ b/test/fixtures/universities.yml @@ -28,3 +28,4 @@ # default_university: name: Université de test + identifier: my-university diff --git a/test/fixtures/university/organizations.yml b/test/fixtures/university/organizations.yml index a684cda0bc2ac7ee17bc8505652fb23c069af8b6..08514e6ab2b50be732b4a828a535e525f17036fc 100644 --- a/test/fixtures/university/organizations.yml +++ b/test/fixtures/university/organizations.yml @@ -36,32 +36,7 @@ # fk_rails_35fcd198e0 (university_id => universities.id) # -one: +default_organization: + name: Organisation de test + active: true university: default_university - name: MyString - meta_description: MyText - address: MyString - zipcode: MyString - city: MyString - country: MyString - url: MyString - phone: MyString - email: MyString - active: false - siren: MyString - kind: 1 - -two: - university: default_university - name: MyString - meta_description: MyText - address: MyString - zipcode: MyString - city: MyString - country: MyString - url: MyString - phone: MyString - email: MyString - active: false - siren: MyString - kind: 1 diff --git a/test/fixtures/university/people.yml b/test/fixtures/university/people.yml new file mode 100644 index 0000000000000000000000000000000000000000..2281277b1a3c39691aae490182ab1a88a3b1e22d --- /dev/null +++ b/test/fixtures/university/people.yml @@ -0,0 +1,58 @@ +# == Schema Information +# +# Table name: university_people +# +# id :uuid not null, primary key +# address :string +# biography :text +# birthdate :date +# city :string +# country :string +# description :text +# description_short :text +# email :string +# first_name :string +# gender :integer +# habilitation :boolean default(FALSE) +# is_administration :boolean +# is_alumnus :boolean default(FALSE) +# is_author :boolean +# is_researcher :boolean +# is_teacher :boolean +# last_name :string +# linkedin :string +# name :string +# phone_mobile :string +# phone_personal :string +# phone_professional :string +# slug :string +# tenure :boolean default(FALSE) +# twitter :string +# url :string +# zipcode :string +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# user_id :uuid indexed +# +# Indexes +# +# index_university_people_on_university_id (university_id) +# index_university_people_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_b47a769440 (user_id => users.id) +# fk_rails_da35e70d61 (university_id => universities.id) +# + +alumnus: + email: alumnus@osuny.org + first_name: Alumnus + is_alumnus: true + last_name: Osuny + name: Alumnus Osuny + cohorts: + - default_cohort + university: default_university + user: alumnus \ No newline at end of file diff --git a/test/fixtures/university/person/experiences.yml b/test/fixtures/university/person/experiences.yml new file mode 100644 index 0000000000000000000000000000000000000000..8aa8f8850da1f347aeb54204a567a90809601382 --- /dev/null +++ b/test/fixtures/university/person/experiences.yml @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: university_person_experiences +# +# id :uuid not null, primary key +# description :text +# from_year :integer +# to_year :integer +# created_at :datetime not null +# updated_at :datetime not null +# organization_id :uuid not null, indexed +# person_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_university_person_experiences_on_organization_id (organization_id) +# index_university_person_experiences_on_person_id (person_id) +# index_university_person_experiences_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_18125d90df (person_id => university_people.id) +# fk_rails_38aaa18a3b (organization_id => university_organizations.id) +# fk_rails_923d0b71fd (university_id => universities.id) +# + +default_experience: + from_year: 2022 + to_year: 2023 + person: alumnus + organization: default_organization + university: default_university \ No newline at end of file diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000000000000000000000000000000000000..a830b4a709a9983cab0485b93ac91578d7508d7e --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,84 @@ +# == Schema Information +# +# Table name: users +# +# id :uuid not null, primary key +# admin_theme :integer default("appstack") +# confirmation_sent_at :datetime +# confirmation_token :string indexed +# confirmed_at :datetime +# current_sign_in_at :datetime +# current_sign_in_ip :string +# direct_otp :string +# direct_otp_delivery_method :string +# direct_otp_sent_at :datetime +# email :string default(""), not null, indexed => [university_id] +# encrypted_otp_secret_key :string indexed +# encrypted_otp_secret_key_iv :string +# encrypted_otp_secret_key_salt :string +# encrypted_password :string default(""), not null +# failed_attempts :integer default(0), not null +# first_name :string +# last_name :string +# last_sign_in_at :datetime +# last_sign_in_ip :string +# locked_at :datetime +# mobile_phone :string +# picture_url :string +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string indexed +# role :integer default("visitor") +# second_factor_attempts_count :integer default(0) +# session_token :string +# sign_in_count :integer default(0), not null +# totp_timestamp :datetime +# unconfirmed_email :string +# unlock_token :string indexed +# created_at :datetime not null +# updated_at :datetime not null +# language_id :uuid indexed +# university_id :uuid not null, indexed => [email], indexed +# +# Indexes +# +# index_users_on_confirmation_token (confirmation_token) UNIQUE +# index_users_on_email_and_university_id (email,university_id) UNIQUE +# index_users_on_encrypted_otp_secret_key (encrypted_otp_secret_key) UNIQUE +# index_users_on_language_id (language_id) +# index_users_on_reset_password_token (reset_password_token) UNIQUE +# index_users_on_university_id (university_id) +# index_users_on_unlock_token (unlock_token) UNIQUE +# +# Foreign Keys +# +# fk_rails_45f4f12508 (language_id => languages.id) +# fk_rails_bd6f7212a9 (university_id => universities.id) +# + +alumnus: + confirmed_at: <%= Time.zone.now %> + email: alumnus@osuny.org + first_name: Alumnus + last_name: Osuny + role: user + language: fr + university: default_university + +admin: + confirmed_at: <%= Time.zone.now %> + email: admin@osuny.org + first_name: Admin + last_name: Osuny + role: admin + language: fr + university: default_university + +server_admin: + confirmed_at: <%= Time.zone.now %> + email: serveradmin@osuny.org + first_name: Server Admin + last_name: Osuny + role: server_admin + language: fr + university: default_university \ No newline at end of file diff --git a/test/support/extranet_setup.rb b/test/support/extranet_setup.rb new file mode 100644 index 0000000000000000000000000000000000000000..59e3e016103f92b851f497aea21a74edfb81221a --- /dev/null +++ b/test/support/extranet_setup.rb @@ -0,0 +1,6 @@ +module ExtranetSetup + def setup + host! "extranet.osuny.test" + sign_in_with_2fa(alumnus) + end +end \ No newline at end of file diff --git a/test/system/university/organizations_test.rb b/test/system/university/organizations_test.rb index f97585ce0389365f13ae117ec3529078c0e39ba4..d31d32daf930c17a5a0318115c369748534cb60a 100644 --- a/test/system/university/organizations_test.rb +++ b/test/system/university/organizations_test.rb @@ -2,7 +2,7 @@ require "application_system_test_case" class University::OrganizationsTest < ApplicationSystemTestCase setup do - @university_organization = university_organizations(:one) + @university_organization = university_organizations(:default_organization) end test "visiting the index" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 35caf45857176187fc4d21786fb9eac41bda08c2..a4fd59f5c106518a47c6af9a725e913a017dda1a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,6 +8,28 @@ require "rails/test_help" Dir["./test/support/**/*.rb"].each { |f| require f } class ActiveSupport::TestCase - parallelize(workers: :number_of_processors) + include Devise::Test::IntegrationHelpers + include TwoFactorAuthentication::Test::IntegrationHelpers + fixtures :all + + setup do + ENV.update(ENV.to_h.merge('APPLICATION_ENV' => 'test')) + end + + def alumnus + @alumnus ||= users(:alumnus) + end + + def alumnus_person + @alumnus_person ||= university_people(:alumnus) + end + + def admin + @admin ||= users(:admin) + end + + def server_admin + @server_admin ||= users(:server_admin) + end end