Skip to content

Commit 0a3c003

Browse files
committed
test: add tests for mkAllPublic
1 parent e9d0535 commit 0a3c003

File tree

3 files changed

+58
-17
lines changed

3 files changed

+58
-17
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+
}

protection/makeAllPublic/tests/Test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,42 @@ const {
66

77
testDescription = getTestDescription("snippets", __dirname);
88

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

0 commit comments

Comments
 (0)