Closed meghfossa closed 6 months ago
I found the solution - for future readers - all you need to do is create additional mock/when/then. Note that it will throw 404, if data does not match
fn make_server(server: &mut MockServer) {
let chunk_1: Vec<_> = (0..=99).collect();
let chunk_2: Vec<_> = (100..=105).collect();
server.mock(|when, then| {
when.method(POST)
.path("/api")
.header("content-type", "application/json")
.header("authorization", "Bearer secret")
.json_body(json!({"components": chunk_1}));
then.status(201)
.header("content-type", "text")
.body("Applied!");
});
server.mock(|when, then| {
when.method(POST)
.path("/api")
.header("content-type", "application/json")
.header("authorization", "Bearer secret")
.json_body(json!({"components": chunk_2}));
then.status(201)
.header("content-type", "text")
.body("Applied!");
});
}
Exactly. For more complex expectation checking there is also matches.
I want to make POST on some
/api
multiple times, and make assertion that both requests were made correctly. Context is, I'm making chunked requests (say 100 items in each/api
request). I want to test that, if I submit 102 items, I see two requests - first one with 100 items, and second with 2 items. I'm not sure how to accomplish this correctly in this library.I'm happy to contribute with F.A.Q or code comment if I can get this resolved.