fix: query localized fields without localization configured

This commit is contained in:
Dan Ribbens
2023-04-21 21:12:30 -04:00
parent c251801b1a
commit 12edb1cc4b
4 changed files with 28 additions and 1 deletions

View File

@@ -449,7 +449,7 @@ export class ParamParser {
// Skip the next iteration, because it's a locale
i += 1;
currentPath = `${currentPath}.${nextSegment}`;
} else if ('localized' in matchedField && matchedField.localized) {
} else if (this.localizationConfig && 'localized' in matchedField && matchedField.localized) {
currentPath = `${currentPath}.${this.req.locale}`;
}

View File

@@ -75,6 +75,12 @@ export default buildConfig({
name: 'number',
type: 'number',
},
{
name: 'fakeLocalization',
type: 'text',
// field is localized even though the config localization is not on
localized: true,
},
// Relationship
{
name: 'relationField',

View File

@@ -469,6 +469,24 @@ describe('collections-rest', () => {
});
});
describe('Edge cases', () => {
it('should query a localized field without localization configured', async () => {
const test = 'test';
await createPost({ fakeLocalization: test });
const { status, result } = await client.find({
query: {
fakeLocalization: {
equals: test,
},
},
});
expect(status).toEqual(200);
expect(result.docs).toHaveLength(1);
});
});
describe('Operators', () => {
it('equals', async () => {
const valueToQuery = 'valueToQuery';

View File

@@ -23,6 +23,7 @@ export interface Post {
title?: string;
description?: string;
number?: number;
fakeLocalization?: string;
relationField?: string | Relation;
relationHasManyField?: string[] | Relation[];
relationMultiRelationTo?:
@@ -55,6 +56,7 @@ export interface Post {
relationTo: 'dummy';
}
)[];
restrictedField?: string;
createdAt: string;
updatedAt: string;
}
@@ -66,6 +68,7 @@ export interface Relation {
}
export interface Dummy {
id: string;
title?: string;
name?: string;
createdAt: string;
updatedAt: string;