mercredi 10 février 2021

Adonis session not persisting while testing

I've built a simple eCommerce application on Adonis JS. I'm trying to test the cart functionality where if the user adds an item to the cart and if it's already there in the cart, then it should simply increase the quantity. For this, I'm hitting the cart API twice to check the functionality. However, my session isn't persisted between requests because of which each time I receive only one quantity.

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

Aucun commentaire:

Enregistrer un commentaire