Skip to content

Commit

Permalink
test: Add API collection
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jun 13, 2024
1 parent 7b7edaf commit 5ecea6e
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: taiki-e/install-action@dprint
- uses: taiki-e/install-action@v2
with:
tool: typos-cli
tool: typos-cli,hurlfmt

- name: Check MSRV
run: |
Expand Down
7 changes: 7 additions & 0 deletions docs/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ This repo is using [Agular's commit message format][commit-message]
- Run `just up` to check for outdated dependencies, and then run `just up --write` to update them.
- Upgrade the `cargo-chef` version in the `Dockerfile`.

## Running API collection

```shell
hurl --variables-file props/local meta/meta.hurl | jq
hurl --variables-file props/local meta/meta.hurl --ignore-asserts | jq
```

[commit-message]: https://github.com/angular/angular/blob/2095a08781167e91a60a4cec65c694688b319cd0/CONTRIBUTING.md#-commit-message-format
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ image-restart:
fmt:
cargo fmt --all
dprint fmt
hurlfmt tests/api-collection/**/*.hurl --in-place

# Check is the codebase properly formatted.
fmt-check:
cargo fmt --all -- --check
dprint check
hurlfmt tests/api-collection/**/*.hurl --check

# Lint the codebase.
lint:
Expand Down
17 changes: 17 additions & 0 deletions tests/api-collection/meta/health.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
health {
status
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.health.status" == "running"


21 changes: 21 additions & 0 deletions tests/api-collection/meta/meta.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
meta {
build
version
config {
env
baseUrl
port
}
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.meta.build" == "unknown"
1 change: 1 addition & 0 deletions tests/api-collection/props/local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
base_url=http://127.0.0.1:8001/graphql
2 changes: 2 additions & 0 deletions tests/api-collection/props/prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base_url=http://1.0.0.2:8001/graphql

2 changes: 2 additions & 0 deletions tests/api-collection/props/staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base_url=http://1.0.0.1:8001/graphql

20 changes: 20 additions & 0 deletions tests/api-collection/user/create_user.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST {{base_url}}
Content-Type: application/json

```graphql
mutation {
createUser(input: { name: "aragorn", email: "[email protected]" }) {
id
name
email
fullName
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.createUser.name" == "aragorn"


20 changes: 20 additions & 0 deletions tests/api-collection/user/create_user_without_email.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST {{base_url}}
Content-Type: application/json

```graphql
mutation {
createUser(input: { name: "aragorn" }) {
id
name
email
fullName
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.createUser.name" == "aragorn"


19 changes: 19 additions & 0 deletions tests/api-collection/user/delete_user.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
POST {{base_url}}
Content-Type: application/json

```graphql
mutation {
deleteUser(id: "017eb8d1-a5b5-9443-2d94-b6ad7787bf0e") {
id
name
fullName
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.deleteUser.name" == "frodo"


22 changes: 22 additions & 0 deletions tests/api-collection/user/update_user.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
POST {{base_url}}
Content-Type: application/json

```graphql
mutation {
updateUser(
input: { id: "017eba0e-ca9a-f014-fc85-1cf8a22a8999", name: "frodo" }
) {
id
name
fullName
}
}

```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.updateUser.name" == "frodo"


19 changes: 19 additions & 0 deletions tests/api-collection/user/user.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
user(id: "017eb8d1-a5b5-9443-2d94-b6ad7787bf0e") {
id
name
email
fullName
}
}
```

HTTP/1.1 200
[Asserts]
status == 200


21 changes: 21 additions & 0 deletions tests/api-collection/user/users.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(first: 7) {
edges {
node {
name
}
}
}
}
```

HTTP/1.1 200
[Asserts]
status == 200
jsonpath "$.data.users.edges" isEmpty


21 changes: 21 additions & 0 deletions tests/api-collection/user/users_both_first_and_last.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(first: 3, last: 3) {
edges {
cursor
node {
id
name
}
}
}
}
```

HTTP/1.1 200
[Asserts]
jsonpath "$.errors[0].message" contains "Passing both `first` and `last` for pagination is not supported"

29 changes: 29 additions & 0 deletions tests/api-collection/user/users_first_3.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(first: 3) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
totalCount
}
}
```

HTTP/1.1 200
[Asserts]
status == 200


31 changes: 31 additions & 0 deletions tests/api-collection/user/users_first_3_after_n.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(
first: 2
after: "Q3Vyc29yOjAxN2YyYTlmLWVjNmMtYzk1ZS01MGVhLWUzZWZkMWIxMjZhNw"
) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
```

HTTP/1.1 200
[Asserts]
status == 200


30 changes: 30 additions & 0 deletions tests/api-collection/user/users_invalid_cursor.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(
first: 2
after: "randomZkMWIxMjZhw"
) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
```

HTTP/1.1 200
[Asserts]
jsonpath "$.errors[0].message" contains "Invalid cursor"

31 changes: 31 additions & 0 deletions tests/api-collection/user/users_last_1_before_n.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
POST {{base_url}}
Content-Type: application/json

```graphql
query {
users(
last: 3
before: "Q3Vyc29yOjAxN2YyYTlmLWVjNmMtYzk1ZS01MGVhLWUzZWZkMWIxMjZhNw"
) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
```

HTTP/1.1 200
[Asserts]
status == 200


30 changes: 30 additions & 0 deletions tests/api-collection/user/users_last_3.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
POST {{base_url}}
Content-Type: application/json

```graphql
{
users(last: 3) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
totalCount
}
}

```

HTTP/1.1 200
[Asserts]
status == 200


Loading

0 comments on commit 5ecea6e

Please sign in to comment.