Skip to content

Commit

Permalink
fix: 🐛 投票チェックにてスクリーンネームが見つからないときに適切なレスポンスを返すように修正 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikukyugamer authored Jun 23, 2022
1 parent c52cc7a commit 2c47112
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/controllers/check_votes_and_bonuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ def index
screen_name = Presenter::Common.normalized_screen_name(params[:screen_name])
user = User.find_by(screen_name: screen_name)

# TODO: エラーハンドリング
return render json: {} if user.blank?
error_response = {
gss2022: [],
unite_attacks: [],
short_stories: [],
fav_quotes: [],
sosenkyo_campaigns: []
}
return render json: error_response if user.blank?

gss2022_tweets = user.tweets.gensosenkyo_2022_votes_for_api
unite_attacks_tweets = user.tweets.unite_attacks_votes_for_api
Expand Down
10 changes: 9 additions & 1 deletion spec/requests/check_votes_and_bonuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
get check_votes_and_bonuses_path(screen_name: '@test_user')

expect(response).to have_http_status :ok
expect(response.body).to eq '{}'
expect(JSON.parse(response.body)).to eq(
{
"gss2022" => [],
"unite_attacks" => [],
"short_stories" => [],
"fav_quotes" => [],
"sosenkyo_campaigns" => []
}
)
end

it 'データベースに存在するとき、期待通りのレスポンスが返ってくること' do
Expand Down

0 comments on commit 2c47112

Please sign in to comment.