Skip to content

Commit

Permalink
test(core): add account-level external id uniqueness checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Apr 27, 2024
1 parent 011a799 commit 852cbbc
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions bats/core/api/invoices.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ setup_file() {
clear_cache

create_user 'alice'
create_user 'bob'
seed_invoices
}

Expand Down Expand Up @@ -69,29 +70,75 @@ seed_invoices() {
[[ "$num_errors" == "0" ]] || exit 1
}

@test "invoices: adding multiple invoices with same external id fails" {
token_name='alice'
btc_wallet_name="$token_name.btc_wallet_id"
btc_amount="1000"
@test "invoices: adding multiple invoices with same external id fails for same account" {
external_id="external-id-$RANDOM"

alice_btc_wallet_name="alice.btc_wallet_id"
alice_usd_wallet_name="alice.usd_wallet_id"
bob_btc_wallet_name="bob.btc_wallet_id"
bob_usd_wallet_name="bob.usd_wallet_id"

btc_amount="1000"
usd_amount="20"

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg wallet_id "$(read_value $alice_btc_wallet_name)" \
--arg amount "$btc_amount" \
--arg external_id "$external_id" \
'{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}'
)

exec_graphql "$token_name" 'ln-invoice-create' "$variables"
exec_graphql 'alice' 'ln-invoice-create' "$variables"
num_errors="$(graphql_output '.data.lnInvoiceCreate.errors | length')"
[[ "$num_errors" == "0" ]] || exit 1

exec_graphql "$token_name" 'ln-invoice-create' "$variables"
# Check 'alice' can't re-use externalId for same wallet
exec_graphql 'alice' 'ln-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnInvoiceCreate.invoice')"
[[ "$invoice" == "null" ]] || exit 1
error_msg="$(graphql_output '.data.lnInvoiceCreate.errors[0].message')"
[[ "${error_msg}" =~ "already exists" ]] || exit 1

# Check 'alice' can't re-use externalId for different wallet
variables=$(
jq -n \
--arg wallet_id "$(read_value $alice_usd_wallet_name)" \
--arg amount "$usd_amount" \
--arg external_id "$external_id" \
'{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}'
)
exec_graphql 'alice' 'ln-usd-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnUsdInvoiceCreate.invoice')"
[[ "$invoice" == "null" ]] || exit 1
error_msg="$(graphql_output '.data.lnUsdInvoiceCreate.errors[0].message')"
[[ "${error_msg}" =~ "already exists" ]] || exit 1

# Check 'bob' can re-use externalId once
variables=$(
jq -n \
--arg wallet_id "$(read_value $bob_btc_wallet_name)" \
--arg amount "$btc_amount" \
--arg external_id "$external_id" \
'{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}'
)
exec_graphql 'bob' 'ln-invoice-create' "$variables"
num_errors="$(graphql_output '.data.lnInvoiceCreate.errors | length')"
[[ "$num_errors" == "0" ]] || exit 1

# Check 'bob' cant re-use externalId again
variables=$(
jq -n \
--arg wallet_id "$(read_value $bob_usd_wallet_name)" \
--arg amount "$usd_amount" \
--arg external_id "$external_id" \
'{input: {walletId: $wallet_id, amount: $amount, externalId: $external_id}}'
)
exec_graphql 'bob' 'ln-usd-invoice-create' "$variables"
invoice="$(graphql_output '.data.lnUsdInvoiceCreate.invoice')"
[[ "$invoice" == "null" ]] || exit 1
error_msg="$(graphql_output '.data.lnUsdInvoiceCreate.errors[0].message')"
[[ "${error_msg}" =~ "already exists" ]] || exit 1
}

@test "invoices: get invoices for account" {
Expand Down

0 comments on commit 852cbbc

Please sign in to comment.