Skip to content

Commit 972437e

Browse files
authored
Merge pull request #3529 from SalesforceCommerceCloud/add-non-streaming-endpoint
@W-20313656: Ref App endpoint to support streaming testing
2 parents 6b34fdb + a47947d commit 972437e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/template-mrt-reference-app/app/ssr.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ const ssrShared = async (req, res) => {
232232
}
233233
}
234234

235+
/**
236+
* Express handler that returns a non-streaming response.
237+
*/
238+
const streamingLarge = (req, res) => {
239+
res.status(200)
240+
res.json({streaming: false})
241+
}
242+
235243
/**
236244
* Express handler that allocates a lot of memory, and then removes
237245
* a reference to the objects, such that they may be garbage collected.
@@ -380,6 +388,7 @@ const {handler, app, server} = runtime.createHandler(options, (app) => {
380388
// before we invoke the handlers)
381389
app.use((req, res, next) => {
382390
res.set('Cache-Control', 'no-cache')
391+
res.set('Server', 'mrt ref app')
383392
return next()
384393
})
385394

@@ -398,6 +407,7 @@ const {handler, app, server} = runtime.createHandler(options, (app) => {
398407
app.get('/isolation', isolationTests)
399408
app.get('/set-response-headers', responseHeadersTest)
400409
app.get('/ssr-shared', ssrShared)
410+
app.get('/streaming-large', streamingLarge)
401411

402412
// Add a /auth/logout path that will always send a 401 (to allow clearing
403413
// of browser credentials)

packages/template-mrt-reference-app/app/ssr.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AccessDenied extends ServiceException {
2424
}
2525

2626
describe('server', () => {
27+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2728
let originalEnv, app, server
2829
const lambdaMock = mockClient(LambdaClient)
2930
const s3Mock = mockClient(S3Client)
@@ -61,7 +62,8 @@ describe('server', () => {
6162
['/multi-cookies', 200, 'application/json; charset=utf-8'],
6263
['/set-response-headers', 200, 'application/json; charset=utf-8'],
6364
['/isolation', 200, 'application/json; charset=utf-8'],
64-
['/memtest', 200, 'application/json; charset=utf-8']
65+
['/memtest', 200, 'application/json; charset=utf-8'],
66+
['/streaming-large', 200, 'application/json; charset=utf-8']
6567
])('Path %p should render correctly', (path, expectedStatus, expectedContentType) => {
6668
return request(app)
6769
.get(path)
@@ -77,6 +79,10 @@ describe('server', () => {
7779
return request(app).get('/cache/123').expect('Cache-Control', 's-maxage=123')
7880
})
7981

82+
test('All responses have Server header set to "mrt ref app"', () => {
83+
return request(app).get('/').expect('Server', 'mrt ref app')
84+
})
85+
8086
test('Path "/headers" echoes request headers', async () => {
8187
const response = await request(app).get('/headers').set('Random-Header', 'random')
8288

@@ -171,4 +177,10 @@ describe('server', () => {
171177
'This file is used in the E2E tests to verify that correct header values are set.'
172178
)
173179
})
180+
181+
test('Path "/streaming-large" returns streaming: false', async () => {
182+
const response = await request(app).get('/streaming-large')
183+
expect(response.status).toBe(200)
184+
expect(response.body).toEqual({streaming: false})
185+
})
174186
})

0 commit comments

Comments
 (0)