@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
84 lines (83 loc) • 3.44 kB
JavaScript
import { config, StaticCollection, StaticData } from '@/test';
import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { staticCollections } from '../api/static.service';
const mockLoader = async ()=>{
return Promise.resolve([
...StaticData
]);
};
describe('withStaticCollection 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;
// Register the static collection loader
staticCollections.push(StaticCollection.slug);
});
afterAll(async ()=>{
const index = staticCollections.indexOf(StaticCollection.slug);
if (index > -1) {
staticCollections.splice(index, 1);
}
await clearContext();
});
describe('Collection config', ()=>{
let withStaticCollectionConfig;
beforeAll(async ()=>{
withStaticCollectionConfig = payload.config.collections.find((collection)=>collection.slug === StaticCollection.slug);
});
it('should have a endpoint with "/" path', ()=>{
expect(withStaticCollectionConfig.endpoints && withStaticCollectionConfig.endpoints.find((endpoint)=>endpoint.path === '/')).toBeDefined();
});
it('should have a endpoint with "/:id/" path', ()=>{
expect(withStaticCollectionConfig.endpoints && withStaticCollectionConfig.endpoints.find((endpoint)=>endpoint.path === '/:id')).toBeDefined();
});
describe('translation', ()=>{
it('should have a labels property', ()=>{
expect(withStaticCollectionConfig).toHaveProperty('labels');
});
it('fields should have a label property', ()=>{
const [field] = withStaticCollectionConfig.fields;
expect(field).toHaveProperty('label');
});
});
});
describe('Fields', ()=>{
let doc;
it('should find all StaticCollection documents', async ()=>{
const docs = await client.get(`/${StaticCollection.slug}?pagination=false`, {
headers: {
Authorization: `JWT ${userToken}`
}
});
expect(docs.length).toBeGreaterThan(0);
});
it('should find a StaticCollection document by id', async ()=>{
doc = await client.get(`/${StaticCollection.slug}/${StaticData[0].id}`, {
headers: {
Authorization: `JWT ${userToken}`
}
});
expect(doc).toBeDefined();
});
it('should have a valid id field', async ()=>{
expect(doc.id).toEqual(StaticData[0].id);
});
it('should have a valid name field', async ()=>{
expect(doc.name).toEqual(StaticData[0].name);
});
it('should have a valid description field', async ()=>{
expect(doc.description).toEqual(StaticData[0].description);
});
});
});
//# sourceMappingURL=withStaticCollection.test.js.map