UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

63 lines (62 loc) 2.48 kB
import { config, MenuCollection } 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('withMenu collection', ()=>{ 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('Collection config', ()=>{ let withMenuCollection; beforeAll(async ()=>{ withMenuCollection = payload.config.collections.find((collection)=>collection.slug === MenuCollection.slug); }); it('should have a endpoint with "/" path', ()=>{ expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find((endpoint)=>endpoint.path === '/')).toBeDefined(); }); it('should have a endpoint with "/:id/" path', ()=>{ expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find((endpoint)=>endpoint.path === '/:id')).toBeDefined(); }); describe('translation', ()=>{ it('should have a labels property', ()=>{ expect(withMenuCollection).toHaveProperty('labels'); }); it('fields should have a label property', ()=>{ const [field] = withMenuCollection.fields; expect(field).toHaveProperty('label'); }); }); }); describe('Create doc', ()=>{ let withMenuDoc; let postData; it('should create a MenuCollection document', async ()=>{ postData = { customField: uuid() }; ({ doc: withMenuDoc } = await client.post(MenuCollection.slug, postData, { headers: { Authorization: `JWT ${userToken}` } })); expect(withMenuDoc).toBeDefined(); }); it('should have a valid custom field', async ()=>{ expect(withMenuDoc.customField).toEqual(postData.customField); }); }); }); //# sourceMappingURL=withMenu.test.js.map