From d38806988b3764da4837e9bb9ac70fa73f21a435 Mon Sep 17 00:00:00 2001 From: Dionysos <75300347+ice-dionysos@users.noreply.github.com> Date: Sun, 14 Jan 2024 13:28:43 +0100 Subject: [PATCH] kyc/quiz: fix correct_option fetch (#92) --- kyc/quiz/quiz.go | 6 +++--- kyc/quiz/quiz_test.go | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kyc/quiz/quiz.go b/kyc/quiz/quiz.go index 5fec9dcd..2fc60f56 100644 --- a/kyc/quiz/quiz.go +++ b/kyc/quiz/quiz.go @@ -414,7 +414,7 @@ group by return data.userProgress, nil } -func (*repositoryImpl) CheckQuestionNumber(ctx context.Context, questions []uint8, num uint8, tx storage.QueryExecer) (uint8, error) { +func (*repositoryImpl) CheckQuestionNumber(ctx context.Context, lang string, questions []uint8, num uint8, tx storage.QueryExecer) (uint8, error) { type currentQuestion struct { CorrectOption uint8 `db:"correct_option"` } @@ -423,7 +423,7 @@ func (*repositoryImpl) CheckQuestionNumber(ctx context.Context, questions []uint return 0, ErrUnknownQuestionNumber } - data, err := storage.Get[currentQuestion](ctx, tx, `select correct_option from questions where id = $1`, questions[num-1]) + data, err := storage.Get[currentQuestion](ctx, tx, `select correct_option from questions where id = $1 and "language" = $2`, questions[num-1], lang) if err != nil { if errors.Is(err, storage.ErrNotFound) { return 0, ErrUnknownQuestionNumber @@ -562,7 +562,7 @@ func (r *repositoryImpl) ContinueQuizSession( //nolint:funlen,revive //. if pErr != nil { return wrapErrorInTx(pErr) } - _, err = r.CheckQuestionNumber(ctx, progress.Questions, question, tx) + _, err = r.CheckQuestionNumber(ctx, progress.Lang, progress.Questions, question, tx) if err != nil { return wrapErrorInTx(err) } else if uint8(len(progress.Answers)) != question-1 { diff --git a/kyc/quiz/quiz_test.go b/kyc/quiz/quiz_test.go index e3aac2be..c4941e28 100644 --- a/kyc/quiz/quiz_test.go +++ b/kyc/quiz/quiz_test.go @@ -20,7 +20,10 @@ func helperInsertQuestion(t *testing.T, r *repositoryImpl) { insert into questions (id, correct_option, options, language, question) values (10, 1, '{"Paris", "Melbourne", "Warsaw", "Guadalajara"}', 'en', 'What is the capital of France?'), (20, 2, '{"Kyiv", "Madrid", "Milan", "Schaarzen"}', 'en', 'What is the capital of Spain?'), - (30, 3, '{"Waalkerk", "İstanbul", "Berlin", "Wien"}', 'en', 'What is the capital of Germany?') + (30, 3, '{"Waalkerk", "İstanbul", "Berlin", "Wien"}', 'en', 'What is the capital of Germany?'), + (10, 1, '{"Paris", "Melbourne", "Warsaw", "Guadalajara"}', 'xx', 'What is the capital of France???'), + (20, 2, '{"Kyiv", "Madrid", "Milan", "Schaarzen"}', 'xx', 'What is the capital of Spain???'), + (30, 3, '{"Waalkerk", "İstanbul", "Berlin", "Wien"}', 'xx', 'What is the capital of Germany???') on conflict do nothing; `