UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

68 lines (67 loc) 2.7 kB
import { ActionCollection, config } 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'; // @see action.service.test.ts for specific tests about the action service describe('withAction 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 withActionConfig; beforeAll(async ()=>{ withActionConfig = payload.config.collections.find((collection)=>collection.slug === ActionCollection.slug); }); it('should have a GET endpoint with "/" path', ()=>{ expect(withActionConfig.endpoints && withActionConfig.endpoints.find((endpoint)=>endpoint.path === '/' && endpoint.method === 'get')).toBeDefined(); }); describe('translation', ()=>{ it('should have a labels property', ()=>{ expect(withActionConfig).toHaveProperty('labels'); }); it('fields should have a label property', ()=>{ const [field] = withActionConfig.fields; expect(field).toHaveProperty('label'); }); }); }); describe('Create doc', ()=>{ let withActionDoc; let postData; it('should create a withAction document', async ()=>{ postData = { email: 'foo@bar.com', customField: uuid() }; ({ doc: withActionDoc } = await client.post(ActionCollection.slug, postData, { headers: { Authorization: `users API-Key ${users.api.apiKey}` } })); expect(withActionDoc).toBeDefined(); }); it('should have a valid email field', async ()=>{ expect(withActionDoc.email).toEqual(postData.email); }); it('should have a valid custom field', async ()=>{ expect(withActionDoc.customField).toEqual(postData.customField); }); it('should have an empty endUser field', async ()=>{ expect(withActionDoc.endUser).toBeUndefined(); }); }); }); //# sourceMappingURL=withAction.test.js.map