supertest icon indicating copy to clipboard operation
supertest copied to clipboard

how to set signed cookies in supertest?

Open AlirezaTaji6 opened this issue 5 years ago • 1 comments

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

AlirezaTaji6 avatar Jul 29 '20 23:07 AlirezaTaji6

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...

manfrinmm avatar Nov 19 '20 14:11 manfrinmm