Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added end-to-end tests for money in promotions, delivery methods and commission rates

Damian Legawiec4d51f67e00b2
diff --git a/packages/dashboard/e2e/commission-rates.spec.ts b/packages/dashboard/e2e/commission-rates.spec.ts
index d3d3234c42..66550bd7ae 100644
--- a/packages/dashboard/e2e/commission-rates.spec.ts
+++ b/packages/dashboard/e2e/commission-rates.spec.ts
@@ -33,6 +33,50 @@ test.describe('commission rates', () => {
await expect(row.getByText(/^15(\.0+)?%$/)).toBeVisible({ timeout: 15_000 })
})
+ // Amounts and rates go to the API as exact decimal strings, so each one
+ // must read back as typed when the rate is reopened.
+ test('keeps a flat fee per currency exactly', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, COMMISSION_RATES_PATH(creds.store_id), CTA)
+
+ const name = `E2E Flat Commission ${Date.now()}`
+ await page.getByRole('button', { name: CTA }).click()
+ await page.locator('#name').fill(name)
+ await page.locator('#kind').click()
+ await page.getByRole('option', { name: /^flat fee$/i }).click()
+ await page.getByRole('dialog').getByLabel('USD', { exact: true }).fill('1.25')
+ await page.getByRole('button', { name: /create commission rate/i }).click()
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ await expect(page.getByRole('dialog').getByLabel('USD', { exact: true })).toHaveValue('1.25', {
+ timeout: 15_000,
+ })
+ })
+
+ test('keeps a percentage with its floor, cap and tax exactly', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, COMMISSION_RATES_PATH(creds.store_id), CTA)
+
+ const name = `E2E Bounded Commission ${Date.now()}`
+ await page.getByRole('button', { name: CTA }).click()
+ const sheet = page.getByRole('dialog')
+ await page.locator('#name').fill(name)
+ await page.locator('#value').fill('12.5')
+ await sheet.getByLabel('USD Minimum', { exact: true }).fill('0.50')
+ await sheet.getByLabel('USD Maximum', { exact: true }).fill('25.00')
+ await page.locator('#commission_tax_rate').fill('7.125')
+ await page.getByRole('button', { name: /create commission rate/i }).click()
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ const reopened = page.getByRole('dialog')
+ await expect(page.locator('#value')).toHaveValue('12.5', { timeout: 15_000 })
+ await expect(reopened.getByLabel('USD Minimum', { exact: true })).toHaveValue('0.50')
+ await expect(reopened.getByLabel('USD Maximum', { exact: true })).toHaveValue('25.00')
+ await expect(page.locator('#commission_tax_rate')).toHaveValue('7.125')
+ })
+
test('deletes a rate after confirming', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, COMMISSION_RATES_PATH(creds.store_id), CTA)
diff --git a/packages/dashboard/e2e/delivery-settings.spec.ts b/packages/dashboard/e2e/delivery-settings.spec.ts
index c4f408876e..4b16db8193 100644
--- a/packages/dashboard/e2e/delivery-settings.spec.ts
+++ b/packages/dashboard/e2e/delivery-settings.spec.ts
@@ -361,7 +361,7 @@ test.describe('delivery profiles', () => {
// A method left on the default would reopen as Internal whether or not the
// stored provider round-tripped, so pick the other built-in one.
- test('prices a method through the freight rate provider, and it reopens that way', async ({
+ test('prices a method through the freight rate provider with a markup, and it reopens that way', async ({
page,
}) => {
const creds = await login(page)
@@ -385,6 +385,9 @@ test.describe('delivery profiles', () => {
await rateProvider.click()
await page.getByRole('option', { name: /^freight$/i }).click()
await expect(rateProvider).toContainText(/^freight$/i)
+ // A provider-priced method carries the store's markup on top of the quote.
+ await sheet.locator('#markup_percent').fill('7.5')
+ await sheet.locator('#markup_flat').fill('2.50')
await page.getByRole('button', { name: /create delivery method/i }).click()
await expect(page.getByRole('heading', { name: /new delivery method/i })).toHaveCount(0, {
@@ -392,9 +395,11 @@ test.describe('delivery profiles', () => {
})
await page.getByText(methodName).click()
- await expect(fieldSelect(page.getByRole('dialog'), 'Rate provider')).toContainText(
- /^freight$/i,
- { timeout: 15_000 },
- )
+ const reopened = page.getByRole('dialog')
+ await expect(fieldSelect(reopened, 'Rate provider')).toContainText(/^freight$/i, {
+ timeout: 15_000,
+ })
+ await expect(reopened.locator('#markup_percent')).toHaveValue('7.5')
+ await expect(reopened.locator('#markup_flat')).toHaveValue('2.50')
})
})
diff --git a/packages/dashboard/e2e/promotions.spec.ts b/packages/dashboard/e2e/promotions.spec.ts
index 06096b4e79..a293c29eb1 100644
--- a/packages/dashboard/e2e/promotions.spec.ts
+++ b/packages/dashboard/e2e/promotions.spec.ts
@@ -412,6 +412,72 @@ test.describe('promotions', () => {
await submitCreate(page, name)
})
+ // Money goes to the API as an exact decimal string; each value must read
+ // back as typed after the promotion is saved and reloaded.
+ test('keeps a flat rate amount and an item total minimum exactly', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Money Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickRule(page, /^item total\b/i)
+ await page.getByRole('dialog').locator('#preference-amount_min').fill('50.25')
+ await saveEditor(page)
+
+ await pickAction(page, /^create whole-order adjustment\b/i)
+ const calculatorSelect = page.locator('#calculator-type')
+ await expect(calculatorSelect).toBeEnabled({ timeout: 10_000 })
+ await calculatorSelect.click()
+ await page.getByRole('option', { name: /^flat rate$/i }).click()
+ await page.getByRole('dialog').locator('#preference-amount').fill('12.50')
+ await saveEditor(page)
+
+ await submitCreate(page, name)
+ await page.reload()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await openAdjustmentAction(page, /flat rate/i)
+ // Preferences carry no currency of their own, so the value reads back
+ // without trailing zeros.
+ await expect(page.getByRole('dialog').locator('#preference-amount')).toHaveValue(/^12\.50?$/)
+ await cancelEditor(page)
+
+ await page
+ .locator('div.items-stretch')
+ .filter({ hasText: /^item total/i })
+ .first()
+ .getByRole('button')
+ .first()
+ .click()
+ await expect(page.getByRole('dialog').locator('#preference-amount_min')).toHaveValue('50.25', {
+ timeout: 5_000,
+ })
+ })
+
+ test('keeps a flat percent discount exactly', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Percent Promo ${Date.now()}`
+ await startNewPromotion(page, creds.store_id, name)
+
+ await pickAction(page, /^create whole-order adjustment\b/i)
+ const calculatorSelect = page.locator('#calculator-type')
+ await expect(calculatorSelect).toBeEnabled({ timeout: 10_000 })
+ await calculatorSelect.click()
+ await page.getByRole('option', { name: /^flat percent$/i }).click()
+ await page.getByRole('dialog').locator('#preference-flat_percent').fill('7.5')
+ await saveEditor(page)
+
+ await submitCreate(page, name)
+ await page.reload()
+ await expect(page.getByRole('heading', { name })).toBeVisible({ timeout: 15_000 })
+
+ await openAdjustmentAction(page, /flat percent/i)
+ await expect(page.getByRole('dialog').locator('#preference-flat_percent')).toHaveValue('7.5')
+ })
+
test('saves the tiers of a tiered calculator, lowest threshold first', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, PROMOTIONS_PATH(creds.store_id), CTA)