Skip to content

Commit

Permalink
テスト環境での分報チャンネル作成処理を模倣するための修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Takuya-Sakai91 committed Apr 8, 2024
1 parent 1d01a29 commit 379f723
Showing 1 changed file with 52 additions and 51 deletions.
103 changes: 52 additions & 51 deletions test/integration/discord/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
# 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
end
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

Expand Down Expand Up @@ -130,7 +131,7 @@ def save
end

def id
'fake_times_snowflake_0123456789'
'1234567890123456789'
end
end
end
Expand Down

0 comments on commit 379f723

Please sign in to comment.