-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e test for the range-key option (#147)
- Loading branch information
1 parent
0d9464f
commit 1b807d9
Showing
7 changed files
with
173 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[ | ||
{ | ||
"key": "abc", | ||
"value": { | ||
"productId": 123, | ||
"userId": 1, | ||
"amount": 1, | ||
"price": { | ||
"total": 19.99, | ||
"currency": "DOLLAR" | ||
}, | ||
"timestamp": 1 | ||
} | ||
}, | ||
{ | ||
"key": "def", | ||
"value": { | ||
"productId": 123, | ||
"userId": 2, | ||
"amount": 2, | ||
"price": { | ||
"total": 30.00, | ||
"currency": "DOLLAR" | ||
}, | ||
"timestamp": 2 | ||
} | ||
}, | ||
{ | ||
"key": "ghi", | ||
"value": { | ||
"productId": 456, | ||
"userId": 2, | ||
"amount": 1, | ||
"price": { | ||
"total": 79.99, | ||
"currency": "DOLLAR" | ||
}, | ||
"timestamp": 3 | ||
} | ||
}, | ||
{ | ||
"key": "jkl", | ||
"value": { | ||
"productId": 789, | ||
"userId": 2, | ||
"amount": 1, | ||
"price": { | ||
"total": 99.99, | ||
"currency": "DOLLAR" | ||
}, | ||
"timestamp": 4 | ||
} | ||
} | ||
] |
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 @@ | ||
query { | ||
findUserPurchasesInTime(userId: "2", timestampFrom: 1, timestampTo: 4) { | ||
productId, | ||
price | ||
{ | ||
total | ||
} | ||
} | ||
} |
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 @@ | ||
[ | ||
{ | ||
"productId": 123, | ||
"price": { | ||
"total": 30 | ||
} | ||
}, | ||
{ | ||
"productId": 456, | ||
"price": { | ||
"total": 79.99 | ||
} | ||
} | ||
] |
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,30 @@ | ||
type Query { | ||
findUserPurchasesInTime( | ||
userId: String | ||
timestampFrom: Int | ||
timestampTo: Int | ||
): [Purchase] @topic(name: "user-purchases", | ||
keyArgument: "userId" | ||
rangeFrom: "timestampFrom", | ||
rangeTo: "timestampTo") | ||
} | ||
|
||
type Purchase { | ||
productId: Int! | ||
userId: Int! | ||
amount: Int | ||
price: Price | ||
timestamp: Int | ||
} | ||
|
||
type Product { | ||
productId: Int! | ||
name: String | ||
description: String | ||
price: Price | ||
} | ||
|
||
type Price { | ||
total: Float | ||
currency: String | ||
} |
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,61 @@ | ||
#!/usr/bin/env ./test/libs/bats/bin/bats | ||
# shellcheck shell=bats | ||
|
||
CONTENT_TYPE="content-type:application/json" | ||
API_KEY="X-API-Key:${X_API_KEY}" | ||
PURCHASE_TYPE="Purchase" | ||
PURCHASE_TOPIC="user-purchases" | ||
GATEWAY="range-key-gateway-test" | ||
PURCHASE_INGEST_URL="${HOST}/ingest/${PURCHASE_TOPIC}" | ||
GRAPHQL_URL="${HOST}/gateway/${GATEWAY}/graphql" | ||
GRAPHQL_CLI="gql-cli ${GRAPHQL_URL} -H ${API_KEY}" | ||
|
||
|
||
setup() { | ||
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then | ||
printf "creating context for %s\n" "$HOST" | ||
printf "with API_KEY: %s\n" "${X_API_KEY}" | ||
quick context create --host "${HOST}" --key "${X_API_KEY}" | ||
fi | ||
} | ||
|
||
@test "should deploy range-gateway" { | ||
run quick gateway create ${GATEWAY} | ||
echo "$output" | ||
sleep 30 | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "Create gateway ${GATEWAY} (this may take a few seconds)" ] | ||
} | ||
|
||
@test "should apply schema to range-gateway" { | ||
run quick gateway apply ${GATEWAY} -f schema.gql | ||
echo "$output" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "Applied schema to gateway ${GATEWAY}" ] | ||
} | ||
|
||
@test "should create product-price-range topic" { | ||
run quick topic create ${PURCHASE_TOPIC} --key string --value schema --schema "${GATEWAY}.${PURCHASE_TYPE}" --range-key userId --range-field timestamp | ||
echo "$output" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "Created new topic ${PURCHASE_TOPIC}" ] | ||
} | ||
|
||
@test "should ingest valid data in product-price-range" { | ||
curl --request POST --url "${PURCHASE_INGEST_URL}" --header "${CONTENT_TYPE}" --header "${API_KEY}" --data "@./purchases.json" | ||
} | ||
|
||
@test "should retrieve range of inserted items" { | ||
sleep 30 | ||
result="$(${GRAPHQL_CLI} < query-range.gql | jq -j .findUserPurchasesInTime)" | ||
expected="$(cat result-range.json)" | ||
echo "$result" | ||
[ "$result" = "$expected" ] | ||
} | ||
|
||
teardown() { | ||
if [[ "${#BATS_TEST_NAMES[@]}" -eq "$BATS_TEST_NUMBER" ]]; then | ||
quick gateway delete ${GATEWAY} | ||
quick topic delete ${PURCHASE_TYPE} | ||
fi | ||
} |
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