/** * `schema.enum(() => values)` reads its values each time it is used, so a list * that comes from config (team roles, stacksjs/stacks#3590) is the app's and * not whatever the config held when the model file loaded. */ import { expect, test } from 'bun:test' import { schema } from '../src/runtime' test('validates, lists and reports the values as they are now', () => { let values = ['owner', 'admin'] const rule = schema.enum(() => values) as ReturnType & { allowedValues: string[] } expect(rule.validate('developer').valid).toBe(false) values = ['owner', 'admin', 'developer'] expect(rule.validate('developer').valid).toBe(true) expect(rule.allowedValues).toEqual(['owner', 'admin', 'developer']) expect(rule.validate('nope').errors).toEqual([{ message: 'Must be one of: owner, admin, developer' }]) }) test('a plain list is unchanged', () => { const rule = schema.enum(['a', 'b']) expect(rule.validate('a').valid).toBe(true) expect(rule.validate('c').valid).toBe(false) })