Repository: medusajs/medusa
File: integration-tests/http/__tests__/cart/store/cart.spec.ts (TypeScript)

Code before:
                  adjustments: [],
                }),
              ]),
            })
          )
        })

        it("should throw an error when adding a promotion that does not exist", async () => {
          const invalidPromoCode = "SOME_INVALID_PROMO_CODE"

          try {
            await api.post(
              `/store/carts/${cart.id}/promotions`,
              { promo_codes: [invalidPromoCode] },
              storeHeaders
            )
            fail()
          } catch (e) {
            expect(e.response.status).toEqual(400)
            expect(e.response.data.type).toEqual("invalid_data")
            expect(e.response.data.message).toEqual(
              `The promotion code ${invalidPromoCode} is invalid`
            )
          }
        })

        it("should remove promotion adjustments when promotion is deleted", async () => {
          let cartBeforeRemovingPromotion = (
            await api.get(`/store/carts/${cart.id}`, storeHeaders)
          ).data.cart

          expect(cartBeforeRemovingPromotion).toEqual(
            expect.objectContaining({
              id: cart.id,
              items: expect.arrayContaining([
                expect.objectContaining({
                  adjustments: expect.arrayContaining([
                    expect.objectContaining({
                      id: expect.any(String),
                      code: "PROMOTION_APPLIED",
                      promotion_id: promotion.id,
                      amount: 100,
                    }),
                  ]),
                }),
              ]),
            })
          )

          await api.delete(`/admin/promotions/${promotion.id}`, adminHeaders)


Review comment (bug):
suggestion: you can grab the error and check it outside the try catch.

`const { response } = await api.post(...).catch((e) => e)`

generally speaking, ideally we avoid using `try/catch` on tests to avoid hiding errors. And we don't have to safeguard it with `fail` 

Code after:
                  adjustments: [],
                }),
              ]),
            })
          )
        })

        it("should throw an error when adding a promotion that does not exist", async () => {
          const invalidPromoCode = "SOME_INVALID_PROMO_CODE"

          const { response } = await api
            .post(
              `/store/carts/${cart.id}/promotions`,
              { promo_codes: [invalidPromoCode] },
              storeHeaders
            )
            .catch((e) => e)

          expect(response.status).toEqual(400)
          expect(response.data.type).toEqual("invalid_data")
          expect(response.data.message).toEqual(
            `The promotion code ${invalidPromoCode} is invalid`
          )
        })

        it("should remove promotion adjustments when promotion is deleted", async () => {
          let cartBeforeRemovingPromotion = (
            await api.get(`/store/carts/${cart.id}`, storeHeaders)
          ).data.cart

          expect(cartBeforeRemovingPromotion).toEqual(
            expect.objectContaining({
              id: cart.id,
              items: expect.arrayContaining([
                expect.objectContaining({
                  adjustments: expect.arrayContaining([
                    expect.objectContaining({
                      id: expect.any(String),
                      code: "PROMOTION_APPLIED",
                      promotion_id: promotion.id,
                      amount: 100,
                    }),
                  ]),
                }),
              ]),
            })
          )

          await api.delete(`/admin/promotions/${promotion.id}`, adminHeaders)

          let response = await api.post(