From 379f723f60b4c3267134885c4579d413841a08ae Mon Sep 17 00:00:00 2001 From: natsuto6 <79001972+natsuto6@users.noreply.github.com> Date: Sat, 6 Apr 2024 00:34:04 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=92=B0=E5=A2=83?= =?UTF-8?q?=E3=81=A7=E3=81=AE=E5=88=86=E5=A0=B1=E3=83=81=E3=83=A3=E3=83=B3?= =?UTF-8?q?=E3=83=8D=E3=83=AB=E4=BD=9C=E6=88=90=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E6=A8=A1=E5=80=A3=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discord/users_controller_test.rb | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) 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