Skip to content

Commit 8fee416

Browse files
committed
Make cookie test less brittle
Signed-off-by: Alan Cha <[email protected]>
1 parent e05816f commit 8fee416

File tree

7 files changed

+16
-10
lines changed

7 files changed

+16
-10
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_js:
55
- "9"
66
- "10"
77
- "11"
8+
- "12"
89

910
os:
1011
- linux

packages/openapi-to-graphql/lib/preprocessor.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/lib/preprocessor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"aedes": "^0.40.1",
8989
"aedes-persistence": "^7.2.1",
9090
"body-parser": "^1.18.3",
91+
"cookie-parser": "^1.4.5",
9192
"express": "^4.16.4",
9293
"express-graphql": "^0.9.0",
9394
"glob": "^7.1.3",

packages/openapi-to-graphql/test/example_api.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ test('Get response with cookies', () => {
606606
return graphql(createdSchema, query).then(result => {
607607
expect(result).toEqual({
608608
data: {
609-
cookie:
610-
'Thanks for your cookie preferences: "cookie_type=chocolate chip; cookie_size=mega-sized; "'
609+
cookie: `You ordered a mega-sized chocolate chip cookie!`
611610
}
612611
})
613612
})

packages/openapi-to-graphql/test/example_api_server.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ function startServer(PORT) {
1515
const app = express()
1616

1717
const bodyParser = require('body-parser')
18+
const cookieParser = require('cookie-parser')
19+
1820
app.use(bodyParser.text())
1921
app.use(bodyParser.json())
22+
app.use(cookieParser())
2023

2124
const Users = {
2225
arlene: {
@@ -477,13 +480,15 @@ function startServer(PORT) {
477480
app.get('/api/cookie', (req, res) => {
478481
console.log(req.method, req.path, req.query, req.headers)
479482

480-
if ('cookie' in req.headers) {
483+
if (req.cookies && req.cookies.cookie_type && req.cookies.cookie_size) {
481484
res
482485
.set('Content-Type', 'text/plain')
483486
.status(200)
484-
.send(`Thanks for your cookie preferences: "${req.headers.cookie}"`)
487+
.send(
488+
`You ordered a ${req.cookies.cookie_size} ${req.cookies.cookie_type} cookie!`
489+
)
485490
} else {
486-
res.status(400).send('Need Cookie header parameter')
491+
res.status(400).send('Need cookie header parameter')
487492
}
488493
})
489494

packages/openapi-to-graphql/test/fixtures/example_oas7.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"description": "The location of the local test server.",
2727
"variables": {
2828
"port": {
29-
"default": "3008"
29+
"default": "3007"
3030
},
3131
"basePath": {
3232
"default": "api"

0 commit comments

Comments
 (0)