Skip to content

Commit aeba5cb

Browse files
committed
wip
1 parent 3c14a49 commit aeba5cb

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

packages/twenty-server/src/engine/metadata-modules/field-metadata/services/field-metadata-related-records.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ export class FieldMetadataRelatedRecordsService {
132132
}
133133

134134
const viewFilterDisplayValues = viewFilter.displayValue.split(',');
135-
135+
if (viewFilterDisplayValues.length === 0) {
136+
return updatedOption.map((option) => option.new.label).join(', ');
137+
}
138+
136139
const remainingViewFilterDisplayValue = viewFilterDisplayValues.filter(
137140
(viewFilterOptionLabel) => {
138141
!deletedOption.find((option) => option.label === viewFilterOptionLabel);

packages/twenty-server/test/integration/graphql/utils/find-one-operation.util.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export const findOneOperation = async ({
3030
});
3131
}
3232

33-
if (response.body.errors) {
34-
console.log(response.body.errors);
35-
}
36-
37-
console.log(response.body.data);
3833
return {
3934
data: {
4035
findResponse: response.body.data[objectMetadataSingularName],

packages/twenty-server/test/integration/metadata/suites/field-metadata/__snapshots__/update-one-field-metadata-related-record.integration-spec.ts.snap

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/twenty-server/test/integration/metadata/suites/field-metadata/update-one-field-metadata-related-record.integration-spec.ts

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { faker } from '@faker-js/faker';
22
import { isDefined } from 'class-validator';
3-
import { FieldMetadataComplexOption, FieldMetadataDefaultOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
3+
import {
4+
FieldMetadataComplexOption,
5+
FieldMetadataDefaultOption,
6+
} from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
47
import { createOneOperation } from 'test/integration/graphql/utils/create-one-operation.util';
58
import { findOneOperation } from 'test/integration/graphql/utils/find-one-operation.util';
69
import { createOneFieldMetadata } from 'test/integration/metadata/suites/field-metadata/utils/create-one-field-metadata.util';
@@ -26,12 +29,18 @@ const generateOption = (index: number): Option => ({
2629
color: 'green',
2730
position: index,
2831
});
29-
const generateOptions = (length: number) =>
30-
Array.from({ length }, (_value, index) => generateOption(index));
32+
const generateOptionWithId = (index: number): Option & { id: string } => ({
33+
...generateOption(index),
34+
id: faker.string.uuid(),
35+
});
36+
const generateOptions = (length: number, withId: boolean = false) =>
37+
Array.from({ length }, (_value, index) =>
38+
withId ? generateOptionWithId(index) : generateOption(index),
39+
);
3140
const updateOption = ({ value, label, ...option }: Option) => ({
3241
...option,
33-
value: `${value}_${faker.lorem.word().toLocaleUpperCase()}`,
34-
label: `${label} ${faker.lorem.word()}`,
42+
value: `${value}_UPDATED`,
43+
label: `${label} updated`,
3544
});
3645

3746
const ALL_OPTIONS = generateOptions(10);
@@ -105,41 +114,49 @@ describe('updateOne', () => {
105114
}
106115
});
107116

117+
type ViewFilterUpdate = {
118+
displayValue: string;
119+
value: string;
120+
};
108121
const testCases: EachTestingContext<{
109-
initial: Option[];
110-
updateOptions: (options: FieldMetadataDefaultOption[] | FieldMetadataComplexOption[]) => Option[];
122+
fieldMetadataOptions: Option[];
123+
createViewFilter: ViewFilterUpdate;
124+
updateOptions: (
125+
options: FieldMetadataDefaultOption[] | FieldMetadataComplexOption[],
126+
) => Option[];
111127
expected?: null;
112128
}>[] = [
113129
// {
114130
// title:
115131
// 'should delete related view filter if all select field options got deleted',
116132
// context: {
117133
// initial: ALL_OPTIONS,
118-
// updated: generateOptions(3),
134+
// updateOptions: () => {
135+
// const withId = true;
136+
// return generateOptions(3, withId);
137+
// },
119138
// expected: null,
120139
// },
121140
// },
122141
// {
123142
// title: 'should update related view filter label',
124143
// context: {
125144
// initial: ALL_OPTIONS,
126-
// updated: ALL_OPTIONS.map((option, index) =>
127-
// isEven(option, index) ? updateOption(option) : option,
128-
// ),
129-
// },
130-
// },
131-
// {
132-
// title: 'should update related view filter with added options',
133-
// context: {
134-
// initial: ALL_OPTIONS.slice(0, 2),
135-
// updated: ALL_OPTIONS,
145+
// updateOptions: (options) =>
146+
// options.map((option, index) =>
147+
// isEven(option, index) ? updateOption(option) : option,
148+
// ),
136149
// },
137150
// },
138151
{
139-
title: 'should update related view filter updated option',
152+
title: 'should update related view filter with updated option',
140153
context: {
141-
initial: ALL_OPTIONS,
142-
updateOptions: (options: Option[]) =>
154+
fieldMetadataOptions: ALL_OPTIONS,
155+
createViewFilter: {
156+
displayValue: `${ALL_OPTIONS.length} options`,
157+
value: ALL_OPTIONS.map((option) => option.value).join(', '),
158+
},
159+
updateOptions: (options) =>
143160
options.map((option, index) =>
144161
index === 5 ? updateOption(option) : option,
145162
),
@@ -149,9 +166,16 @@ describe('updateOne', () => {
149166

150167
test.each(testCases)(
151168
'$title',
152-
async ({ context: { expected, initial, updateOptions } }) => {
169+
async ({
170+
context: {
171+
expected,
172+
createViewFilter,
173+
fieldMetadataOptions,
174+
updateOptions,
175+
},
176+
}) => {
153177
const { createOneField, createOneView } =
154-
await createObjectSelectFieldAndView(ALL_OPTIONS);
178+
await createObjectSelectFieldAndView(fieldMetadataOptions);
155179
const {
156180
data: { createOneResponse: createOneViewFilter },
157181
} = await createOneOperation<{
@@ -168,8 +192,8 @@ describe('updateOne', () => {
168192
viewId: createOneView.id,
169193
fieldMetadataId: createOneField.id,
170194
operand: 'is',
171-
value: JSON.stringify(initial.map(({ label }) => label)),
172-
displayValue: `${initial.length} options`,
195+
value: createViewFilter.value,
196+
displayValue: createViewFilter.displayValue,
173197
},
174198
});
175199

@@ -203,15 +227,14 @@ describe('updateOne', () => {
203227
},
204228
});
205229

206-
expect(errors).toMatchSnapshot();
207-
208230
if (expected !== undefined) {
231+
expect(errors).toMatchSnapshot();
209232
expect(findResponse).toBe(expected);
210233
return;
211234
}
212235

213236
expect(findResponse).toMatchSnapshot({
214-
id: createOneViewFilter.id,
237+
id: expect.any(String),
215238
});
216239
},
217240
);

0 commit comments

Comments
 (0)