Skip to content

Commit

Permalink
Merge pull request #25 from subeshb1/fix/dash_number_key_failure
Browse files Browse the repository at this point in the history
Add quote to dynamically accessed key names
  • Loading branch information
subeshb1 authored Aug 31, 2020
2 parents 03d91ff + bd31aa1 commit cfd7691
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: CI

on: [push, pull_request]
on: [push]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.3.2
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

## v0.3.1
## v0.3.2
- Fix script breaking on test cases starting with numbers Eg: `01_testcase, 02_testcase` and containing hyphen `-` Eg: `test-case`

## v0.3.1
- Fixed null body being sent when no body content was provided.
- Fixed typo in external script test message.

Expand Down
28 changes: 14 additions & 14 deletions api-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ function usage() {

# api methods
call_api() {
ROUTE=$(jq -r ".testCases.$1.path" $FILE)
BODY="$(jq -r ".testCases.$1 | select(.body != null) | .body" $FILE)"
QUERY_PARAMS=$(cat $FILE | jq -r ".testCases.$1 | select(.query != null) | .query | to_entries | map(\"\(.key)=\(.value|tostring)\") | join(\"&\") | \"?\" + . ")
REQUEST_HEADER=$(cat $FILE | jq -r ".testCases.$1 | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
METHOD="$(jq -r ".testCases.$1.method //\"GET\" | ascii_upcase" $FILE)"
ROUTE=$(jq -r ".testCases.\"$1\".path" $FILE)
BODY="$(jq -r ".testCases.\"$1\" | select(.body != null) | .body" $FILE)"
QUERY_PARAMS=$(cat $FILE | jq -r ".testCases.\"$1\" | select(.query != null) | .query | to_entries | map(\"\(.key)=\(.value|tostring)\") | join(\"&\") | \"?\" + . ")
REQUEST_HEADER=$(cat $FILE | jq -r ".testCases.\"$1\" | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
METHOD="$(jq -r ".testCases.\"$1\".method //\"GET\" | ascii_upcase" $FILE)"
# curl -ivs --request $METHOD "$URL$ROUTE$QUERY_PARAMS" \
# --data "$BODY" \
# "$COMMON_HEADER" \
Expand Down Expand Up @@ -211,8 +211,8 @@ api_factory() {
for TEST_CASE in $@; do
API_ERROR=0
echo "${BOLD}Running Case:${RESET} $TEST_CASE"
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.$TEST_CASE.description" $FILE)"
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.$TEST_CASE.path" $FILE)"
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".description" $FILE)"
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.\"$TEST_CASE\".path" $FILE)"
call_api $TEST_CASE
display_results
echo ""
Expand All @@ -227,9 +227,9 @@ test_factory() {
for TEST_CASE in $@; do
API_ERROR=0
echo "${BOLD}Testing Case:${RESET} $TEST_CASE"
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.$TEST_CASE.description" $FILE)"
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.$TEST_CASE.path" $FILE)"
if [[ -z $(jq -r ".testCases.$TEST_CASE.expect? | select(. !=null)" $FILE) ]]; then
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".description" $FILE)"
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.\"$TEST_CASE\".path" $FILE)"
if [[ -z $(jq -r ".testCases.\"$TEST_CASE\".expect? | select(. !=null)" $FILE) ]]; then
tput cuf 2
echo "No test cases found"
echo ""
Expand All @@ -245,7 +245,7 @@ test_factory() {
continue
fi

local TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.header? | select(. !=null and . != {})" $FILE)
local TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.header? | select(. !=null and . != {})" $FILE)
if [[ ! -z $TEST_SCENARIO ]]; then
tput cuf 2
echo "${UNDERLINE}Checking condition for header${RESET}"
Expand All @@ -254,7 +254,7 @@ test_factory() {
echo ""
fi

TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.body? | select(. !=null and . != {})" $FILE)
TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.body? | select(. !=null and . != {})" $FILE)
if [[ ! -z $TEST_SCENARIO ]]; then
tput cuf 2
echo "${UNDERLINE}Checking condition for body${RESET}"
Expand All @@ -263,7 +263,7 @@ test_factory() {
echo ""
fi

TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.external? | select(. !=null and . != \"\")" $FILE)
TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.external? | select(. !=null and . != \"\")" $FILE)
if [[ ! -z $TEST_SCENARIO ]]; then
tput cuf 2
echo "${UNDERLINE}Checking condition from external program${RESET}"
Expand Down Expand Up @@ -299,7 +299,7 @@ test_factory() {

test_runner() {
for test in ""contains eq path_eq path_contains hasKey[]""; do
local TEST_SCENARIO=$(jq -c -r ".testCases.$1.expect.$2.$test? | select(. !=null)" $FILE)
local TEST_SCENARIO=$(jq -c -r ".testCases.\"$1\".expect.$2.$test? | select(. !=null)" $FILE)
if [[ -z $TEST_SCENARIO ]]; then
continue
fi
Expand Down
2 changes: 1 addition & 1 deletion test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hayd/ubuntu-deno:1.0.2
FROM hayd/ubuntu-deno:1.3.1


WORKDIR /app
Expand Down
7 changes: 4 additions & 3 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ const getBook = (ctx: RouterContext<any>) => {

const postBook = async (ctx: RouterContext<RouteParams>) => {
const { request, response } = ctx;
response.type = 'application/json'
if (request.hasBody) {
const result: any = await request.body({
contentTypes: {
text: ["application/javascript"],
},
});
const body: any = JSON.parse(result.value)
})
const body: {id:string} = await result.value
const book: IBook | undefined = searchBookById(body.id)
if (!book) {
if (!book) {
response.status = 200
response.body = body
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"url": "api-test:3000",
"header": {
"Content-Type": "application/javascript"
"Content-Type": "application/json"
}
}

0 comments on commit cfd7691

Please sign in to comment.