ladjs / supertest

🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
MIT License
13.75k stars 758 forks source link

how to set signed cookies in supertest? #665

Open AlirezaTaji6 opened 4 years ago

AlirezaTaji6 commented 4 years ago

I wrote a test and the router just get signed cookies but I can't set signed cookie for my request

manfrinmm commented 3 years ago

I throught the same problem. My solution was make a request to sign in:

const { cpf: login } = await CustomerFactory.merge({ password: "secret" }).create();

const credentials = {
  login,
  password: "secret",
};

// Make request to login   
const response = await request.post("/customers/sessions").send(credentials);

// Get cookies from response
const { header } = response;

// Make request to a private route
const response_with_cookies = await request
    .put("/customers/profiles")
    .set("Cookie", [...header["set-cookie"]]) // this line I add cookies...
    .send(customer_updated);

I hope it helped...