/** * Auth: log in with the credentials from tests/.env and use the issued tokens. */ import { apiClient } from '../helpers/api' import { staffSession, userSession } from '../helpers/sessions' describe('auth tokens', () => { it('staff login returns a token and staff id', async () => { const staff = await staffSession() expect(typeof staff.token).toBe('string') expect(staff.token.length).toBeGreaterThan(10) expect(staff.staffId).toBeGreaterThan(0) }) it('user login returns a token and user id', async () => { const user = await userSession() expect(typeof user.token).toBe('string') expect(user.token.length).toBeGreaterThan(10) expect(user.userId).toBeGreaterThan(0) }) it('each token authenticates its own protected procedures', async () => { const [staff, user] = await Promise.all([staffSession(), userSession()]) const products = await apiClient(staff.token).admin.product.getProducts.query() expect(Array.isArray(products.products)).toBe(true) const addresses = await apiClient(user.token).user.address.getUserAddresses.query() expect(Array.isArray(addresses.data)).toBe(true) }) })