@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
62 lines (61 loc) • 2.22 kB
JavaScript
import { config, FieldCollection, getTestConfig, 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('withComponent field', ()=>{
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('Field config', ()=>{
let collection;
let field;
beforeAll(async ()=>{
collection = payload.config.collections.find((x)=>x.slug === FieldCollection.slug);
});
it('should have a field named "components" of type "blocks"', ()=>{
field = collection.fields.find((field)=>field.type === 'blocks' && field.name === 'components');
expect(field).toBeDefined();
});
});
describe('Document creation', ()=>{
let fieldsDoc;
let postData;
beforeAll(async ()=>{
postData = {
_id: uuid(),
title: uuid(),
components: [
{
blockType: withBlockOption.slug,
customField: uuid()
}
]
};
({ doc: fieldsDoc } = await client.post(`/${FieldCollection.slug}?locale=${testConfig.defaultLocale}`, postData, {
headers: {
Authorization: `JWT ${userToken}`
}
}));
});
it('should have a valid "components" field', async ()=>{
const [block] = fieldsDoc.components;
expect(block).toBeDefined();
});
});
});
//# sourceMappingURL=withComponents.test.js.map