-
Notifications
You must be signed in to change notification settings - Fork 43
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
🐛 Address required status bug #1843
Conversation
07f865f
to
fc6c538
Compare
Signed-off-by: Ian Bolton <[email protected]>
7c2888d
to
8c94ee8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good, and I like the unit test!
I think the unit test could be rearranged to keep a single server.use()
in place.
rest.get("/hub/assessments", (req, res, ctx) => { | ||
return res( | ||
ctx.json([ | ||
createMockAssessment({ | ||
id: 1, | ||
application: { id: 1, name: "app1" }, | ||
questionnaire: { id: 1, name: "questionnaire1" }, | ||
status: "started", | ||
required: false, | ||
sections: [], | ||
}), | ||
createMockAssessment({ | ||
id: 2, | ||
application: { id: 1, name: "app1" }, | ||
questionnaire: { id: 2, name: "questionnaire2" }, | ||
status: "complete", | ||
required: false, | ||
sections: [], | ||
}), | ||
]) | ||
); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the second set of handlers is a bit confusing.
I suggest just doing a use once kind of setup so it is more obvious that the data will change on the second request.
This may work (not tested):
rest.get("/hub/assessments", (req, res, ctx) => {
return res.once(
// first json
);
})
rest.get("/hub/assessments", (req, res, ctx) => {
return res(
// json for the rest of the time
);
})
See: https://v1.mswjs.io/docs/api/setup-server/use#one-time-override
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I just found you can use a generator function in this case -- way cooler:
mswjs/msw#1117 (reply in thread)
It points at this bit of code for more examples: https://github.com/mswjs/msw/blob/6990c3a57a1f515fe977c2eaa7741005b885b8af/test/rest-api/generator.mocks.ts#L4
//cc @rszwajko
Resolves https://issues.redhat.com/browse/MTA-2505 - Adds additional unit test coverage Signed-off-by: Ian Bolton <[email protected]> Signed-off-by: Cherry Picker <[email protected]>
Resolves https://issues.redhat.com/browse/MTA-2505 - Adds additional unit test coverage Backport-of: #1843 Signed-off-by: Ian Bolton <[email protected]> Signed-off-by: Cherry Picker <[email protected]>
Resolves https://issues.redhat.com/browse/MTA-2505