Skip to content

Commit

Permalink
test: add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi committed Nov 7, 2023
1 parent d903091 commit 77d1b57
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
27 changes: 27 additions & 0 deletions core/api/test/bats/gql/invoices-by-wallet.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
query invoicesForWallet($walletId: WalletId!, $first: Int, $after: String) {
me {
defaultAccount {
id
displayCurrency
walletById(walletId: $walletId) {
id
invoices(first: $first, after: $after) {
...InvoiceList
}
}
}
}
}

fragment InvoiceList on InvoiceConnection {
pageInfo {
hasNextPage
}
edges {
cursor
node {
__typename
paymentHash
}
}
}
23 changes: 23 additions & 0 deletions core/api/test/bats/gql/invoices.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
query invoices($walletIds: [WalletId], $first: Int, $after: String) {
me {
defaultAccount {
defaultWalletId
invoices(walletIds: $walletIds, first: $first, after: $after) {
...InvoiceList
}
}
}
}

fragment InvoiceList on InvoiceConnection {
pageInfo {
hasNextPage
}
edges {
cursor
node {
__typename
paymentHash
}
}
}
79 changes: 79 additions & 0 deletions core/api/test/bats/invoices.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env bats

load "helpers/setup-and-teardown"
load "helpers/ln"

setup_file() {
clear_cache

bitcoind_init
start_trigger
start_server
start_ws_server
start_exporter

lnds_init
login_user "$ALICE_TOKEN_NAME" "$ALICE_PHONE" "$CODE"

token_name="$ALICE_TOKEN_NAME"
btc_wallet_name="$token_name.btc_wallet_id"
btc_amount="1000"

# Generate btc invoice
variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
--arg amount "$btc_amount" \
'{input: {walletId: $wallet_id, amount: $amount}}'
)
exec_graphql "$token_name" 'ln-invoice-create' "$variables"
exec_graphql "$token_name" 'ln-invoice-create' "$variables"

# Generate usd invoice
usd_wallet_name="$token_name.usd_wallet_id"
usd_amount="100"

variables=$(
jq -n \
--arg wallet_id "$(read_value $usd_wallet_name)" \
--arg amount "$usd_amount" \
'{input: {walletId: $wallet_id, amount: $amount}}'
)
exec_graphql "$token_name" 'ln-usd-invoice-create' "$variables"
}

@test "invoices: get invoices for account" {
token_name="$ALICE_TOKEN_NAME"

exec_graphql "$token_name" 'invoices' '{"first": 3}'

invoice_count="$(graphql_output '.data.me.defaultAccount.invoices.edges | length')"
[[ "$invoice_count" -eq "3" ]] || exit 1
}

@test "invoices: get invoices for wallet" {
token_name="$ALICE_TOKEN_NAME"
btc_wallet_name="$token_name.btc_wallet_id"

variables=$(
jq -n \
--arg wallet_id "$(read_value $btc_wallet_name)" \
'{walletId: $wallet_id, first: 2}'
)
exec_graphql "$token_name" 'invoices-by-wallet' "$variables"

invoice_count="$(graphql_output '.data.me.defaultAccount.walletById.invoices.edges | length')"
[[ "$invoice_count" -eq "2" ]] || exit 1
}


teardown_file() {
stop_trigger
stop_server
stop_ws_server
stop_exporter
}

setup() {
reset_redis
}

0 comments on commit 77d1b57

Please sign in to comment.