Skip to content

Commit

Permalink
- add integration test for onResponseBody
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 committed Sep 18, 2024
1 parent 1a1ecc4 commit 379dd34
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/core/snapshots/test-on-response-body.md_0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: tests/core/spec.rs
expression: response
---
{
"status": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"data": {
"hello": {
"name": "Leanne Graham - Changed by JS"
}
}
}
}
52 changes: 52 additions & 0 deletions tests/core/snapshots/test-on-response-body.md_client.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
source: tests/core/spec.rs
expression: formatted
---
scalar Bytes

scalar Date

scalar DateTime

scalar Email

scalar Empty

scalar Int128

scalar Int16

scalar Int32

scalar Int64

scalar Int8

scalar JSON

scalar PhoneNumber

type Query {
hello: User!
}

scalar UInt128

scalar UInt16

scalar UInt32

scalar UInt64

scalar UInt8

scalar Url

type User {
id: Int!
name: String!
}

schema {
query: Query
}
16 changes: 16 additions & 0 deletions tests/core/snapshots/test-on-response-body.md_merged.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: tests/core/spec.rs
expression: formatter
---
schema @server @upstream(baseURL: "https://jsonplaceholder.typicode.com") @link(src: "test.js", type: Script) {
query: Query
}

type Query {
hello: User! @http(path: "/users/1", onResponseBody: "onResponse")
}

type User {
id: Int!
name: String!
}
43 changes: 43 additions & 0 deletions tests/execution/test-on-response-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Js Customize the Response with onResponseBody.

```js @file:test.js
function onResponse({response}) {
let body = JSON.parse(response.body);
body.name = body.name + " - Changed by JS";
response.body = JSON.stringify(body);
return {response};
}
```

```graphql @config
schema @server @upstream(baseURL: "https://jsonplaceholder.typicode.com") @link(type: Script, src: "test.js") {
query: Query
}

type Query {
hello: User! @http(path: "/users/1", onResponseBody: "onResponse")
}

type User {
id: Int!
name: String!
}
```

```yml @mock
- request:
method: GET
url: https://jsonplaceholder.typicode.com/users/1
response:
status: 200
body:
id: 1
name: Leanne Graham
```

```yml @test
- method: POST
url: http://localhost:8080/graphql
body:
query: query { hello { name } }
```

0 comments on commit 379dd34

Please sign in to comment.