UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

49 lines (48 loc) 1.91 kB
import { config } from '@/test'; import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload'; import { optionIsObject } from 'payload/shared'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; import { options } from '../../options'; // todo: update this test to match the new implementation describe('withRoles field', ()=>{ let payload; let client; let userToken; let endUserToken; let apiKey; beforeAll(async ()=>{ const context = await getContext(config); payload = context.payload; client = context.client; userToken = await client.getToken('users', users.admin); endUserToken = await client.getToken('end_users', endUsers.user); apiKey = users.api.apiKey; }); afterAll(async ()=>{ await clearContext(); }); describe('Field config', ()=>{ let collection; let field; beforeAll(async ()=>{ collection = payload.config.collections.find((collection)=>collection.slug === options.slug.users); }); it('should have a field named "roles" of type "select"', ()=>{ field = collection.fields.find((field)=>field.type === 'select' && field.name === 'roles'); expect(field).toBeDefined(); }); it('should be required', ()=>{ expect(field.required).toEqual(true); }); it('options should match the roles defined in options.rolesUser', ()=>{ Object.entries(options.roles).forEach(([k, v])=>{ if (options.rolesUser.includes(v)) { const option = field.options.find((x)=>optionIsObject(x) && x.value === v); expect(option).toBeDefined(); expect(option.label).toEqual(k); } }); }); }); }); //# sourceMappingURL=withRoles.test.js.map