From 9e67944671503f647f6c31016c776e8a7a7c6737 Mon Sep 17 00:00:00 2001 From: bodymindarts Date: Thu, 9 Nov 2023 15:26:13 +0100 Subject: [PATCH] ci: await_api_keys_is_up --- bats/ci_setup_suite.bash | 19 +++++++++++++++++++ bats/core/api-keys/api-keys.bats | 15 ++++++++------- bats/helpers/_common.bash | 10 ---------- bats/helpers/setup-and-teardown.bash | 3 ++- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/bats/ci_setup_suite.bash b/bats/ci_setup_suite.bash index 03f23124669..e32fa255f7a 100644 --- a/bats/ci_setup_suite.bash +++ b/bats/ci_setup_suite.bash @@ -9,6 +9,7 @@ setup_suite() { background buck2 run //dev:up -- --bats=True > "${REPO_ROOT}/bats/.e2e-tilt.log" echo $! > "$TILT_PID_FILE" await_api_is_up + await_api_keys_is_up } teardown_suite() { @@ -18,3 +19,21 @@ teardown_suite() { buck2 run //dev:down } + +await_api_is_up() { + server_is_up() { + exec_graphql 'anon' 'globals' + network="$(graphql_output '.data.globals.network')" + [[ "${network}" = "regtest" ]] || exit 1 + } + + retry 300 1 server_is_up +} + +await_api_keys_is_up() { + api_keys_is_up() { + curl localhost:5394/auth/check || exit 1 + } + + retry 300 1 api_keys_is_up +} diff --git a/bats/core/api-keys/api-keys.bats b/bats/core/api-keys/api-keys.bats index 9094a2ab42b..01b25bb5e9d 100644 --- a/bats/core/api-keys/api-keys.bats +++ b/bats/core/api-keys/api-keys.bats @@ -14,16 +14,11 @@ new_key_name() { random_uuid } -@test "api-keys: returns empty list for no api-keys" { +@test "api-keys: create new key" { login_user 'alice' '+16505554350' exec_graphql 'alice' 'api-keys' - length="$(graphql_output '.data.me.apiKeys | length')" - [[ "$length" == "0" ]] || exit 1 -} - -@test "api-keys: create new key" { - login_user 'alice' '+16505554350' + initial_length="$(graphql_output '.data.me.apiKeys | length')" key_name="$(new_key_name)" cache_value 'key_name' $key_name @@ -40,6 +35,12 @@ new_key_name() { [[ "${name}" = "${key_name}" ]] || exit 1 key_id=$(echo "$key" | jq -r '.id') cache_value "api-key-id" "$key_id" + + exec_graphql 'alice' 'api-keys' + post_creation_length="$(graphql_output '.data.me.apiKeys | length')" + + # Check that the length has incremented by 1 + [[ "$((post_creation_length))" -eq "$((initial_length + 1))" ]] || exit 1 } @test "api-keys: can authenticate with api key and list keys" { diff --git a/bats/helpers/_common.bash b/bats/helpers/_common.bash index 6e6186a8c9c..4df170b9bda 100644 --- a/bats/helpers/_common.bash +++ b/bats/helpers/_common.bash @@ -13,16 +13,6 @@ start_services() { echo $! > "$SERVICES_PID_FILE" } -await_api_is_up() { - server_is_up() { - exec_graphql 'anon' 'globals' - network="$(graphql_output '.data.globals.network')" - [[ "${network}" = "regtest" ]] || exit 1 - } - - retry 300 1 server_is_up -} - stop_services() { [[ -f "$SERVICES_PID_FILE" ]] && kill -9 "$(cat "$SERVICES_PID_FILE")" > /dev/null || true buck2 run //dev:down diff --git a/bats/helpers/setup-and-teardown.bash b/bats/helpers/setup-and-teardown.bash index 6d6d7bf8d2f..276f3232c2d 100644 --- a/bats/helpers/setup-and-teardown.bash +++ b/bats/helpers/setup-and-teardown.bash @@ -6,7 +6,8 @@ login_user() { local code="000000" - local variables=$( + local variables + variables=$( jq -n \ --arg phone "$phone" \ --arg code "$code" \