withSession method
A copy of this client that works like a browser with a session:
- it keeps the cookies of every response (
Set-Cookie) and sends them back. A cookie with an empty value,Max-Age=0or an oldExpiresdate is removed. - on
POST,PUT,PATCHandDELETEit sends theXSRF-TOKENcookie in theX-XSRF-TOKENheader, like axios and Inertia. SoCsrfMiddlewarelets the request in.
Each call gives a new browser with no cookies. Copies made from it (eg. with withHeaders) share its cookies.
DoxTestClient browser = client.withSession();
await browser.get('/login'); // gets the session and XSRF-TOKEN cookies
TestResponse res = await browser.post('/login', body: form);
res.expectStatus(302).expectHeader('location', '/dashboard');
(await browser.get('/dashboard')).expectStatus(200);
Implementation
DoxTestClient withSession() {
return DoxTestClient._copy(baseUri, headers, _http, <String, String>{});
}