diff --git a/test/integration/discord/users_controller_test.rb b/test/integration/discord/users_controller_test.rb index 06398ededf2..c4cb9ac482a 100644 --- a/test/integration/discord/users_controller_test.rb +++ b/test/integration/discord/users_controller_test.rb @@ -1,34 +1,39 @@ # frozen_string_literal: true require 'test_helper' +require 'supports/mock_env_helper' module Discord class UsersControllerTest < ActionDispatch::IntegrationTest + include MockEnvHelper + test 'POST create by student' do - Card.stub(:new, -> { FakeCard.new }) do - Subscription.stub(:new, -> { FakeSubscription.new }) do - Discord::TimesChannel.stub(:new, ->(_) { ValidTimesChannel.new }) do - assert_difference 'User.students.count', 1 do - post users_path, - params: { - user: { - adviser: 'false', - trainee: 'false', - company_id: '', - login_name: 'Piyopiyo-student', - email: 'piyopiyo-student@example.com', - name: '現役生です', - name_kana: 'ゲンエキセイデス', - description: '現役生と言います。よろしくお願いします。', - job: 'part_time_worker', - os: 'linux', - experience: 'inexperienced', - password: 'passW0rd1234', - password_confirmation: 'passW0rd1234', - coc: 1, - tos: 2 + mock_env('DISCORD_GUILD_ID' => '111') do + Card.stub(:new, -> { FakeCard.new }) do + Subscription.stub(:new, -> { FakeSubscription.new }) do + Discord::TimesChannel.stub(:new, ->(_) { ValidTimesChannel.new }) do + assert_difference 'User.students.count', 1 do + post users_path, + params: { + user: { + adviser: 'false', + trainee: 'false', + company_id: '', + login_name: 'Piyopiyo-student', + email: 'piyopiyo-student@example.com', + name: '現役生です', + name_kana: 'ゲンエキセイデス', + description: '現役生と言います。よろしくお願いします。', + job: 'part_time_worker', + os: 'linux', + experience: 'inexperienced', + password: 'passW0rd1234', + password_confirmation: 'passW0rd1234', + coc: 1, + tos: 2 + } } - } + end end end end @@ -36,43 +41,39 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_redirected_to root_url student = User.find_by(login_name: 'Piyopiyo-student') - student.create_discord_profile unless student.discord_profile - student.discord_profile.times_id = ValidTimesChannel.new.id - student.discord_profile.save! assert_not_nil student.discord_profile.times_id end test 'POST create by trainee' do - Discord::TimesChannel.stub(:new, ->(_) { ValidTimesChannel.new }) do - assert_difference 'User.trainees.count', 1 do - post users_path, - params: { - user: { - adviser: 'false', - trainee: 'true', - company_id: '123456789', - login_name: 'Piyopiyo-trainee', - email: 'piyopiyo-trainee@example.com', - name: '研修生です', - name_kana: 'ケンシュウセイデス', - description: '研修生と言います。よろしくお願いします。', - job: 'office_worker', - os: 'windows_wsl2', - experience: 'ruby', - password: 'passW0rd1234', - password_confirmation: 'passW0rd1234', - coc: 1, - tos: 2 + mock_env('DISCORD_GUILD_ID' => '222') do + Discord::TimesChannel.stub(:new, ->(_) { ValidTimesChannel.new }) do + assert_difference 'User.trainees.count', 1 do + post users_path, + params: { + user: { + adviser: 'false', + trainee: 'true', + company_id: '123456789', + login_name: 'Piyopiyo-trainee', + email: 'piyopiyo-trainee@example.com', + name: '研修生です', + name_kana: 'ケンシュウセイデス', + description: '研修生と言います。よろしくお願いします。', + job: 'office_worker', + os: 'windows_wsl2', + experience: 'ruby', + password: 'passW0rd1234', + password_confirmation: 'passW0rd1234', + coc: 1, + tos: 2 + } } - } + end end end assert_redirected_to root_url trainee = User.find_by(login_name: 'Piyopiyo-trainee') - trainee.create_discord_profile unless trainee.discord_profile - trainee.discord_profile.times_id = ValidTimesChannel.new.id - trainee.discord_profile.save! assert_not_nil trainee.discord_profile.times_id end @@ -130,7 +131,7 @@ def save end def id - 'fake_times_snowflake_0123456789' + '1234567890123456789' end end end