feat: refactors buildQuery to rely on fields instead of mongoose
This commit is contained in:
@@ -4,6 +4,8 @@ import { buildConfig } from '../buildConfig';
|
||||
export const slug = 'global';
|
||||
export const arraySlug = 'array';
|
||||
|
||||
export const accessControlSlug = 'access-control';
|
||||
|
||||
export const englishLocale = 'en';
|
||||
export const spanishLocale = 'es';
|
||||
|
||||
@@ -51,6 +53,33 @@ export default buildConfig({
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: accessControlSlug,
|
||||
access: {
|
||||
read: ({ req: { user } }) => {
|
||||
if (user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: {
|
||||
equals: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'enabled',
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
@@ -60,5 +89,12 @@ export default buildConfig({
|
||||
password: devUser.password,
|
||||
},
|
||||
});
|
||||
|
||||
await payload.updateGlobal({
|
||||
slug: accessControlSlug,
|
||||
data: {
|
||||
title: 'hello',
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GraphQLClient } from 'graphql-request';
|
||||
import { initPayloadTest } from '../helpers/configHelpers';
|
||||
import configPromise, { arraySlug, englishLocale, slug, spanishLocale } from './config';
|
||||
import configPromise, { accessControlSlug, arraySlug, englishLocale, slug, spanishLocale } from './config';
|
||||
import payload from '../../src';
|
||||
import { RESTClient } from '../helpers/rest';
|
||||
|
||||
@@ -144,6 +144,29 @@ describe('globals', () => {
|
||||
expect(en).toMatchObject(localized.en);
|
||||
expect(es).toMatchObject(localized.es);
|
||||
});
|
||||
|
||||
it('should respect valid access query constraint', async () => {
|
||||
const emptyGlobal = await payload.findGlobal({
|
||||
slug: accessControlSlug,
|
||||
overrideAccess: false,
|
||||
});
|
||||
|
||||
expect(Object.keys(emptyGlobal)).toHaveLength(0);
|
||||
|
||||
await payload.updateGlobal({
|
||||
slug: accessControlSlug,
|
||||
data: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
|
||||
const hasAccess = await payload.findGlobal({
|
||||
slug: accessControlSlug,
|
||||
overrideAccess: false,
|
||||
});
|
||||
|
||||
expect(hasAccess.title).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('graphql', () => {
|
||||
|
||||
Reference in New Issue
Block a user