UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

68 lines (67 loc) 2.56 kB
import { BlockCollection, config, withBlockOption } from '@/test'; import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload'; import { v4 as uuid } from 'uuid'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; describe('withBlock block', ()=>{ 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('Block config', ()=>{ let withBlockConfig; beforeAll(async ()=>{ const collection = payload.config.collections.find((collection)=>collection.slug === BlockCollection.slug); const blockField = collection.fields.find((_)=>_.type === 'blocks'); withBlockConfig = blockField.blocks.find((_)=>_.slug === withBlockOption.slug); }); describe('translation', ()=>{ it('should have a labels property', ()=>{ expect(withBlockConfig).toHaveProperty('labels'); }); it('fields should have a label property', ()=>{ const [field] = withBlockConfig.fields; expect(field).toHaveProperty('label'); }); }); }); describe('Fields', ()=>{ let withBlocksDoc; let withBlockBlock; let postData; beforeAll(async ()=>{ postData = { blocks: [ { blockType: withBlockOption.slug, customField: uuid() } ] }; ({ doc: withBlocksDoc } = await client.post(BlockCollection.slug, postData, { headers: { Authorization: `JWT ${userToken}` } })); }); it('should have a valid blocks field containing a withBlock block', async ()=>{ [withBlockBlock] = withBlocksDoc.blocks; expect(withBlockBlock).toBeDefined(); }); it('block should have a valid custom field', async ()=>{ expect(withBlockBlock.customField).toEqual(postData.blocks[0].customField); }); }); }); //# sourceMappingURL=withBlock.test.js.map