mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 12:15:38 +00:00
55 lines
981 B
Plaintext
55 lines
981 B
Plaintext
meta {
|
|
name: variables interpolation
|
|
type: graphql
|
|
seq: 3
|
|
}
|
|
|
|
post {
|
|
url: {{host}}/api/echo/json
|
|
body: graphql
|
|
auth: none
|
|
}
|
|
|
|
body:graphql {
|
|
query { __typename }
|
|
}
|
|
|
|
body:graphql:vars {
|
|
{
|
|
"my_json": "{{my_json}}"
|
|
}
|
|
}
|
|
|
|
assert {
|
|
res.status: eq 200
|
|
}
|
|
|
|
script:pre-request {
|
|
const testData = {
|
|
a: [1,2,3],
|
|
b: {
|
|
c: "test",
|
|
d: "another value"
|
|
}
|
|
};
|
|
|
|
// Single escaping
|
|
let cv = JSON.stringify(testData).replace(/"/g, '\\"');
|
|
|
|
bru.setVar("my_json", cv)
|
|
}
|
|
|
|
script:post-response {
|
|
bru.deleteVar("my_json")
|
|
}
|
|
|
|
tests {
|
|
test("GraphQL variables with nested object and array are interpolated then sent as parsed object", function() {
|
|
const body = res.getBody();
|
|
expect(body).to.have.property("variables");
|
|
expect(body.variables).to.be.an("object");
|
|
expect(body.variables).to.have.property("my_json");
|
|
expect(body.variables.my_json).to.eql("{\"a\":[1,2,3],\"b\":{\"c\":\"test\",\"d\":\"another value\"}}");
|
|
});
|
|
}
|