[FIX] Optimistically compute position only for objectMetadataItem that has the field (#10510)
# Introduction In this PR https://github.com/twentyhq/twenty/pull/10493 introduced a regression on optimistic cache for record creation, by expecting a `position` `fieldMetadataItem` on every `ObjectMetadataItem` which is a wrong assertion Some `Tasks` and `ApiKeys` do not have one ## Fix Dynamically compute optimistic record input position depending on current `ObjectMetadataItem` ## Refactor Refactored a failing test following [jest each](https://jestjs.io/docs/api#describeeachtablename-fn-timeout) pattern to avoid error prone duplicated env tests. Created a "standard' and applied it to an other test also using `it.each`.
This commit is contained in:
@ -1,23 +1,40 @@
|
||||
import { EachTestingContext } from '~/types/EachTestingContext';
|
||||
import { buildRecordFromKeysWithSameValue } from '~/utils/array/buildRecordFromKeysWithSameValue';
|
||||
|
||||
type BuildRecordFromKeysWithSameValueTestContext = EachTestingContext<{
|
||||
array: string[];
|
||||
expected: Record<string, boolean | string>;
|
||||
arg?: boolean | string;
|
||||
}>;
|
||||
|
||||
const buildRecordFromKeysWithSameValueTestUseCases: BuildRecordFromKeysWithSameValueTestContext[] =
|
||||
[
|
||||
{
|
||||
title: 'It should create record from array and fill with boolean',
|
||||
context: {
|
||||
array: ['foo', 'bar'] as const,
|
||||
expected: { foo: true, bar: true },
|
||||
arg: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'It should create record from array and fill with string',
|
||||
context: {
|
||||
array: ['foo', 'bar'],
|
||||
expected: { foo: 'oui', bar: 'oui' },
|
||||
arg: 'oui',
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'It should create empty record from empty array',
|
||||
context: { array: [], expected: {}, arg: undefined },
|
||||
},
|
||||
];
|
||||
describe('buildRecordFromKeysWithSameValue', () => {
|
||||
test.each([
|
||||
{ array: [], expected: {}, arg: undefined },
|
||||
{
|
||||
array: ['foo', 'bar'],
|
||||
expected: { foo: 'oui', bar: 'oui' },
|
||||
arg: 'oui',
|
||||
},
|
||||
{
|
||||
array: ['foo', 'bar'] as const,
|
||||
expected: { foo: true, bar: true },
|
||||
arg: true,
|
||||
},
|
||||
])(
|
||||
'.buildRecordFromKeysWithSameValue($array, $arg)',
|
||||
({ array, arg, expected }) => {
|
||||
const result = buildRecordFromKeysWithSameValue(array, arg);
|
||||
expect(result).toEqual(expected);
|
||||
},
|
||||
);
|
||||
test.each<BuildRecordFromKeysWithSameValueTestContext>(
|
||||
buildRecordFromKeysWithSameValueTestUseCases,
|
||||
)('.$title', ({ context: { array, arg, expected } }) => {
|
||||
const result = buildRecordFromKeysWithSameValue(array, arg);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user