import { test, expect, createItem, uniqueSuffix, findOrFail } from './fixtures'; test.describe('Disabling a customer account', () => { test('an admin can disable an account and the customer is told at sign-in', async ({ page, customer, admin, adminCustomers, authModal }) => { await admin.open('Customers'); await expect(adminCustomers.row(customer.email)).toBeVisible(); await expect(adminCustomers.status(customer.email, 'ACTIVE')).toBeVisible(); await adminCustomers.disable(customer.email); await expect(page.getByText('Account disabled')).toBeVisible(); await expect(adminCustomers.status(customer.email, 'DISABLED')).toBeVisible(); // A generic credential error would send a real customer round the // password-reset loop forever. await authModal.gotoLogIn(); await authModal.logIn(customer.email, customer.password); await expect(page.getByText(/disabled/i)).toBeVisible(); }); test('an existing session stops working immediately', async ({ page, request, customer, accountModal }) => { // Still signed in from registration, in this same browser context. await accountModal.open(); await expect(accountModal.emailText(customer.email)).toBeVisible(); const customers = await (await request.get('/api/admin/customers')).json(); const id = findOrFail( customers, (c: { email: string }) => c.email === customer.email, `the customer ${customer.email}` ).id; await request.post(`/api/admin/customers/${id}/disable`); // The cookie is unchanged, so this proves the server rejects it rather // than the browser having discarded it. await page.goto('/account'); await expect(page).toHaveURL(/\/login/); }); test('re-enabling restores sign-in', async ({ page, request, customer, admin, adminCustomers, authModal, header }) => { const customers = await (await request.get('/api/admin/customers')).json(); const id = findOrFail( customers, (c: { email: string }) => c.email === customer.email, `the customer ${customer.email}` ).id; await request.post(`/api/admin/customers/${id}/disable`); await admin.open('Customers'); await expect(adminCustomers.row(customer.email)).toBeVisible(); await adminCustomers.reEnable(customer.email); await expect(page.getByText('Account re-enabled')).toBeVisible(); await authModal.gotoLogIn(); await authModal.logIn(customer.email, customer.password); await header.waitForSignedIn(); }); test('the confirmation warns that held items will be released', async ({ page, request, customer, admin, adminCustomers }) => { const item = await createItem(request, { name: `Held ${uniqueSuffix()}`, price: '40' }); expect((await page.request.post(`/api/cart/items/${item.id}`)).status()).toBe(201); await admin.open('Customers'); await expect(adminCustomers.row(customer.email)).toBeVisible(); await adminCustomers.disableButton(customer.email).click(); // The consequence has to be visible at the moment of the decision. await expect(page.getByText(/1 reserved item/)).toBeVisible(); await adminCustomers.confirmDialog.getByRole('button', { name: 'Disable' }).click(); await expect(page.getByText('Account disabled')).toBeVisible(); const released = await (await request.get(`/api/items/${item.id}`)).json(); expect(released.status).toBe('available'); }); });