@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
72 lines (71 loc) • 2.73 kB
JavaScript
import { config, FieldCollection, getTestConfig } 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('withAbstract 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 "abstract" of type "richText"', ()=>{
field = collection.fields.find((field)=>field.type === 'richText' && field.name === 'abstract');
expect(field).toBeDefined();
});
it('should be localized', ()=>{
expect(field.localized).toEqual(true);
});
it('should have a "afterRead" hook defined', ()=>{
expect(field.hooks.afterRead).toBeDefined();
});
});
describe('Document creation', ()=>{
let fieldsDoc;
let postData;
beforeAll(async ()=>{
postData = {
_id: uuid(),
title: uuid(),
abstract: [
{
type: 'text',
text: uuid()
}
]
};
const { doc } = await client.post(`/${FieldCollection.slug}?market=${testConfig.documents.market.id}&locale=${testConfig.defaultLocale}`, postData, {
headers: {
Authorization: `JWT ${userToken}`
}
});
fieldsDoc = await client.get(`/${FieldCollection.slug}/${doc.id}?market=${testConfig.documents.market.id}&locale=${testConfig.defaultLocale}`, {
headers: {
Authorization: `users API-Key ${users.api.apiKey}`
}
});
});
it('should have a valid "abstract" field', async ()=>{
expect(fieldsDoc.abstract).toEqual(`<span>${postData.abstract[0].text}</span>`);
});
});
});
//# sourceMappingURL=withAbstract.test.js.map