-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add subscriber to top level bats
- Loading branch information
1 parent
f4fdcbb
commit 71ad2a4
Showing
12 changed files
with
355 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,55 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "../../helpers/_common.bash" | ||
load "../../helpers/subscriber.bash" | ||
|
||
@test "public: can query globals" { | ||
exec_graphql 'anon' 'globals' | ||
network="$(graphql_output '.data.globals.network')" | ||
[[ "${network}" = "regtest" ]] || exit 1 | ||
} | ||
|
||
@test "public: can apply idempotency key to queries" { | ||
fixed_idempotency_key=$(new_idempotency_key) | ||
original_new_idempotency_key=$(declare -f new_idempotency_key) | ||
new_idempotency_key() { | ||
echo $fixed_idempotency_key | ||
} | ||
|
||
# Successful 1st attempt | ||
exec_graphql 'anon' 'globals' | ||
errors="$(graphql_output '.errors')" | ||
[[ "$errors" == "null" ]] || exit 1 | ||
|
||
# Failed 2nd attempt with same idempotency key | ||
exec_graphql 'anon' 'globals' | ||
error_msg="$(graphql_output '.errors[0].message')" | ||
[[ "$error_msg" == "HTTP fetch failed from 'public': 409: Conflict" ]] || exit 1 | ||
|
||
# Failed attempt with invalid idempotency key | ||
new_idempotency_key() { | ||
echo "invalid-key" | ||
} | ||
exec_graphql 'anon' 'globals' | ||
error_msg="$(graphql_output '.errors[0].message')" | ||
[[ "$error_msg" == "HTTP fetch failed from 'public': 400: Bad Request" ]] || exit 1 | ||
|
||
# Successful 3rd attempt with unique valid idempotency key | ||
eval "$original_new_idempotency_key" | ||
exec_graphql 'anon' 'globals' | ||
[[ "$errors" == "null" ]] || exit 1 | ||
} | ||
|
||
@test "public: can subscribe to price" { | ||
subscribe_to 'anon' price-sub | ||
retry 10 1 grep 'Data.*\bprice\b' .e2e-subscriber.log | ||
|
||
num_errors=$( | ||
grep 'Data.*\bprice\b' .e2e-subscriber.log \ | ||
| awk '{print $2}' \ | ||
| jq -r '.data.price.errors | length' | ||
) | ||
[[ "$num_errors" == "0" ]] || exit 1 | ||
|
||
stop_subscriber | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
subscription { | ||
price( | ||
input: { amount: 100 amountCurrencyUnit: BTCSAT priceCurrencyUnit: USDCENT } | ||
) { | ||
errors { | ||
message | ||
} | ||
price { | ||
base | ||
offset | ||
currencyUnit | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CURRENT_FILE=${BASH_SOURCE:-bats/helpers/.} | ||
source "$(dirname "$CURRENT_FILE")/_common.bash" | ||
|
||
export SUBSCRIBER_PID_FILE="${BATS_ROOT_DIR}/.gql_subscriber_pid" | ||
|
||
subscribe_to() { | ||
stop_subscriber > /dev/null 2>&1 || true | ||
|
||
token_name=$1 | ||
if [[ -n "$token_name" && "$token_name" != 'anon' ]]; then | ||
token="$(read_value "$token_name")" | ||
fi | ||
gql_filename=$2 | ||
variables=$3 | ||
|
||
background \ | ||
buck2 run //bats/helpers/subscriber:run -- \ | ||
"ws://${OATHKEEPER_PROXY}/graphqlws" \ | ||
"$(gql_file "$gql_filename")" \ | ||
"$token" \ | ||
"$variables" \ | ||
> "${BATS_ROOT_DIR}/.e2e-subscriber.log" | ||
echo $! > "$SUBSCRIBER_PID_FILE" | ||
} | ||
|
||
stop_subscriber() { | ||
[[ -f "$SUBSCRIBER_PID_FILE" ]] && kill $(cat $SUBSCRIBER_PID_FILE) > /dev/null || true | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load( | ||
"@toolchains//workspace-pnpm:macros.bzl", | ||
"dev_pnpm_task_binary", | ||
) | ||
|
||
dev_pnpm_task_binary( | ||
name = "run", | ||
command = "subscriber", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "subscriber", | ||
"scripts": { | ||
"subscriber": "ts-node src/gql-subscribe.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/ws": "^8.5.8", | ||
"@types/node": "^20.8.7", | ||
"ws": "^8.14.2", | ||
"graphql-ws": "^5.14.1", | ||
"ts-node": "^10.9.1" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
Oops, something went wrong.