Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add bats test for map #3923

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions bats/admin-gql/update-merchant-map.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mutation businessUpdateMapInfo($input: BusinessUpdateMapInfoInput!) {
businessUpdateMapInfo(input: $input) {
errors {
message
}
accountDetails {
id
username
level
status
title
owner {
id
language
phone
email {
address
verified
}
createdAt
}
coordinates {
latitude
longitude
}
wallets {
id
walletCurrency
accountId
balance
pendingIncomingBalance
}
createdAt
}
}
}
25 changes: 2 additions & 23 deletions bats/core/api/admin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,15 @@

load "../../helpers/_common.bash"
load "../../helpers/user.bash"
load "../../helpers/admin.bash"

setup_file() {
clear_cache

create_user 'tester'
user_update_username 'tester'
}

HYDRA_PUBLIC_API="http://localhost:4444"
HYDRA_ADMIN_API="http://localhost:4445"


@test "admin: can retrieve admin token" {
client=$(curl -L -s -X POST $HYDRA_ADMIN_API/admin/clients \
-H 'Content-Type: application/json' \
-d '{
"grant_types": ["client_credentials"]
}')

client_id=$(echo $client | jq -r '.client_id')
client_secret=$(echo $client | jq -r '.client_secret')

admin_token=$(curl -s -X POST $HYDRA_PUBLIC_API/oauth2/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-u "$client_id:$client_secret" \
-d "grant_type=client_credentials" | jq -r '.access_token'
)
echo "admin_token: $admin_token"
[[ -n "$admin_token" ]] || exit 1
cache_value 'admin.token' "$admin_token"
login_admin
}

@test "admin: can query account details by phone" {
Expand Down
41 changes: 41 additions & 0 deletions bats/core/api/merchant.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bats

load "../../helpers/_common.bash"
load "../../helpers/user.bash"
load "../../helpers/admin.bash"

setup_file() {
clear_cache

create_user 'merchant'
user_update_username 'merchant'

login_admin
}

@test "merchants: add a merchant with admin api" {
nicolasburtey marked this conversation as resolved.
Show resolved Hide resolved
admin_token="$(read_value 'admin.token')"
latitude=40.712776
longitude=-74.005974
title="My Merchant"
local username="$(read_value merchant.username)"

variables=$(jq -n \
--arg latitude "$latitude" \
--arg longitude "$longitude" \
--arg title "$title" \
--arg username "$username" \
'{input: {latitude: ($latitude | tonumber), longitude: ($longitude | tonumber), title: $title, username: $username}}'
)

exec_admin_graphql $admin_token 'update-merchant-map' "$variables"
latitude_result="$(graphql_output '.data.businessUpdateMapInfo.accountDetails.coordinates.latitude')"
[[ "$latitude_result" == "$latitude" ]] || exit 1
}

@test "merchant: can query merchants" {
local username="$(read_value merchant.username)"
exec_graphql 'anon' 'business-map-markers'
fetch_username="$(graphql_output '.data.businessMapMarkers[0].username')"
[[ $username = $fetch_username ]] || exit 1
}
12 changes: 12 additions & 0 deletions bats/gql/business-map-markers.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
query businessMapMarkers {
businessMapMarkers {
username
mapInfo {
title
coordinates {
longitude
latitude
}
}
}
}
23 changes: 23 additions & 0 deletions bats/helpers/admin.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

HYDRA_PUBLIC_API="http://localhost:4444"
HYDRA_ADMIN_API="http://localhost:4445"

login_admin() {
client=$(curl -L -s -X POST $HYDRA_ADMIN_API/admin/clients \
-H 'Content-Type: application/json' \
-d '{
"grant_types": ["client_credentials"]
}')

client_id=$(echo $client | jq -r '.client_id')
client_secret=$(echo $client | jq -r '.client_secret')

admin_token=$(curl -s -X POST $HYDRA_PUBLIC_API/oauth2/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-u "$client_id:$client_secret" \
-d "grant_type=client_credentials" | jq -r '.access_token'
)
echo "admin_token: $admin_token"
[[ -n "$admin_token" ]] || exit 1
cache_value 'admin.token' "$admin_token"
}
Loading