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.

2.5 KB
Raw Blame
import { expect, test } from '@playwright/test'
import { getCredentials } from './helpers'

test.describe('admin authentication', () => {
  test('signs in via the login form and lands on the dashboard', async ({ page }) => {
    const creds = getCredentials()

    await page.goto('/login')
    await expect(page.getByText(/welcome back/i)).toBeVisible()

    await page.getByLabel(/email/i).fill(creds.admin_email)
    await page.getByLabel(/password/i).fill(creds.admin_password)
    await page.getByRole('button', { name: /^sign in$/i }).click()

    // The /_authenticated/ index resolves the active store and redirects to
    // /$storeId. We just need to leave /login.
    await expect(page).not.toHaveURL(/\/login/, { timeout: 15_000 })
    await expect(page.url()).not.toContain('/login')
  })

  test('rejects invalid credentials with an inline error', async ({ page }) => {
    await page.goto('/login')

    await page.getByLabel(/email/i).fill('[email protected]')
    await page.getByLabel(/password/i).fill('wrong-password-123')
    await page.getByRole('button', { name: /^sign in$/i }).click()

    await expect(page.getByText(/invalid email or password/i)).toBeVisible()
    expect(page.url()).toContain('/login')
  })

  test('reaches the forgot-password page from the login form', async ({ page }) => {
    await page.goto('/login')
    await page.getByRole('link', { name: /forgot password/i }).click()

    await expect(page).toHaveURL(/\/forgot-password/)
    // The heading specifically: the route announcer's live region briefly holds
    // the same text, so a bare text match resolves to two elements.
    await expect(page.getByRole('heading', { name: 'Reset your password' })).toBeVisible()
  })

  test('confirms the reset request without revealing whether the email exists', async ({
    page,
  }) => {
    // Same confirmation for a real and an unknown email — no account enumeration.
    for (const email of ['[email protected]', '[email protected]']) {
      await page.goto('/forgot-password')
      await page.getByLabel(/email/i).fill(email)
      await page.getByRole('button', { name: /send reset link/i }).click()

      await expect(page.getByText(/check your email/i)).toBeVisible({ timeout: 15_000 })
    }
  })

  test('shows an invalid-link message when the reset token is missing', async ({ page }) => {
    await page.goto('/reset-password')

    await expect(page.getByText(/invalid reset link/i)).toBeVisible()
    await expect(page.getByRole('link', { name: /request a new reset link/i })).toBeVisible()
  })
})