chore: test coverage queries
This commit is contained in:
@@ -7,7 +7,7 @@ import { combineMerge } from '../utilities/combineMerge';
|
|||||||
import { operatorMap } from './operatorMap';
|
import { operatorMap } from './operatorMap';
|
||||||
import { sanitizeQueryValue } from './sanitizeQueryValue';
|
import { sanitizeQueryValue } from './sanitizeQueryValue';
|
||||||
import { PayloadRequest, Where } from '../types';
|
import { PayloadRequest, Where } from '../types';
|
||||||
import { Field, FieldAffectingData, TabAsField, UIField, fieldAffectsData } from '../fields/config/types';
|
import { Field, FieldAffectingData, fieldAffectsData, TabAsField, UIField } from '../fields/config/types';
|
||||||
import { CollectionPermission, FieldPermissions, GlobalPermission } from '../auth';
|
import { CollectionPermission, FieldPermissions, GlobalPermission } from '../auth';
|
||||||
import flattenFields from '../utilities/flattenTopLevelFields';
|
import flattenFields from '../utilities/flattenTopLevelFields';
|
||||||
import { getEntityPolicies } from '../utilities/getEntityPolicies';
|
import { getEntityPolicies } from '../utilities/getEntityPolicies';
|
||||||
@@ -566,8 +566,8 @@ const getBuildQueryPlugin = ({
|
|||||||
});
|
});
|
||||||
const result = await paramParser.parse();
|
const result = await paramParser.parse();
|
||||||
|
|
||||||
if (this.errors.length > 0) {
|
if (paramParser.errors.length > 0) {
|
||||||
throw new QueryError(this.errors);
|
throw new QueryError(paramParser.errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ describe('collections-rest', () => {
|
|||||||
data: { description },
|
data: { description },
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log({ relationFieldStatus, relationFieldDocs, relationFieldErrors });
|
|
||||||
|
|
||||||
const { status: relationMultiRelationToStatus } = await client.updateMany<Post>({
|
const { status: relationMultiRelationToStatus } = await client.updateMany<Post>({
|
||||||
where: { 'relationMultiRelationTo.missing': { equals: 'title' } },
|
where: { 'relationMultiRelationTo.missing': { equals: 'title' } },
|
||||||
data: { description },
|
data: { description },
|
||||||
@@ -150,8 +148,8 @@ describe('collections-rest', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const description = 'description';
|
const description = 'description';
|
||||||
const { status } = await client.updateMany<Post>({
|
const result = await client.updateMany({
|
||||||
query: { restrictedField: { equals: 'restricted' } },
|
where: { restrictedField: { equals: 'restricted' } },
|
||||||
data: { description },
|
data: { description },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -160,137 +158,12 @@ describe('collections-rest', () => {
|
|||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(status).toEqual(400);
|
expect(result.status).toEqual(400);
|
||||||
|
expect(result.errors).toHaveLength(1);
|
||||||
|
expect(result.errors[0].message).toEqual('The following path cannot be queried: restrictedField');
|
||||||
expect(doc.description).toBeUndefined();
|
expect(doc.description).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should bulk update with a relationship field that exists in one collection and not another', async () => {
|
|
||||||
const relationOne = await payload.create({
|
|
||||||
collection: 'dummy',
|
|
||||||
data: {
|
|
||||||
title: 'title',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const relationTwo = await payload.create({
|
|
||||||
collection: 'relation',
|
|
||||||
data: {
|
|
||||||
name: 'name',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const description = 'desc';
|
|
||||||
const relationPost = await payload.create({
|
|
||||||
collection: slug,
|
|
||||||
data: {
|
|
||||||
description,
|
|
||||||
relationMultiRelationTo: {
|
|
||||||
value: relationTwo.id,
|
|
||||||
relationTo: 'relation',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const relationToDummyPost = await payload.create({
|
|
||||||
collection: slug,
|
|
||||||
data: {
|
|
||||||
description,
|
|
||||||
relationMultiRelationTo: {
|
|
||||||
value: relationOne.id,
|
|
||||||
relationTo: 'dummy',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedDescription = 'updated';
|
|
||||||
|
|
||||||
const { status: relationMultiRelationToStatus, docs: updated } = await client.updateMany<Post>({
|
|
||||||
where: {
|
|
||||||
'relationMultiRelationTo.title': {
|
|
||||||
equals: relationOne.title,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: { description: updatedDescription },
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedDoc = await payload.findByID({
|
|
||||||
collection: slug,
|
|
||||||
id: relationToDummyPost.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const otherDoc = await payload.findByID({
|
|
||||||
collection: slug,
|
|
||||||
id: relationPost.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(relationMultiRelationToStatus).toEqual(200);
|
|
||||||
expect(updated).toHaveLength(1);
|
|
||||||
expect(updated[0].id).toEqual(relationToDummyPost.id);
|
|
||||||
expect(updatedDoc.description).toEqual(updatedDescription);
|
|
||||||
expect(otherDoc.description).toEqual(description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should bulk update with a relationship field that exists in one collection and is restricted in another', async () => {
|
|
||||||
const name = 'name';
|
|
||||||
const relationOne = await payload.create({
|
|
||||||
collection: 'dummy',
|
|
||||||
data: {
|
|
||||||
title: 'title',
|
|
||||||
name, // read access: () => false
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const relationTwo = await payload.create({
|
|
||||||
collection: 'relation',
|
|
||||||
data: {
|
|
||||||
name,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const description = 'desc';
|
|
||||||
const relationPost = await payload.create({
|
|
||||||
collection: slug,
|
|
||||||
data: {
|
|
||||||
description,
|
|
||||||
relationMultiRelationTo: {
|
|
||||||
value: relationTwo.id,
|
|
||||||
relationTo: 'relation',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const relationToDummyPost = await payload.create({
|
|
||||||
collection: slug,
|
|
||||||
data: {
|
|
||||||
description,
|
|
||||||
relationMultiRelationTo: {
|
|
||||||
value: relationOne.id,
|
|
||||||
relationTo: 'dummy',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedDescription = 'updated';
|
|
||||||
|
|
||||||
const { status } = await client.updateMany<Post>({
|
|
||||||
where: { 'relationMultiRelationTo.name': { equals: name } },
|
|
||||||
data: { description: updatedDescription },
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const updatedDoc = await payload.findByID({
|
|
||||||
collection: slug,
|
|
||||||
id: relationPost.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const otherDoc = await payload.findByID({
|
|
||||||
collection: slug,
|
|
||||||
id: relationToDummyPost.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(status).toEqual(200);
|
|
||||||
expect(updatedDoc.description).toEqual(updatedDescription);
|
|
||||||
expect(otherDoc.description).toEqual(description);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return formatted errors for bulk updates', async () => {
|
it('should return formatted errors for bulk updates', async () => {
|
||||||
const text = 'bulk-update-test-errors';
|
const text = 'bulk-update-test-errors';
|
||||||
const errorDoc = await payload.create({
|
const errorDoc = await payload.create({
|
||||||
@@ -554,25 +427,6 @@ describe('collections-rest', () => {
|
|||||||
expect(result.docs).toEqual([post1]);
|
expect(result.docs).toEqual([post1]);
|
||||||
expect(result.totalDocs).toEqual(1);
|
expect(result.totalDocs).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('nested by property value', async () => {
|
|
||||||
const post1 = await createPost({
|
|
||||||
relationMultiRelationTo: { relationTo: relationSlug, value: relation.id },
|
|
||||||
});
|
|
||||||
await createPost();
|
|
||||||
|
|
||||||
const { status, result } = await client.find<Post>({
|
|
||||||
query: {
|
|
||||||
'relationMultiRelationTo.value.name': {
|
|
||||||
equals: relation.name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(status).toEqual(200);
|
|
||||||
expect(result.docs).toEqual([post1]);
|
|
||||||
expect(result.totalDocs).toEqual(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('relationTo multi hasMany', () => {
|
describe('relationTo multi hasMany', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user