* chore: rename js files to txt * chore: rename ts files to txt * chore: delete environment helpers * chore: convert global setup & teardown to txt * chore: rename helper js/ts files to txt * chore: rename seeder js/ts files to txt * chore: remove typeorm * chore: reintroduce used helpers
111 lines
2.6 KiB
Plaintext
111 lines
2.6 KiB
Plaintext
const path = require("path")
|
|
|
|
const setupServer = require("../../../environment-helpers/setup-server")
|
|
const { useApi } = require("../../../environment-helpers/use-api")
|
|
const { useDb, initDb } = require("../../../environment-helpers/use-db")
|
|
const {
|
|
simpleRegionFactory,
|
|
simpleProductFactory,
|
|
simpleShippingTaxRateFactory,
|
|
simpleShippingOptionFactory,
|
|
} = require("../../../factories")
|
|
|
|
const adminSeeder = require("../../../helpers/admin-seeder")
|
|
|
|
jest.setTimeout(30000)
|
|
|
|
describe("Shipping Options Totals Calculations", () => {
|
|
let medusaProcess
|
|
let dbConnection
|
|
|
|
beforeAll(async () => {
|
|
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
|
dbConnection = await initDb({ cwd })
|
|
medusaProcess = await setupServer({ cwd })
|
|
})
|
|
|
|
afterAll(async () => {
|
|
const db = useDb()
|
|
await db.shutdown()
|
|
|
|
medusaProcess.kill()
|
|
})
|
|
|
|
beforeEach(async () => {
|
|
await adminSeeder(dbConnection)
|
|
})
|
|
|
|
afterEach(async () => {
|
|
const db = useDb()
|
|
await db.teardown()
|
|
})
|
|
|
|
it("admin gets correct shipping prices", async () => {
|
|
const api = useApi()
|
|
|
|
const region = await simpleRegionFactory(dbConnection, {
|
|
tax_rate: 25,
|
|
})
|
|
const so = await simpleShippingOptionFactory(dbConnection, {
|
|
region_id: region.id,
|
|
price: 100,
|
|
})
|
|
await simpleShippingTaxRateFactory(dbConnection, {
|
|
shipping_option_id: so.id,
|
|
rate: {
|
|
region_id: region.id,
|
|
rate: 10,
|
|
},
|
|
})
|
|
|
|
const res = await api.get(`/admin/shipping-options`, {
|
|
headers: {
|
|
"x-medusa-access-token": "test_token",
|
|
},
|
|
})
|
|
|
|
expect(res.data.shipping_options).toHaveLength(1)
|
|
expect(res.data.shipping_options).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: so.id,
|
|
amount: 100,
|
|
price_incl_tax: 110,
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
|
|
it("gets correct shipping prices", async () => {
|
|
const api = useApi()
|
|
|
|
const region = await simpleRegionFactory(dbConnection, {
|
|
tax_rate: 25,
|
|
})
|
|
const so = await simpleShippingOptionFactory(dbConnection, {
|
|
region_id: region.id,
|
|
price: 100,
|
|
})
|
|
await simpleShippingTaxRateFactory(dbConnection, {
|
|
shipping_option_id: so.id,
|
|
rate: {
|
|
region_id: region.id,
|
|
rate: 10,
|
|
},
|
|
})
|
|
|
|
const res = await api.get(`/store/shipping-options?region_id=${region.id}`)
|
|
|
|
expect(res.data.shipping_options).toHaveLength(1)
|
|
expect(res.data.shipping_options).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
id: so.id,
|
|
amount: 100,
|
|
price_incl_tax: 110,
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
})
|