Skip to content

Commit

Permalink
chore: add earn e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Oct 27, 2023
1 parent 69e4f0d commit 1cd755e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
42 changes: 42 additions & 0 deletions core/api/test/bats/earn.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bats

load "helpers/setup-and-teardown"

setup_file() {
clear_cache
reset_redis

bitcoind_init
start_trigger
start_server

initialize_user_from_onchain "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE"
}

teardown_file() {
stop_trigger
stop_server
}

@test "earn: mark quiz completed" {
token_name="$ALICE_TOKEN_NAME"
question_id="walletDownloaded"

# Ensure quiz rewards are disabled and question is not completed
exec_graphql "$token_name" 'account-quiz'
rewards_enabled="$(graphql_output '.data.me.defaultAccount.quizRewardsEnabled')"
[[ "$rewards_enabled" == "false" ]] || exit 1
quiz_question_completed="$(graphql_output ".data.me.defaultAccount.quiz[] | select(.id == \"$question_id\") | .completed")"
[[ "$quiz_question_completed" == "false" ]] || exit 1

# Mark question as completed
variables=$(
jq -n \
'{input: { id: "'"$question_id"'" }}')

exec_graphql "$token_name" 'account-quiz-completed' "$variables"
quiz_question_completed="$(graphql_output '.data.quizCompleted.quiz.completed')"
[[ "$quiz_question_completed" == "true" ]] || exit 1
reward_paid="$(graphql_output ".data.quizCompleted.rewardPaid")"
[[ "$reward_paid" == "false" ]] || exit 1
}
13 changes: 13 additions & 0 deletions core/api/test/bats/gql/account-quiz-completed.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mutation accountQuizCompleted($input: QuizCompletedInput!) {
quizCompleted(input: $input) {
quiz {
amount
completed
id
}
errors {
message
}
rewardPaid
}
}
14 changes: 14 additions & 0 deletions core/api/test/bats/gql/account-quiz.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query me {
me {
defaultAccount {
... on ConsumerAccount {
quizRewardsEnabled
quiz {
id
completed
}
}
id
}
}
}

0 comments on commit 1cd755e

Please sign in to comment.