UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

103 lines (102 loc) 4.23 kB
import { config, getTestConfig, PageCollection } from '@/test'; import { textToSlug } from '@websolutespa/payload-utils'; import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload'; import { v4 as uuid } from 'uuid'; import { afterAll, beforeAll, describe, expect, it } from 'vitest'; describe('withPage 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 withPageConfig; beforeAll(async ()=>{ withPageConfig = payload.config.collections.find((collection)=>collection.slug === PageCollection.slug); }); it('should have a endpoint with "/" path', ()=>{ expect(withPageConfig.endpoints && withPageConfig.endpoints.find((endpoint)=>endpoint.path === '/')).toBeDefined(); }); it('should have a endpoint with "/:id/" path', ()=>{ expect(withPageConfig.endpoints && withPageConfig.endpoints.find((endpoint)=>endpoint.path === '/:id')).toBeDefined(); }); it('should have a preview url', ()=>{ expect(withPageConfig.admin.preview).toBeDefined(); }); describe('translation', ()=>{ it('should have a labels property', ()=>{ expect(withPageConfig).toHaveProperty('labels'); }); it('fields should have a label property', ()=>{ const [field] = withPageConfig.fields; expect(field).toHaveProperty('label'); }); }); }); describe('Create doc', ()=>{ let withPageDoc; let postData; it('should create a PageCollection document', async ()=>{ postData = { title: uuid(), slug: uuid(), order: 1, isDefault: false, useSplat: false, category: testConfig.documents.category.id, template: testConfig.documents.template.id, markets: [ testConfig.documents.market.id ], customField: uuid() }; ({ doc: withPageDoc } = await client.post(PageCollection.slug, postData, { headers: { Authorization: `JWT ${userToken}` } })); expect(withPageDoc).toBeDefined(); }); it('should have a valid title field', async ()=>{ expect(withPageDoc.title).toEqual(postData.title); }); it('should have a valid category field', async ()=>{ expect(withPageDoc.category.id).toEqual(postData.category); }); it('should have a valid slug field', async ()=>{ expect(withPageDoc.slug).toEqual(textToSlug(postData.slug)); }); it('should have a valid order field', async ()=>{ expect(withPageDoc.order).toEqual(postData.order); }); it('should have a valid isDefault field', async ()=>{ expect(withPageDoc.isDefault).toEqual(postData.isDefault); }); it('should have a valid useSplat field', async ()=>{ expect(withPageDoc.useSplat).toEqual(postData.useSplat); }); it('should have a valid markets field', async ()=>{ expect(withPageDoc.markets.map((x)=>x.id)).toEqual(postData.markets); }); it('should have a valid template field', async ()=>{ expect(withPageDoc.template.id).toEqual(postData.template); }); it('should have a valid custom field', async ()=>{ expect(withPageDoc.customField).toEqual(postData.customField); }); }); }); //# sourceMappingURL=withPage.test.js.map