Challenge #8: Infinite Responses
The embedded stub is currently programmed so that, for any given endpoint, it always returns the same response. In the next challenge, you’ll add the ability to optionally change that behavior. In this challenge, you’ll write a test to document and preserve the current behavior.
Instructions
1. In the "provides an infinite number of responses when an endpoint has one response configured"
test:
- Assert that, when multiple requests are made of the same endpoint, the same response comes back each time.
- The test should pass without needing changes to the production code.
Remember to commit your changes when you’re done.
API Documentation
No new methods.
JavaScript Primers
No new concepts.
Hints
1
The test needs to configure an endpoint, then make multiple requests and assertions against it.
This is similar to previous tests.
it("provides an infinite number of responses when an endpoint has one response configured", async () => {
const client = HttpClient.createNull({
"/endpoint": { status: 200, headers: { myheader: "myValue" }, body: "my body" },
});
const { response: response1 } = await requestAsync({ client, path: "/endpoint" });
const { response: response2 } = await requestAsync({ client, path: "/endpoint" });
assert.deepEqual(response1, {
status: 200,
headers: { myheader: "myValue" },
body: "my body",
});
assert.deepEqual(response2, {
status: 200,
headers: { myheader: "myValue" },
body: "my body",
});
});
Complete Solution
Test code:
it("provides an infinite number of responses when an endpoint has one response configured", async () => {
const client = HttpClient.createNull({
"/endpoint": { status: 200, headers: { myheader: "myValue" }, body: "my body" },
});
const { response: response1 } = await requestAsync({ client, path: "/endpoint" });
const { response: response2 } = await requestAsync({ client, path: "/endpoint" });
assert.deepEqual(response1, {
status: 200,
headers: { myheader: "myValue" },
body: "my body",
});
assert.deepEqual(response2, {
status: 200,
headers: { myheader: "myValue" },
body: "my body",
});
});
The production code is unchanged.