I was trying to use the Node.js supertest to test some REST API.
request(app)
.post("/products")
.set(
"Authorization",
"Bearer my jwt token here"
)
.set("Content-Type", "multipart/form-data")
.field("name", "Tomato")
.field("userId", "5d921d306e96d70a28989127")
.attach(
"productImage",
"D:/NodeJS/node-rest-shop/uploads/1558612339690managing-redis.jpg"
)
.expect(201)
.then(res => {
const body = res.body;
expect(body).to.contain.property("message");
expect(body).to.contain.property("productId");
expect(body).to.contain.property("date");
expect(body).to.contain.property("user");
expect(body).to.contain.property("request");
done();
})
.catch(err => done(err));
.field("userId", userId)
Is there any way to set the value of userId as a variable without setting a string value? It is a MongoDB object id.
Aucun commentaire:
Enregistrer un commentaire