Reviewed-on: #368 Co-authored-by: miteruzo <miteruzo@naver.com> Co-committed-by: miteruzo <miteruzo@naver.com>
このコミットはPull リクエスト #368 でマージされました.
このコミットが含まれているのは:
@@ -129,7 +129,7 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it 'returns not found for a non-admin user' do
|
||||
it 'stores a game result for a non-admin user' do
|
||||
sign_in_as member
|
||||
|
||||
post '/gekanator/games', params: {
|
||||
@@ -138,7 +138,18 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
answers: []
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(GekanatorGame.find(json['id']).user).to eq(member)
|
||||
end
|
||||
|
||||
it 'returns unauthorized without a user' do
|
||||
post '/gekanator/games', params: {
|
||||
guessed_post_id: guessed_post.id,
|
||||
correct_post_id: correct_post.id,
|
||||
answers: []
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -261,17 +272,57 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it 'returns not found for a non-admin user' do
|
||||
it 'allows a non-admin user to suggest a question for their own game' do
|
||||
member_game = GekanatorGame.create!(
|
||||
user: member,
|
||||
guessed_post: guessed_post,
|
||||
correct_post: correct_post,
|
||||
won: false,
|
||||
question_count: 1,
|
||||
answers: [{ 'question_id' => 'tag:1', 'answer' => 'yes' }]
|
||||
)
|
||||
sign_in_as member
|
||||
|
||||
post '/gekanator/question_suggestions', params: {
|
||||
gekanator_game_id: game.id,
|
||||
question_text: 'member question?',
|
||||
answer: 'yes'
|
||||
}
|
||||
expect {
|
||||
post '/gekanator/question_suggestions', params: {
|
||||
gekanator_game_id: member_game.id,
|
||||
question_text: 'member question?',
|
||||
answer: 'yes'
|
||||
}
|
||||
}.to change { GekanatorQuestionSuggestion.count }.by(1)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(GekanatorQuestionSuggestion.last).to have_attributes(
|
||||
gekanator_game_id: member_game.id,
|
||||
user_id: member.id
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns not found for another user game' do
|
||||
sign_in_as member
|
||||
|
||||
expect {
|
||||
post '/gekanator/question_suggestions', params: {
|
||||
gekanator_game_id: game.id,
|
||||
question_text: 'member question?',
|
||||
answer: 'yes'
|
||||
}
|
||||
}.not_to change { GekanatorQuestionSuggestion.count }
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'returns unauthorized without a user' do
|
||||
expect {
|
||||
post '/gekanator/question_suggestions', params: {
|
||||
gekanator_game_id: game.id,
|
||||
question_text: 'member question?',
|
||||
answer: 'yes'
|
||||
}
|
||||
}.not_to change { GekanatorQuestionSuggestion.count }
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /gekanator/games/:id/extra_questions' do
|
||||
@@ -377,6 +428,38 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['questions'].map { _1['id'] }).to contain_exactly(accepted.id)
|
||||
end
|
||||
|
||||
it 'allows a non-admin user to fetch extra questions for their own game' do
|
||||
member_game = GekanatorGame.create!(
|
||||
user: member,
|
||||
guessed_post: guessed_post,
|
||||
correct_post: correct_post,
|
||||
won: false,
|
||||
question_count: 1,
|
||||
answers: [{ 'question_id' => 'tag:1', 'answer' => 'yes' }]
|
||||
)
|
||||
accepted = create_post_similarity_question!(text: 'accepted?')
|
||||
sign_in_as member
|
||||
|
||||
get "/gekanator/games/#{member_game.id}/extra_questions"
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['questions'].map { _1['id'] }).to include(accepted.id)
|
||||
end
|
||||
|
||||
it 'returns not found for another user game' do
|
||||
sign_in_as member
|
||||
|
||||
get "/gekanator/games/#{game.id}/extra_questions"
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'returns unauthorized without a user' do
|
||||
get "/gekanator/games/#{game.id}/extra_questions"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /gekanator/games/:id/extra_question_answers' do
|
||||
@@ -503,6 +586,69 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
|
||||
it 'allows a non-admin user to answer extra questions for their own game' do
|
||||
member_game = GekanatorGame.create!(
|
||||
user: member,
|
||||
guessed_post: guessed_post,
|
||||
correct_post: correct_post,
|
||||
won: false,
|
||||
question_count: 1,
|
||||
answers: [{ 'question_id' => 'tag:1', 'answer' => 'yes' }]
|
||||
)
|
||||
question = create_post_similarity_question!(text: 'extra?')
|
||||
sign_in_as member
|
||||
|
||||
expect {
|
||||
post "/gekanator/games/#{member_game.id}/extra_question_answers", params: {
|
||||
answers: [
|
||||
{
|
||||
question_id: question.id,
|
||||
answer: 'yes'
|
||||
}
|
||||
]
|
||||
}
|
||||
}.to change { GekanatorQuestionExample.count }.by(1)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
expect(GekanatorQuestionExample.last).to have_attributes(
|
||||
user_id: member.id,
|
||||
gekanator_game_id: member_game.id
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns not found for another user game' do
|
||||
question = create_post_similarity_question!(text: 'extra?')
|
||||
sign_in_as member
|
||||
|
||||
expect {
|
||||
post "/gekanator/games/#{game.id}/extra_question_answers", params: {
|
||||
answers: [
|
||||
{
|
||||
question_id: question.id,
|
||||
answer: 'yes'
|
||||
}
|
||||
]
|
||||
}
|
||||
}.not_to change { GekanatorQuestionExample.count }
|
||||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'returns unauthorized without a user' do
|
||||
question = create_post_similarity_question!(text: 'extra?')
|
||||
|
||||
post "/gekanator/games/#{game.id}/extra_question_answers", params: {
|
||||
answers: [
|
||||
{
|
||||
question_id: question.id,
|
||||
answer: 'yes'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /gekanator/questions' do
|
||||
@@ -608,5 +754,33 @@ RSpec.describe 'Gekanator learning API', type: :request do
|
||||
'length' => 21
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns title-contains questions without authentication' do
|
||||
GekanatorQuestion.create!(
|
||||
text: '題名に「結束バンド」が含まれる?',
|
||||
kind: 'title',
|
||||
source: 'ai_generated',
|
||||
status: 'accepted',
|
||||
priority_weight: 0.95,
|
||||
condition: {
|
||||
type: 'title-contains',
|
||||
text: '結束バンド'
|
||||
},
|
||||
created_by: admin
|
||||
)
|
||||
|
||||
get '/gekanator/questions'
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
question_json = json['questions'].find { _1['id'] == 'title:contains:結束バンド' }
|
||||
expect(question_json).to include(
|
||||
'text' => '題名に「結束バンド」が含まれる?',
|
||||
'kind' => 'title'
|
||||
)
|
||||
expect(question_json['condition']).to include(
|
||||
'type' => 'title-contains',
|
||||
'text' => '結束バンド'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
新しい課題から参照
ユーザをブロックする