chore(tests): Try to use the api integration tests for v2 (#6588)

Few things to keep in mind:
1. You need to set MEDUSA_FF_MEDUSA_V2 to true before running the tests to run with the v2 API
2. You can use the `breaking` function to differentiate between v1 and v2 differences. This can help us identify what was breaking pretty quickly afterwards
3. You will need to run specific tests for now instead of all if you want to target v2. I think that's fine though, as we don't really need these to run on every PR until we have feature parity (and by then, all tests would be both v1 and v2 compatible)


**note: Adrien** 
- add a new way to load modules only to run their loaders comparable to the way to run the migrations only
- improve tests runner to cleanup the data properly as well as re running all loaders and core defaults

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
Stevche Radevski
2024-03-07 08:05:43 +00:00
committed by GitHub
co-authored by Adrien de Peretti
parent 000eb61e33
commit 12b035cb18
76 changed files with 773 additions and 371 deletions
@@ -30,6 +30,14 @@ moduleIntegrationTestRunner({
})
})
it("should fail to get created if default currency code is not in list of supported currency codes", async function () {
const err = await service
.create({ ...createStoreFixture, default_currency_code: "jpy" })
.catch((err) => err.message)
expect(err).toEqual("Store does not have currency: jpy")
})
describe("upserting a store", () => {
it("should get created if it does not exist", async function () {
const store = await service.upsert(createStoreFixture)
@@ -67,6 +75,45 @@ moduleIntegrationTestRunner({
})
expect(updatedStore.title).toEqual("Updated store")
})
it("should fail updating default currency code to an unsupported one", async function () {
const createdStore = await service.create(createStoreFixture)
const updateErr = await service
.update(createdStore.id, {
default_currency_code: "jpy",
})
.catch((err) => err.message)
expect(updateErr).toEqual("Store does not have currency: jpy")
})
it("should fail updating default currency code to an unsupported one if the supported currencies are also updated", async function () {
const createdStore = await service.create(createStoreFixture)
const updateErr = await service
.update(createdStore.id, {
supported_currency_codes: ["mkd"],
default_currency_code: "jpy",
})
.catch((err) => err.message)
expect(updateErr).toEqual("Store does not have currency: jpy")
})
it("should fail updating supported currencies if one of them is used as a default one", async function () {
const createdStore = await service.create({
...createStoreFixture,
default_currency_code: "eur",
})
const updateErr = await service
.update(createdStore.id, {
supported_currency_codes: ["jpy"],
})
.catch((err) => err.message)
expect(updateErr).toEqual(
"You are not allowed to remove default currency from store currencies without replacing it as well"
)
})
})
describe("deleting a store", () => {