Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor requestContextPlugin.spec.js to use response headers #176

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions test/requestContextPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe('requestContextPlugin', () => {
function prepareReply() {
return testService.processRequest(requestId).then(() => {
const storedValue = req.requestContext.get('testKey')
reply.status(204).send({
storedValue,
})
reply.status(204).header('storedvalue', storedValue).send()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution LGTM
I preferred the #177 because the 204 status code was not necessary to make the module work, so it was adding confusion and it is better to remove it instead.

If you would like to update this PR adding an clear test such the plugin must keep the context across 20x requests it would be best!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, so something like the plugin must keep the context across 204 requests => then use the headers in a separate case? @Eomm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have added a new case, does it make sense? what changes would you recommend 🤔 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Eomm do you think we can merge this?

})
}

Expand Down Expand Up @@ -58,7 +56,7 @@ describe('requestContextPlugin', () => {
.query({ requestId: 1 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue1')
expect(response.headers.storedvalue).toBe('testValue1')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand All @@ -71,7 +69,7 @@ describe('requestContextPlugin', () => {
.query({ requestId: 2 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue2')
expect(response.headers.storedvalue).toBe('testValue2')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand Down Expand Up @@ -101,9 +99,7 @@ describe('requestContextPlugin', () => {
function prepareReply() {
return testService.processRequest(requestId).then(() => {
const storedValue = req.requestContext.get('testKey')
reply.status(204).send({
storedValue,
})
reply.status(204).header('storedvalue', storedValue).send()
})
}

Expand Down Expand Up @@ -133,7 +129,7 @@ describe('requestContextPlugin', () => {
.body({ requestId: 1 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue1')
expect(response.headers.storedvalue).toBe('testValue1')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand All @@ -146,7 +142,7 @@ describe('requestContextPlugin', () => {
.body({ requestId: 2 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue2')
expect(response.headers.storedvalue).toBe('testValue2')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand Down Expand Up @@ -178,9 +174,7 @@ describe('requestContextPlugin', () => {
function prepareReply() {
return testService.processRequest(requestId.replace('testValue', '')).then(() => {
const storedValue = req.requestContext.get('testKey')
reply.status(204).send({
storedValue,
})
reply.status(204).header('storedvalue', storedValue).send()
})
}

Expand All @@ -207,7 +201,7 @@ describe('requestContextPlugin', () => {
.body({ requestId: 1 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue1')
expect(response.headers.storedvalue).toBe('testValue1')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand All @@ -220,7 +214,7 @@ describe('requestContextPlugin', () => {
.body({ requestId: 2 })
.end()
.then((response) => {
expect(response.json().storedValue).toBe('testValue2')
expect(response.headers.storedvalue).toBe('testValue2')
responseCounter++
if (responseCounter === 2) {
resolveResponsePromise()
Expand Down