【发布时间】:2021-05-14 21:38:31
【问题描述】:
我在 Adonis JS 上构建了一个简单的电子商务应用程序。我正在尝试测试购物车功能,如果用户将商品添加到购物车并且它已经在购物车中,那么它应该只是增加数量。为此,我两次点击购物车 API 来检查功能。但是,我的会话不会在请求之间持续存在,因此每次我只收到一个数量。
test('should increase the quantity if user tries to add the same item to cart', async ({ assert, client }) => {
const menu = await createMenu(client);
// Simply adds to cart
await client.post(`/cart/${menu.id}`).send({
quantity: 1,
}).end();
// It should increase the quantity to 2 now.
const response = await client.post(`/cart/${menu.id}`).send({
quantity: 1,
}).end();
response.assertStatus(200);
// There should be only one item in cart
assert.equal(response.body.data.items.length, 1);
// And quantity of that item should be 2.
assert.equal(response.body.data.items[0].quantity, 2);
});
【问题讨论】:
标签: node.js session testing adonis.js