-
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.
Merge pull request #8 from nkmr-jp/develop
💥 Supports structure generation for each request method and request parameter.
- Loading branch information
Showing
22 changed files
with
468 additions
and
48 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ node_modules | |
*.go | ||
*.json | ||
tmp | ||
.node-version | ||
.node-version | ||
tests/docs | ||
tests/jsonplaceholder.typicode.com |
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
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
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
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,6 @@ | ||
"jsonplaceholder.typicode.com": | ||
docs: | ||
- https://jsonplaceholder.typicode.com/ | ||
format: | ||
- /posts/{post} | ||
- /todos/{todo} |
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,77 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helper/helper | ||
|
||
setup() { | ||
if [ "$BATS_TEST_NUMBER" -eq 1 ]; then | ||
init_doc | ||
rm -rf ./jsonplaceholder.typicode.com | ||
fi | ||
|
||
BASE_HOST="jsonplaceholder.typicode.com" | ||
BASE_URL="https://$BASE_HOST" | ||
API_TO_GO="node ../bin/api-to-go.js" | ||
doc "## $BATS_TEST_DESCRIPTION" | ||
} | ||
|
||
teardown(){ | ||
write_doc_details "api-to-go" | ||
} | ||
|
||
@test "Command with Path parameters" { | ||
COMMAND="$API_TO_GO $BASE_URL/todos/1" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
|
||
assert_files_match /todos/todo_get.go | ||
assert_files_match /todos/todo_get.json | ||
} | ||
|
||
@test "Command with Query parameters" { | ||
QUERY='?userId=1&completed=false' | ||
COMMAND="$API_TO_GO $BASE_URL/todos$QUERY" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
|
||
assert_files_match /todos_get.go | ||
assert_files_match /todos_get.json | ||
assert_files_match /todos_get_query.go | ||
assert_files_match /todos_get_query.json | ||
} | ||
|
||
@test "Command with Body parameters" { | ||
DATA=' { | ||
"userId": 1, | ||
"id": 1, | ||
"title": "delectus aut autem", | ||
"completed": false | ||
}' | ||
COMMAND="$API_TO_GO $BASE_URL/todos '$DATA'" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
|
||
assert_files_match /todos_post.go | ||
assert_files_match /todos_post.json | ||
assert_files_match /todos_post_body.go | ||
assert_files_match /todos_post_body.json | ||
} | ||
|
||
@test "Command with custom headers" { | ||
HEADERS='{"Content-Type": "application/json"}' | ||
COMMAND="$API_TO_GO --headers '$HEADERS' $BASE_URL/todos/1" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "Command with GET method" { | ||
COMMAND="$API_TO_GO --method GET $BASE_URL/todos/1" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "Display help message" { | ||
COMMAND="$API_TO_GO --help" | ||
run eval "$COMMAND" | ||
[ "$status" -eq 0 ] | ||
[ "${lines[0]}" = "Usage: api-to-go [options] <url> [body]" ] | ||
} |
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,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
assert_files_match() { | ||
local generated_file="./$BASE_HOST$1" | ||
local fixture_file="./fixture/$BASE_HOST$1" | ||
|
||
diff_output=$(diff "$generated_file" "$fixture_file") | ||
diff_status=$? | ||
|
||
[ "$diff_status" -eq 0 ] | ||
} |
Oops, something went wrong.