Skip to content

Commit

Permalink
kyc/quiz: fix correct_option fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-dionysos committed Jan 14, 2024
1 parent 3e76e35 commit be72f8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions kyc/quiz/quiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion kyc/quiz/quiz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`

Expand Down

0 comments on commit be72f8d

Please sign in to comment.