Skip to content

Commit

Permalink
fix: ensures you can query on mixed schema type within blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikrut committed Aug 12, 2022
1 parent 9e4e4b2 commit fba0847
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/mongoose/buildQuery.ts
Expand Up @@ -203,6 +203,8 @@ class ParamParser {
if (priorSchemaType.instance === 'Mixed' || priorSchemaType.instance === 'Array') {
lastIncompletePath.path = currentPath;
}
} else {
lastIncompletePath.path = currentPath;
}

if (operator === 'near') {
Expand Down
5 changes: 5 additions & 0 deletions test/fields/collections/Blocks/index.ts
Expand Up @@ -14,6 +14,10 @@ export const blocksField: Field = {
type: 'text',
required: true,
},
{
name: 'richText',
type: 'richText',
},
],
},
{
Expand Down Expand Up @@ -76,6 +80,7 @@ export const blocksFieldSeedData = [
blockName: 'First block',
blockType: 'text',
text: 'first block',
richText: [],
},
{
blockName: 'Second block',
Expand Down
9 changes: 8 additions & 1 deletion test/fields/config.ts
Expand Up @@ -59,7 +59,6 @@ export default buildConfig({
});

await payload.create({ collection: 'array-fields', data: arrayDoc });
await payload.create({ collection: 'block-fields', data: blocksDoc });
await payload.create({ collection: 'collapsible-fields', data: collapsibleDoc });
await payload.create({ collection: 'conditional-logic', data: conditionalLogicDoc });
await payload.create({ collection: 'group-fields', data: groupDoc });
Expand Down Expand Up @@ -89,5 +88,13 @@ export default buildConfig({
await payload.create({ collection: 'rich-text-fields', data: richTextDocWithRelationship });

await payload.create({ collection: 'number-fields', data: numberDoc });

const blocksDocWithRichText = { ...blocksDoc };

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
blocksDocWithRichText.blocks[0].richText = richTextDocWithRelationship.richText;

await payload.create({ collection: 'block-fields', data: blocksDocWithRichText });
},
});
24 changes: 24 additions & 0 deletions test/fields/int.spec.ts
Expand Up @@ -305,6 +305,30 @@ describe('Fields', () => {
expect(blockFields.docs[0].blocks[2].subBlocks[0].number).toEqual(blocksFieldSeedData[2].subBlocks[0].number);
expect(blockFields.docs[0].blocks[2].subBlocks[1].text).toEqual(blocksFieldSeedData[2].subBlocks[1].text);
});

it('should query based on richtext data within a block', async () => {
const blockFieldsSuccess = await payload.find({
collection: 'block-fields',
where: {
'blocks.richText.children.text': {
like: 'fun',
},
},
});

expect(blockFieldsSuccess.docs).toHaveLength(1);

const blockFieldsFail = await payload.find({
collection: 'block-fields',
where: {
'blocks.richText.children.text': {
like: 'funny',
},
},
});

expect(blockFieldsFail.docs).toHaveLength(0);
});
});

describe('richText', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/localization/int.spec.ts
Expand Up @@ -230,7 +230,7 @@ describe('Localization', () => {
const result = await payload.find<WithLocalizedRelationship>({
collection: withLocalizedRelSlug,
where: {
'localizedRelation.title': {
'localizedRelationship.title': {
equals: localizedRelation.title,
},
},
Expand All @@ -244,7 +244,7 @@ describe('Localization', () => {
collection: withLocalizedRelSlug,
locale: spanishLocale,
where: {
'localizedRelation.title': {
'localizedRelationship.title': {
equals: relationSpanishTitle,
},
},
Expand All @@ -258,7 +258,7 @@ describe('Localization', () => {
collection: withLocalizedRelSlug,
locale: 'all',
where: {
'localizedRelation.title.es': {
'localizedRelationship.title.es': {
equals: relationSpanishTitle,
},
},
Expand Down

0 comments on commit fba0847

Please sign in to comment.