Skip to content

Commit

Permalink
Bug return multi select fields in rest api response (#6253)
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull authored Jul 16, 2024
1 parent 753095d commit c0f6f52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import {
objectMetadataItemMock,
} from 'src/engine/api/__mocks__/object-metadata-item.mock';
import { mapFieldMetadataToGraphqlQuery } from 'src/engine/api/rest/core/query-builder/utils/map-field-metadata-to-graphql-query.utils';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';

describe('mapFieldMetadataToGraphqlQuery', () => {
it('should map properly', () => {
expect(
mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldNumberMock),
mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldNumberMock),
).toEqual('fieldNumber');
expect(
mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldTextMock),
mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldTextMock),
).toEqual('fieldText');
expect(
mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldLinkMock),
mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], fieldLinkMock),
).toEqual(`
fieldLink
{
Expand All @@ -25,7 +27,10 @@ describe('mapFieldMetadataToGraphqlQuery', () => {
}
`);
expect(
mapFieldMetadataToGraphqlQuery(objectMetadataItemMock, fieldCurrencyMock),
mapFieldMetadataToGraphqlQuery(
[objectMetadataItemMock],
fieldCurrencyMock,
),
).toEqual(`
fieldCurrency
{
Expand All @@ -34,4 +39,21 @@ describe('mapFieldMetadataToGraphqlQuery', () => {
}
`);
});
describe('should handle all field metadata types', () => {
Object.values(FieldMetadataType).forEach((fieldMetadataType) => {
it(`with field type ${fieldMetadataType}`, () => {
const field = {
type: fieldMetadataType,
name: 'toObjectMetadataName',
fromRelationMetadata: {
relationType: RelationMetadataType.ONE_TO_MANY,
},
};

expect(
mapFieldMetadataToGraphqlQuery([objectMetadataItemMock], field),
).toBeDefined();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ export const mapFieldMetadataToGraphqlQuery = (
FieldMetadataType.UUID,
FieldMetadataType.TEXT,
FieldMetadataType.PHONE,
FieldMetadataType.EMAIL,
FieldMetadataType.DATE_TIME,
FieldMetadataType.DATE,
FieldMetadataType.EMAIL,
FieldMetadataType.BOOLEAN,
FieldMetadataType.NUMBER,
FieldMetadataType.SELECT,
FieldMetadataType.NUMERIC,
FieldMetadataType.PROBABILITY,
FieldMetadataType.RATING,
FieldMetadataType.BOOLEAN,
FieldMetadataType.SELECT,
FieldMetadataType.MULTI_SELECT,
FieldMetadataType.POSITION,
FieldMetadataType.RAW_JSON,
].includes(fieldType);

if (fieldIsSimpleValue) {
Expand Down

0 comments on commit c0f6f52

Please sign in to comment.