chore: simplifies index creation

This commit is contained in:
Dan Ribbens
2022-08-15 16:54:23 -04:00
parent 48f929f3ab
commit 2ca526bd22
3 changed files with 59 additions and 17 deletions

View File

@@ -19,6 +19,7 @@ const PointFields: CollectionConfig = {
name: 'localized',
type: 'point',
label: 'Localized Point',
unique: true,
localized: true,
},
{
@@ -36,7 +37,7 @@ const PointFields: CollectionConfig = {
export const pointDoc = {
point: [7, -7],
localized: [5, -2],
localized: [15, -12],
group: { point: [1, 9] },
};

View File

@@ -160,6 +160,9 @@ describe('Fields', () => {
describe('point', () => {
let doc;
const point = [7, -7];
const localized = [5, -2];
const group = { point: [1, 9] };
beforeAll(async () => {
const findDoc = await payload.find({
@@ -183,9 +186,6 @@ describe('Fields', () => {
});
it('should create', async () => {
const point = [7, -7];
const localized = [5, -2];
const group = { point: [1, 9] };
doc = await payload.create({
collection: 'point-fields',
data: {
@@ -199,6 +199,30 @@ describe('Fields', () => {
expect(doc.localized).toEqual(localized);
expect(doc.group).toMatchObject(group);
});
it('should not create duplicate point when unique', async () => {
await expect(() => payload.create({
collection: 'point-fields',
data: {
point,
localized,
group,
},
}))
.rejects
.toThrow(Error);
await expect(async () => payload.create({
collection: 'number-fields',
data: {
min: 5,
},
})).rejects.toThrow('The following field is invalid: min');
expect(doc.point).toEqual(point);
expect(doc.localized).toEqual(localized);
expect(doc.group).toMatchObject(group);
});
});
describe('array', () => {
let doc;