UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

64 lines (63 loc) 2.46 kB
import { config, getTestConfig, PageCollection } 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('withCollection collection', ()=>{ let payload; let client; let userToken; let endUserToken; let apiKey; let testConfig; 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; testConfig = await getTestConfig(client, userToken); }); afterAll(async ()=>{ await clearContext(); }); describe('Collection config', ()=>{ let withCollectionConfig; beforeAll(async ()=>{ withCollectionConfig = payload.config.collections.find((collection)=>collection.slug === PageCollection.slug); }); it('should have a endpoint with "/" path', ()=>{ expect(withCollectionConfig.endpoints && withCollectionConfig.endpoints.find((endpoint)=>endpoint.path === '/')).toBeDefined(); }); describe('translation', ()=>{ it('should have a labels property', ()=>{ expect(withCollectionConfig).toHaveProperty('labels'); }); it('fields should have a label property', ()=>{ const [field] = withCollectionConfig.fields; expect(field).toHaveProperty('label'); }); }); }); describe('Fields', ()=>{ let doc; let data; it('should create a PageCollection document', async ()=>{ data = { title: uuid(), category: testConfig.documents.category.id, customField: uuid() }; ({ doc } = await client.post(`/${PageCollection.slug}?locale=${testConfig.defaultLocale}`, data, { headers: { Authorization: `JWT ${userToken}` } })); expect(doc).toBeDefined(); }); it('should have a valid custom field', async ()=>{ expect(doc.customField).toEqual(data.customField); }); }); }); //# sourceMappingURL=withCollection.test.js.map