Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
149 lines
4.5 KiB
Plaintext
149 lines
4.5 KiB
Plaintext
import { ReservedFieldName } from '../../errors/index.js';
|
|
import { sanitizeCollection } from '../../collections/config/sanitize.js';
|
|
import { describe, it, expect } from 'vitest';
|
|
describe('reservedFieldNames - collections -', ()=>{
|
|
const config = {
|
|
collections: [],
|
|
globals: []
|
|
};
|
|
describe('uploads -', ()=>{
|
|
const collectionWithUploads = {
|
|
slug: 'collection-with-uploads',
|
|
fields: [],
|
|
upload: true
|
|
};
|
|
it('should throw on file', async ()=>{
|
|
const fields = [
|
|
{
|
|
name: 'file',
|
|
type: 'text',
|
|
label: 'some-collection'
|
|
}
|
|
];
|
|
await expect(async ()=>{
|
|
await sanitizeCollection(// @ts-expect-error
|
|
{
|
|
...config,
|
|
collections: [
|
|
{
|
|
...collectionWithUploads,
|
|
fields
|
|
}
|
|
]
|
|
}, {
|
|
...collectionWithUploads,
|
|
fields
|
|
});
|
|
}).rejects.toThrow(ReservedFieldName);
|
|
});
|
|
it('should not throw on a custom field', async ()=>{
|
|
const fields = [
|
|
{
|
|
name: 'customField',
|
|
type: 'text',
|
|
label: 'some-collection'
|
|
}
|
|
];
|
|
await expect(async ()=>{
|
|
await sanitizeCollection(// @ts-expect-error
|
|
{
|
|
...config,
|
|
collections: [
|
|
{
|
|
...collectionWithUploads,
|
|
fields
|
|
}
|
|
]
|
|
}, {
|
|
...collectionWithUploads,
|
|
fields
|
|
});
|
|
}).not.toThrow();
|
|
});
|
|
});
|
|
describe('auth -', ()=>{
|
|
const collectionWithAuth = {
|
|
slug: 'collection-with-auth',
|
|
auth: {
|
|
loginWithUsername: true,
|
|
useAPIKey: true,
|
|
verify: true
|
|
},
|
|
fields: []
|
|
};
|
|
it('should throw on hash', async ()=>{
|
|
const fields = [
|
|
{
|
|
name: 'hash',
|
|
type: 'text',
|
|
label: 'some-collection'
|
|
}
|
|
];
|
|
await expect(async ()=>{
|
|
await sanitizeCollection(// @ts-expect-error
|
|
{
|
|
...config,
|
|
collections: [
|
|
{
|
|
...collectionWithAuth,
|
|
fields
|
|
}
|
|
]
|
|
}, {
|
|
...collectionWithAuth,
|
|
fields
|
|
});
|
|
}).rejects.toThrow(ReservedFieldName);
|
|
});
|
|
it('should throw on salt', async ()=>{
|
|
const fields = [
|
|
{
|
|
name: 'salt',
|
|
type: 'text',
|
|
label: 'some-collection'
|
|
}
|
|
];
|
|
await expect(async ()=>{
|
|
await sanitizeCollection(// @ts-expect-error
|
|
{
|
|
...config,
|
|
collections: [
|
|
{
|
|
...collectionWithAuth,
|
|
fields
|
|
}
|
|
]
|
|
}, {
|
|
...collectionWithAuth,
|
|
fields
|
|
});
|
|
}).rejects.toThrow(ReservedFieldName);
|
|
});
|
|
it('should not throw on a custom field', async ()=>{
|
|
const fields = [
|
|
{
|
|
name: 'customField',
|
|
type: 'text',
|
|
label: 'some-collection'
|
|
}
|
|
];
|
|
await expect(async ()=>{
|
|
await sanitizeCollection(// @ts-expect-error
|
|
{
|
|
...config,
|
|
collections: [
|
|
{
|
|
...collectionWithAuth,
|
|
fields
|
|
}
|
|
]
|
|
}, {
|
|
...collectionWithAuth,
|
|
fields
|
|
});
|
|
}).not.toThrow();
|
|
});
|
|
});
|
|
});
|
|
|
|
//# sourceMappingURL=reservedFieldNames.spec.js.map |