Skip to content

Commit 2802d30

Browse files
committed
Merge remote-tracking branch 'origin/main' into gqltest-initial
2 parents cbafbe3 + dfd12ca commit 2802d30

File tree

4 files changed

+63
-21
lines changed

4 files changed

+63
-21
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
type Customer {
2-
name: String
3-
city: String
2+
name: String
3+
city: String
44
}
55
type Query {
6-
# An ecmascript generator of customer data.
7-
# Of course, in real life you will call an API or a database. You can do that by changing the `endpoint` argument on the `@rest` directive.
8-
# https://stepzen.com/docs/connecting-backends/how-to-connect-a-rest-service
9-
customer (id: ID): Customer
10-
@rest (endpoint: "stepzen:empty"
11-
ecmascript: """
12-
function transformREST(s) {
13-
var id = get('id')
14-
if (id==1)
15-
return (JSON.stringify({"name":"John Doe","city":"Miami"}))
16-
else
17-
return (JSON.stringify({"name":"Jane Smith","city":"Santa Clara"}))
18-
}
19-
"""
6+
# An ecmascript generator of customer data.
7+
# Of course, in real life you will call an API or a database. You can do that by changing the `endpoint` argument on the `@rest` directive.
8+
# https://stepzen.com/docs/connecting-backends/how-to-connect-a-rest-service
9+
customer(id: ID!): Customer
10+
@rest(
11+
endpoint: "stepzen:empty"
12+
ecmascript: """
13+
function transformREST(s) {
14+
var id = get('id')
15+
if (id==1)
16+
return (JSON.stringify({"name":"John Doe","city":"Miami"}))
17+
else
18+
return (JSON.stringify({"name":"Jane Smith","city":"Santa Clara"}))
19+
}
20+
"""
2021
)
21-
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
query Customer($id: ID!) {
2+
customer(id: $id) {
3+
name
4+
city
5+
}
6+
}
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require("fs");
2+
const path = require("node:path");
13
const {
24
deployAndRun,
35
authTypes,
@@ -6,8 +8,42 @@ const {
68

79
testDescription = getTestDescription("snippets", __dirname);
810

11+
const requestsFile = path.join(path.dirname(__dirname), "operations.graphql");
12+
const requests = fs.readFileSync(requestsFile, "utf8").toString();
13+
914
describe(testDescription, function () {
15+
// note tests using no authorization since api is public
1016
const tests = [
11-
]
17+
{
18+
label: "customer-1",
19+
query: requests,
20+
operationName: "Customer",
21+
variables: {
22+
id: 1,
23+
},
24+
expected: {
25+
customer: {
26+
name: "John Doe",
27+
city: "Miami",
28+
},
29+
},
30+
authType: authTypes.noAuth,
31+
},
32+
{
33+
label: "customer-2",
34+
query: requests,
35+
operationName: "Customer",
36+
variables: {
37+
id: 2,
38+
},
39+
expected: {
40+
customer: {
41+
name: "Jane Smith",
42+
city: "Santa Clara",
43+
},
44+
},
45+
authType: authTypes.noAuth,
46+
},
47+
];
1248
return deployAndRun(__dirname, tests);
13-
});
49+
});

tests/gqltest.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ async function runGqlOk(authType, endpoint, query, variables, operationName, exp
5656
case authTypes.apiKey:
5757
headers.withAPIKey(apiKey);
5858
break;
59-
// Have not implemented jwt and noAuth yet
59+
// Have not implemented jwt yet
6060
case authTypes.jwt:
6161
case authTypes.noAuth:
6262
default:
63-
authValue = "";
6463
}
6564
await executeOK({
6665
test: this,

0 commit comments

Comments
 (0)