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 purchasing, companies, store credits and post-sale

Claudec786b7b04c94
diff --git a/packages/dashboard/e2e/companies.spec.ts b/packages/dashboard/e2e/companies.spec.ts
new file mode 100644
index 0000000000..38997e6815
--- /dev/null
+++ b/packages/dashboard/e2e/companies.spec.ts
@@ -0,0 +1,160 @@
+import { expect, type Page, test } from '@playwright/test'
+import {
+ FIXTURE_PROMO_CUSTOMER_EMAIL,
+ fillAddressForm,
+ gotoIndex,
+ login,
+ openRowMenu,
+ rowButton,
+} from './helpers'
+
+const COMPANIES_PATH = (storeId: string) => `/${storeId}/companies`
+const CTA = /add company/i
+
+/** One of the detail page's cards, found by its title. */
+function card(page: Page, title: RegExp) {
+ return page
+ .locator('[data-slot="card"]')
+ .filter({ has: page.locator('[data-slot="card-title"]', { hasText: title }) })
+}
+
+/** Creates a company from the list; creating opens its page. */
+async function createCompany(page: Page, storeId: string, name: string) {
+ await gotoIndex(page, COMPANIES_PATH(storeId), CTA)
+ await page.getByRole('button', { name: CTA }).click()
+ await expect(page.getByRole('heading', { name: /^new company$/i })).toBeVisible()
+ await page.locator('#name').fill(name)
+ await page.getByRole('button', { name: /create company/i }).click()
+
+ await expect(page).toHaveURL(/\/companies\/[a-z]+_/, { timeout: 15_000 })
+ await expect(page.getByRole('heading', { name })).toBeVisible()
+}
+
+test.describe('companies', () => {
+ test('creates a company and requires PO numbers on its orders', async ({ page }) => {
+ const creds = await login(page)
+ const name = `E2E Acme ${Date.now()}`
+ await createCompany(page, creds.store_id, name)
+
+ const profile = card(page, /^company$/i)
+ await profile.getByRole('switch', { name: /require a po number/i }).click()
+ await profile.getByRole('button', { name: /^save$/i }).click()
+ await expect(profile.getByRole('button', { name: /^save$/i })).toBeDisabled({
+ timeout: 15_000,
+ })
+
+ await page.reload()
+ await expect(
+ card(page, /^company$/i).getByRole('switch', { name: /require a po number/i }),
+ ).toBeChecked({ timeout: 15_000 })
+ })
+
+ test('adds a division under a company', async ({ page }) => {
+ const creds = await login(page)
+ const name = `E2E Holdings ${Date.now()}`
+ await createCompany(page, creds.store_id, name)
+
+ const subUnits = card(page, /sub-units/i)
+ await expect(subUnits.getByText(/no sub-units yet/i)).toBeVisible()
+ await subUnits.getByRole('button', { name: /add sub-unit/i }).click()
+ const dialog = page.getByRole('dialog')
+ await dialog.locator('#sub-unit-name').fill(`${name} West`)
+ await dialog.getByRole('button', { name: /^create$/i }).click()
+
+ const division = subUnits.getByRole('link', { name: new RegExp(`${name} West`) })
+ await expect(division).toBeVisible({ timeout: 15_000 })
+ await expect(division.getByText(/^division$/i)).toBeVisible()
+
+ // The sub-unit is a node of its own, reached from its parent.
+ await division.click()
+ await expect(page.getByRole('heading', { name: `${name} West` })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+
+ test('adds an existing customer as a member and removes them', async ({ page }) => {
+ const creds = await login(page)
+ await createCompany(page, creds.store_id, `E2E Buyers ${Date.now()}`)
+
+ const members = card(page, /^members/i)
+ await members.getByRole('button', { name: /add member/i }).click()
+ await page.locator('#member-email').fill(FIXTURE_PROMO_CUSTOMER_EMAIL)
+ await page.getByRole('dialog').getByRole('button', { name: /^add$/i }).click()
+
+ const member = members.getByRole('link', { name: FIXTURE_PROMO_CUSTOMER_EMAIL })
+ await expect(member).toBeVisible({ timeout: 15_000 })
+
+ await members.getByRole('button', { name: /actions/i }).click()
+ await page.getByRole('menuitem', { name: /remove member/i }).click()
+ await expect(page.getByRole('heading', { name: /remove this member\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /remove member/i })
+ .click()
+
+ await expect(member).toHaveCount(0, { timeout: 15_000 })
+ await expect(members.getByText(/no members yet/i)).toBeVisible()
+ })
+
+ test('invites an email with no account, then revokes the invitation', async ({ page }) => {
+ const creds = await login(page)
+ await createCompany(page, creds.store_id, `E2E Invites ${Date.now()}`)
+
+ const email = `e2e-company-buyer-${Date.now()}@example.com`
+ const members = card(page, /^members/i)
+ await members.getByRole('button', { name: /add member/i }).click()
+ await page.locator('#member-email').fill(email)
+ await page.getByRole('dialog').getByRole('button', { name: /^add$/i }).click()
+
+ await expect(members.getByText(/pending invitations/i)).toBeVisible({ timeout: 15_000 })
+ await expect(members.getByText(email)).toBeVisible()
+
+ await members.getByRole('button', { name: /revoke invitation/i }).click()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /revoke invitation/i })
+ .click()
+
+ await expect(members.getByText(email)).toHaveCount(0, { timeout: 15_000 })
+ })
+
+ test('adds an address to the address book', async ({ page }) => {
+ const creds = await login(page)
+ await createCompany(page, creds.store_id, `E2E Depots ${Date.now()}`)
+
+ const addressBook = card(page, /^address book/i)
+ await expect(addressBook.getByText(/no addresses yet/i)).toBeVisible()
+ await addressBook.getByRole('button', { name: /add address/i }).click()
+ await expect(page.getByRole('heading', { name: /^new address$/i })).toBeVisible()
+ await fillAddressForm(page, {
+ label: 'Main warehouse',
+ address1: '400 Dock Rd',
+ city: 'Los Angeles',
+ postalCode: '90001',
+ // Country starts at the store's own, the United States.
+ state: 'California',
+ })
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^save$/i })
+ .click()
+
+ await expect(addressBook.getByText('400 Dock Rd')).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a company from the list', async ({ page }) => {
+ const creds = await login(page)
+ const name = `E2E Dissolved ${Date.now()}`
+ await createCompany(page, creds.store_id, name)
+
+ await gotoIndex(page, COMPANIES_PATH(creds.store_id), CTA)
+ await openRowMenu(page, name)
+ await page.getByRole('menuitem', { name: /^delete$/i }).click()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index 430cc7f53b..1db552e1df 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -443,3 +443,59 @@ export async function invitationAcceptancePath(
// Tolerate either path-only (no app origin configured) or an absolute URL.
return acceptance_url.replace(/^https?:\/\/[^/]+/, '')
}
+
+/**
+ * A placed, paid and shipped order for the fixture customer, built through the
+ * API — returns and claims can only be raised against goods that left. Paid
+ * with store credit, because that is the payment method every seeded store
+ * has; it also saves spec time over driving checkout.
+ */
+export async function createShippedOrder(page: Page, accessToken: string, quantity = 2) {
+ const headers = { Authorization: `Bearer ${accessToken}` }
+ const request = async (method: 'get' | 'post' | 'patch', path: string, data?: object) => {
+ const res = await page.request[method](path, { headers, data })
+ expect(res.ok(), `${method.toUpperCase()} ${path}: ${await res.text()}`).toBeTruthy()
+ return res.json()
+ }
+
+ const customers = await request(
+ 'get',
+ `/api/v3/admin/customers?q[email_eq]=${encodeURIComponent(FIXTURE_PROMO_CUSTOMER_EMAIL)}`,
+ )
+ const customerId = customers.data[0].id
+ const variants = await request('get', `/api/v3/admin/variants?q[sku_eq]=${FIXTURE_PROMO_SKU}`)
+ const address = {
+ first_name: 'Promo',
+ last_name: 'Customer',
+ address1: '1 Main St',
+ city: 'Los Angeles',
+ country_code: 'US',
+ state_code: 'CA',
+ postal_code: '90001',
+ phone: '5555555555',
+ }
+
+ const order = await request('post', '/api/v3/admin/orders', {
+ customer_id: customerId,
+ items: [{ variant_id: variants.data[0].id, quantity }],
+ shipping_address: address,
+ billing_address: address,
+ })
+ await request('post', `/api/v3/admin/customers/${customerId}/store_credits`, {
+ amount: order.total,
+ currency: order.currency,
+ memo: `E2E payment for ${order.number}`,
+ })
+ await request('post', `/api/v3/admin/orders/${order.id}/store_credits`)
+ await request('patch', `/api/v3/admin/orders/${order.id}/complete`)
+
+ const fulfillments = await request('get', `/api/v3/admin/orders/${order.id}/fulfillments`)
+ for (const fulfillment of fulfillments.data) {
+ await request(
+ 'patch',
+ `/api/v3/admin/orders/${order.id}/fulfillments/${fulfillment.id}/fulfill`,
+ )
+ }
+
+ return order as { id: string; number: string }
+}
diff --git a/packages/dashboard/e2e/post-sale.spec.ts b/packages/dashboard/e2e/post-sale.spec.ts
new file mode 100644
index 0000000000..b3971d91d7
--- /dev/null
+++ b/packages/dashboard/e2e/post-sale.spec.ts
@@ -0,0 +1,108 @@
+import { expect, type Page, test } from '@playwright/test'
+import { createShippedOrder, FIXTURE_PROMO_PRODUCT, login } from './helpers'
+
+/** One of the order page's cards, found by its title. */
+function card(page: Page, title: RegExp) {
+ return page
+ .locator('[data-slot="card"]')
+ .filter({ has: page.locator('[data-slot="card-title"]', { hasText: title }) })
+ .first()
+}
+
+/** Picks an action from a return or claim's own menu. */
+async function recordAction(page: Page, section: RegExp, action: RegExp) {
+ await card(page, section)
+ .getByRole('button', { name: /^actions$/i })
+ .click()
+ await page.getByRole('menuitem', { name: action }).click()
+}
+
+test.describe('post-sale', () => {
+ // Creating a paid, shipped order through the API, then walking the return
+ // through every state, is more than the default budget allows.
+ test.slow()
+
+ test('takes a return from request to refund, and lists it store-wide', async ({ page }) => {
+ const creds = await login(page)
+ const order = await createShippedOrder(page, creds.accessToken)
+ await page.goto(`/${creds.store_id}/orders/${order.id}`)
+
+ const returns = card(page, /^returns/i)
+ await expect(returns.getByText(/no returns for this order/i)).toBeVisible({ timeout: 15_000 })
+ await returns.getByRole('button', { name: /new return/i }).click()
+
+ const dialog = page.getByRole('dialog')
+ await expect(dialog.getByRole('heading', { name: /new return/i })).toBeVisible()
+ await dialog.getByRole('spinbutton', { name: new RegExp(FIXTURE_PROMO_PRODUCT) }).fill('1')
+ await dialog.locator('#reason-return-reasons').click()
+ await page.getByRole('option', { name: 'Damaged/Defective' }).click()
+ await dialog.locator('#return-memo').fill('Cracked in transit')
+ await dialog.getByRole('button', { name: /new return/i }).click()
+
+ await expect(returns.getByText(/^requested$/i)).toBeVisible({ timeout: 15_000 })
+
+ await recordAction(page, /^returns/i, /^approve$/i)
+ await expect(returns.getByText(/^approved$/i)).toBeVisible({ timeout: 15_000 })
+
+ await recordAction(page, /^returns/i, /receive items/i)
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /receive items/i })
+ .click()
+ await expect(returns.getByText(/^received$/i)).toBeVisible({ timeout: 15_000 })
+
+ await recordAction(page, /^returns/i, /^refund$/i)
+ await page.locator('#refund-method').click()
+ await page.getByRole('option', { name: /store credit/i }).click()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^refund$/i })
+ .click()
+ await expect(returns.getByText(/^refunded$/i)).toBeVisible({ timeout: 15_000 })
+
+ // The cross-order list is where the team sees what is still in flight.
+ await page.goto(`/${creds.store_id}/returns`)
+ await expect(page.getByRole('row').filter({ hasText: order.number })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+
+ test('opens a claim for a missing item, denies it, and lists it store-wide', async ({ page }) => {
+ const creds = await login(page)
+ const order = await createShippedOrder(page, creds.accessToken, 1)
+ await page.goto(`/${creds.store_id}/orders/${order.id}`)
+
+ const claims = card(page, /^claims/i)
+ await claims.getByRole('button', { name: /new claim/i }).click({ timeout: 15_000 })
+
+ const dialog = page.getByRole('dialog')
+ await expect(dialog.getByRole('heading', { name: /new claim/i })).toBeVisible()
+ await dialog.getByRole('spinbutton', { name: new RegExp(FIXTURE_PROMO_PRODUCT) }).fill('1')
+ await dialog.locator('#reason-claim-reasons').click()
+ await page.getByRole('option', { name: 'Never arrived' }).click()
+ await dialog.getByRole('button', { name: /new claim/i }).click()
+
+ await expect(claims.getByText(/^open$/i)).toBeVisible({ timeout: 15_000 })
+
+ await recordAction(page, /^claims/i, /^deny$/i)
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^deny$/i })
+ .click()
+ await expect(claims.getByText(/^denied$/i)).toBeVisible({ timeout: 15_000 })
+
+ await page.goto(`/${creds.store_id}/claims`)
+ await expect(page.getByRole('row').filter({ hasText: order.number })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+
+ test('lists exchanges store-wide', async ({ page }) => {
+ const creds = await login(page)
+ await page.goto(`/${creds.store_id}/exchanges`)
+
+ await expect(page.getByRole('heading', { name: /^exchanges$/i })).toBeVisible({
+ timeout: 15_000,
+ })
+ })
+})
diff --git a/packages/dashboard/e2e/purchase-orders.spec.ts b/packages/dashboard/e2e/purchase-orders.spec.ts
new file mode 100644
index 0000000000..96a1f34226
--- /dev/null
+++ b/packages/dashboard/e2e/purchase-orders.spec.ts
@@ -0,0 +1,202 @@
+import { expect, type Page, test } from '@playwright/test'
+import {
+ FIXTURE_SUPPLIER,
+ FIXTURE_TRANSFER_DESTINATION,
+ FIXTURE_TRANSFER_PRODUCT,
+ FIXTURE_TRANSFER_SKU,
+ gotoIndex,
+ login,
+ openRowMenu,
+} from './helpers'
+
+const PURCHASE_ORDERS_PATH = (storeId: string) => `/${storeId}/purchase-orders`
+const CTA = /new purchase order/i
+
+/**
+ * Raises a purchase order through the API, optionally placed with the
+ * supplier. The form has its own test; the rest of the order's life is what
+ * the others exercise.
+ */
+async function createPurchaseOrder(
+ page: Page,
+ accessToken: string,
+ { quantity, ordered = false }: { quantity: number; ordered?: boolean },
+) {
+ const headers = { Authorization: `Bearer ${accessToken}` }
+
+ const suppliers = await page.request
+ .get('/api/v3/admin/suppliers', { headers, params: { 'q[name_eq]': FIXTURE_SUPPLIER } })
+ .then((res) => res.json())
+ const locations = await page.request
+ .get('/api/v3/admin/stock_locations', { headers, params: { limit: 100 } })
+ .then((res) => res.json())
+ const destination = locations.data.find(
+ (location: { name: string }) => location.name === FIXTURE_TRANSFER_DESTINATION,
+ )
+ const variants = await page.request
+ .get('/api/v3/admin/variants', { headers, params: { 'q[sku_eq]': FIXTURE_TRANSFER_SKU } })
+ .then((res) => res.json())
+
+ const created = await page.request.post('/api/v3/admin/purchase_orders', {
+ headers,
+ data: {
+ supplier_id: suppliers.data[0].id,
+ destination_location_id: destination.id,
+ currency: 'USD',
+ reference: `E2E PO ${Date.now()}`,
+ items: [{ variant_id: variants.data[0].id, quantity_ordered: quantity, unit_cost: 7.5 }],
+ },
+ })
+ expect(created.status(), await created.text()).toBe(201)
+ const purchaseOrder = (await created.json()) as { id: string; number: string }
+
+ if (ordered) {
+ const placed = await page.request.patch(
+ `/api/v3/admin/purchase_orders/${purchaseOrder.id}/mark_ordered`,
+ { headers },
+ )
+ expect(placed.status(), await placed.text()).toBe(200)
+ }
+
+ return purchaseOrder
+}
+
+async function openPurchaseOrder(
+ page: Page,
+ storeId: string,
+ purchaseOrder: { id: string; number: string },
+) {
+ await page.goto(`${PURCHASE_ORDERS_PATH(storeId)}/${purchaseOrder.id}`)
+ await expect(page.getByRole('heading', { name: purchaseOrder.number })).toBeVisible({
+ timeout: 15_000,
+ })
+}
+
+test.describe('purchase orders', () => {
+ test('raises a draft from the form and places it with the supplier', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, PURCHASE_ORDERS_PATH(creds.store_id), CTA)
+ await page.getByRole('button', { name: CTA }).click()
+ await expect(page.getByRole('heading', { name: /new purchase order/i })).toBeVisible()
+
+ await page.locator('#supplier').fill(FIXTURE_SUPPLIER)
+ await page.getByRole('option', { name: FIXTURE_SUPPLIER }).click()
+ await page.locator('#destination').click()
+ await page.getByRole('option', { name: FIXTURE_TRANSFER_DESTINATION }).click()
+
+ await page
+ .getByRole('button', { name: /add a product/i })
+ .first()
+ .click()
+ const picker = page.getByRole('dialog')
+ await picker.getByRole('searchbox').fill(FIXTURE_TRANSFER_SKU)
+ await picker.getByRole('button', { name: new RegExp(FIXTURE_TRANSFER_PRODUCT) }).click()
+ await picker.getByRole('button', { name: /^add 1$/i }).click()
+ await expect(picker).toBeHidden()
+ await page.getByRole('spinbutton', { name: /^ordered$/i }).fill('12')
+
+ await page.getByRole('button', { name: /create draft/i }).click()
+
+ await expect(page).toHaveURL(/\/purchase-orders\/po_/, { timeout: 15_000 })
+ await expect(page.getByText(/^draft$/i).first()).toBeVisible()
+ await expect(page.getByText('0 received of 12 ordered')).toBeVisible()
+
+ await page.getByRole('button', { name: /mark as ordered/i }).click()
+ await expect(page.getByRole('heading', { name: /place this order\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /mark as ordered/i })
+ .click()
+
+ await expect(page.getByText(/^ordered$/i).first()).toBeVisible({ timeout: 15_000 })
+ // Placed lines are a commitment to the supplier, so they can no longer be edited.
+ await expect(page.getByRole('link', { name: /^edit$/i })).toHaveCount(0)
+ })
+
+ test('counts in part of a delivery, then closes the order short', async ({ page }) => {
+ const creds = await login(page)
+ const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, {
+ quantity: 10,
+ ordered: true,
+ })
+ await openPurchaseOrder(page, creds.store_id, purchaseOrder)
+
+ await page.getByLabel(/^accepted$/i).fill('4')
+ await page.getByRole('button', { name: /^receive$/i }).click()
+
+ await expect(page.getByText(/^partially received$/i).first()).toBeVisible({
+ timeout: 15_000,
+ })
+ await expect(page.getByText('4 received of 10 ordered')).toBeVisible()
+
+ // The supplier cannot send the rest: write it off rather than wait.
+ await page.getByRole('button', { name: /more actions/i }).click()
+ await page.getByRole('menuitem', { name: /close short/i }).click()
+ await expect(page.getByRole('heading', { name: /close this order short\?/i })).toBeVisible()
+ await page.locator('#close-short-reason').fill('Discontinued by the supplier')
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^close short$/i })
+ .click()
+
+ await expect(page.getByText(/^received$/i).first()).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText('Discontinued by the supplier')).toBeVisible()
+ })
+
+ test('corrects a draft', async ({ page }) => {
+ const creds = await login(page)
+ const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, { quantity: 3 })
+ await openPurchaseOrder(page, creds.store_id, purchaseOrder)
+
+ await page.getByRole('link', { name: /^edit$/i }).click()
+ await expect(
+ page.getByRole('heading', { name: new RegExp(`edit order ${purchaseOrder.number}`, 'i') }),
+ ).toBeVisible()
+
+ const reference = `Corrected ${Date.now()}`
+ await page.locator('#reference').fill(reference)
+ await page.getByRole('button', { name: /^save$/i }).click()
+
+ await expect(page.getByRole('heading', { name: purchaseOrder.number })).toBeVisible({
+ timeout: 15_000,
+ })
+ await expect(page.getByText(reference)).toBeVisible()
+ })
+
+ test('cancels a placed order after confirming', async ({ page }) => {
+ const creds = await login(page)
+ const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, {
+ quantity: 5,
+ ordered: true,
+ })
+ await openPurchaseOrder(page, creds.store_id, purchaseOrder)
+
+ await page.getByRole('button', { name: /more actions/i }).click()
+ await page.getByRole('menuitem', { name: /cancel order/i }).click()
+ await expect(page.getByRole('heading', { name: /cancel this purchase order\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /cancel order/i })
+ .click()
+
+ await expect(page.getByText(/^cancelled$/i).first()).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a draft from the list', async ({ page }) => {
+ const creds = await login(page)
+ const purchaseOrder = await createPurchaseOrder(page, creds.accessToken, { quantity: 1 })
+ await gotoIndex(page, PURCHASE_ORDERS_PATH(creds.store_id), CTA)
+
+ await openRowMenu(page, purchaseOrder.number)
+ await page.getByRole('menuitem', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete this purchase order\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(page.getByRole('row').filter({ hasText: purchaseOrder.number })).toHaveCount(0, {
+ timeout: 15_000,
+ })
+ })
+})
diff --git a/packages/dashboard/e2e/store-credits.spec.ts b/packages/dashboard/e2e/store-credits.spec.ts
new file mode 100644
index 0000000000..1b09d908f3
--- /dev/null
+++ b/packages/dashboard/e2e/store-credits.spec.ts
@@ -0,0 +1,59 @@
+import { expect, type Page, test } from '@playwright/test'
+import { escapeRegex, FIXTURE_PROMO_CUSTOMER_EMAIL, login } from './helpers'
+
+const STORE_CREDITS_PATH = (storeId: string) => `/${storeId}/loyalty/store-credits`
+
+/** Issues a credit to the fixture customer, the way the customer page does. */
+async function issueStoreCredit(page: Page, accessToken: string, memo: string) {
+ const headers = { Authorization: `Bearer ${accessToken}` }
+ const customers = await page.request
+ .get('/api/v3/admin/customers', {
+ headers,
+ params: { 'q[email_eq]': FIXTURE_PROMO_CUSTOMER_EMAIL },
+ })
+ .then((res) => res.json())
+ const created = await page.request.post(
+ `/api/v3/admin/customers/${customers.data[0].id}/store_credits`,
+ { headers, data: { amount: 40, currency: 'USD', memo } },
+ )
+ expect(created.status(), await created.text()).toBe(201)
+}
+
+test.describe('store credits', () => {
+ test('lists issued credit beside what the store still owes', async ({ page }) => {
+ const creds = await login(page)
+ const memo = `E2E goodwill ${Date.now()}`
+ await issueStoreCredit(page, creds.accessToken, memo)
+
+ await page.goto(STORE_CREDITS_PATH(creds.store_id))
+ await expect(page.getByText(/^outstanding$/i).first()).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('searchbox').fill(memo)
+ const row = page.getByRole('row').filter({ hasText: memo })
+ await expect(row).toHaveCount(1, { timeout: 15_000 })
+ await expect(row.getByText(FIXTURE_PROMO_CUSTOMER_EMAIL)).toBeVisible()
+ await expect(row.getByText('$40.00').first()).toBeVisible()
+ })
+
+ test('opens a credit and follows it to the customer', async ({ page }) => {
+ const creds = await login(page)
+ const memo = `E2E refund credit ${Date.now()}`
+ await issueStoreCredit(page, creds.accessToken, memo)
+
+ await page.goto(STORE_CREDITS_PATH(creds.store_id))
+ await page.getByRole('searchbox').fill(memo)
+ await page
+ .getByRole('button', {
+ name: new RegExp(`${escapeRegex(FIXTURE_PROMO_CUSTOMER_EMAIL)}.*${escapeRegex(memo)}`),
+ })
+ .click()
+
+ const sheet = page.getByRole('dialog')
+ await expect(sheet.getByText(memo)).toBeVisible({ timeout: 15_000 })
+ await expect(sheet.getByRole('heading', { name: /^ledger$/i })).toBeVisible()
+
+ await sheet.getByRole('link', { name: /open customer profile/i }).click()
+ await expect(page).toHaveURL(/\/customers\/cust_/, { timeout: 15_000 })
+ await expect(page.getByText(FIXTURE_PROMO_CUSTOMER_EMAIL).first()).toBeVisible()
+ })
+})
diff --git a/packages/dashboard/e2e/suppliers.spec.ts b/packages/dashboard/e2e/suppliers.spec.ts
new file mode 100644
index 0000000000..f3c7918d21
--- /dev/null
+++ b/packages/dashboard/e2e/suppliers.spec.ts
@@ -0,0 +1,75 @@
+import { expect, type Page, test } from '@playwright/test'
+import { FIXTURE_SUPPLIER, gotoIndex, login, openRowMenu, rowButton } from './helpers'
+
+const SUPPLIERS_PATH = (storeId: string) => `/${storeId}/suppliers`
+const CTA = /new supplier/i
+
+async function createSupplier(page: Page, attrs: { name: string; email?: string }) {
+ await page.getByRole('button', { name: CTA }).click()
+ await expect(page.getByRole('heading', { name: /^new supplier$/i })).toBeVisible()
+ await page.locator('#supplier-name').fill(attrs.name)
+ if (attrs.email) await page.locator('#supplier-email').fill(attrs.email)
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^save$/i })
+ .click()
+}
+
+test.describe('suppliers', () => {
+ test('lists suppliers', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, SUPPLIERS_PATH(creds.store_id), CTA)
+
+ await expect(rowButton(page, FIXTURE_SUPPLIER)).toBeVisible()
+ })
+
+ test('a supplier needs a name', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, SUPPLIERS_PATH(creds.store_id), CTA)
+
+ await createSupplier(page, { name: '' })
+
+ await expect(page.getByText(/a supplier needs a name/i)).toBeVisible()
+ })
+
+ test('adds a supplier and edits their contact', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, SUPPLIERS_PATH(creds.store_id), CTA)
+
+ const suffix = Date.now()
+ const name = `E2E Mill ${suffix}`
+ await createSupplier(page, { name, email: `orders-${suffix}@mill.test` })
+
+ const row = page.getByRole('row').filter({ has: rowButton(page, name) })
+ await expect(row.getByText(`orders-${suffix}@mill.test`)).toBeVisible({ timeout: 15_000 })
+
+ await rowButton(page, name).click()
+ await expect(page.locator('#supplier-name')).toHaveValue(name, { timeout: 15_000 })
+ await page.locator('#supplier-contact').fill('Alex Buyer')
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^save$/i })
+ .click()
+
+ await expect(row.getByText('Alex Buyer')).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('deletes a supplier with no purchasing history', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, SUPPLIERS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Former Supplier ${Date.now()}`
+ await createSupplier(page, { name })
+ await expect(rowButton(page, name)).toBeVisible({ timeout: 15_000 })
+
+ await openRowMenu(page, name)
+ await page.getByRole('menuitem', { name: /^delete$/i }).click()
+ await expect(page.getByRole('heading', { name: /delete this supplier\?/i })).toBeVisible()
+ await page
+ .getByRole('dialog')
+ .getByRole('button', { name: /^delete$/i })
+ .click()
+
+ await expect(rowButton(page, name)).toHaveCount(0, { timeout: 15_000 })
+ })
+})