Adonis 会话不会在测试之间持续存在

Adonis session not persisting between tests

我在 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);
});

方法是使用 supertest

const supertest = require('supertest');

test('should increase the quantity if user tries to add the same item to cart', async ({ assert, client }) => {

    const BASE_URL = 'http://localhost:4000';
    const agent = supertest.agent(BASE_URL);

    const menu = await createMenu(client);

    // Simply adds to cart
    const result1 = await agent.post(`/cart/${menu.id}`).send({
            quantity: 1,
    }).withCredentials();

    assert.equal(result1.status, 200);

    // It should increase the quantity to 2 now.
    const result2 = await agent.post(`/cart/${menu.id}`).send({
            quantity: 1,
    }).withCredentials();

    assert.equal(result2.status, 200);
    // There should be only one item in cart
    assert.equal(result2.body.data.items.length, 1);
    // And quantity of that item should be 2.
    assert.equal(result2.body.data.items[0].quantity, 2);
});