Skip to content

Commit

Permalink
ci: await_api_keys_is_up
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Nov 9, 2023
1 parent 530f68a commit 3616e05
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Buck2 build
run: nix develop -c buck2 build core/api core/api-keys apps/dashboard apps/consent
run: nix develop -c buck2 build //core/api //core/api-keys //apps/dashboard //apps/consent
- name: Run bats tests
run: |
nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/**
19 changes: 19 additions & 0 deletions bats/ci_setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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:5397/auth/check || exit 1
}

retry 300 1 api_keys_is_up
}
15 changes: 8 additions & 7 deletions bats/core/api-keys/api-keys.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" {
Expand Down
10 changes: 0 additions & 10 deletions bats/helpers/_common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bats/helpers/setup-and-teardown.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ login_user() {

local code="000000"

local variables=$(
local variables
variables=$(
jq -n \
--arg phone "$phone" \
--arg code "$code" \
Expand Down

0 comments on commit 3616e05

Please sign in to comment.