Skip to content

Commit

Permalink
e2e test for the range-key option (#147)
Browse files Browse the repository at this point in the history
added an e2e test for range-key, updated the justfile. resolves #145 and
resolves #134
  • Loading branch information
DawidNiezgodka authored Nov 17, 2022
1 parent 0d9464f commit 1b807d9
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ within the timeframe between 1 and 3
(remember that the bound is exclusive).
```graphql
query {
findUserPurchasesInTime(id: "2", timestampFrom: 1, timestampTo: 4) {
findUserPurchasesInTime(userId: "2", timestampFrom: 1, timestampTo: 4) {
productId,
price
{
Expand Down
54 changes: 54 additions & 0 deletions e2e/functional/key-range/purchases.json
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
}
}
]
9 changes: 9 additions & 0 deletions e2e/functional/key-range/query-range.gql
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
}
}
}
14 changes: 14 additions & 0 deletions e2e/functional/key-range/result-range.json
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
}
}
]
30 changes: 30 additions & 0 deletions e2e/functional/key-range/schema.gql
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
}
61 changes: 61 additions & 0 deletions e2e/functional/key-range/tests.bats
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
}
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ e2e-run-multi-stream api-key quick-host:
e2e-run-range api-key quick-host:
docker run -v {{ e2e-dir }}/range:/tests/range -e X_API_KEY={{ api-key }} -e HOST={{ quick-host }} quick-e2e-test-runner --rm -it

# Runs the e2e key-range tests
e2e-run-key-range api-key quick-host:
docker run -v {{ e2e-dir }}/key-range:/tests/key-range -e X_API_KEY={{ api-key }} -e HOST={{ quick-host }} quick-e2e-test-runner --rm -it

# Runs the e2e schema tests
e2e-run-schema api-key quick-host:
docker run -v {{ e2e-dir }}/schema:/tests/schema -e X_API_KEY={{ api-key }} -e HOST={{ quick-host }} quick-e2e-test-runner --rm -it
Expand Down

0 comments on commit 1b807d9

Please sign in to comment.