-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Allow multiple responses for a unique request ID #129
feat: Allow multiple responses for a unique request ID #129
Conversation
This allows multiple responses to be recorded for the same request
|
@tvsbrent Pinging you on this to see if you have any feedback. |
tvsbrent
left a comment
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.
Thanks so much for this submission! We did have one suggestion that should make it easier to introduce this change.
| data.responseCollections.forEach(entry => { | ||
| const responseCollection = new PlaybackResponseCollection(entry); | ||
| this.#responseCollections.set(responseCollection.id, responseCollection); |
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.
suggestion: We were discussing an approach that would keep us from having to introduce this as a breaking change. It's honestly something I should have thought of before, but here in the deserialize method for the PlaybackRequestMatcher, we could put in code to migrate the responses field into the responseCollections field.
I don't think such a migration would be that difficult. (Although, I've been wrong more than once!) Some pseudo-code below:
if (data.responses) {
data.responses.forEach(entry => {
const { id, url, ...rest } = entry;
// This should match the shape that the response collection constructor/deserialize method expects
const responseCollection = new PlaybackResponseCollection({ id, url, responses: [rest] });
this.#responseCollection.set(responseCollection.id, responseCollection);
});
} else {
// Other deserialization code here.
...
}|
Your suggestion seems to work. I implemented it and added a few tests. |
Summary
This change allows multiple responses to be recorded for the same request.
For example, if an app makes a GET request to the endpoint
/todo/1it will record the response within a response collection for the calculated request ID.Any subsequent responses for the same GET requests will be pushed into the response collection for that calculated request ID.
This allows the plugin to support the case described in the issue. Where a later request for an entity results in a different response.
Related Issue(s)
Issue #128
Checklist