Workspace migration v2 testing (#13136)

# Introduction
Introduced `EachTesting` pattern for the builder unit tests.
As always any suggestions are more than welcomed !


Still need to:
- [x] implem basic tests for field
- [x] create `get-flat-index-field-metadata.mock.ts`
- [x] Implement basic tests for index and index-fields
- [ ] Implem standard edges cases tests TDD style

## Misc
- was https://github.com/twentyhq/twenty/pull/13132 closed due to mess
to rebase on main
This commit is contained in:
Paul Rastoin
2025-07-15 16:08:50 +02:00
committed by GitHub
parent 2c7a459634
commit c5a74b8e92
25 changed files with 3013 additions and 1575 deletions

View File

@ -0,0 +1,46 @@
import { isDefined } from 'twenty-shared/utils';
export const extractRecordIdsAndDatesAsExpectAny = (
record: Record<string, unknown> | Array<Record<string, unknown>>,
): any => {
if (Array.isArray(record)) {
return record.map(extractRecordIdsAndDatesAsExpectAny);
}
if (typeof record !== 'object') {
throw new Error(
'extractRecordIdsAndDatesAsExpectAny should be called with an array or a record only',
);
}
return Object.entries(record).reduce((acc, [key, value]) => {
if (!isDefined(value)) {
return acc;
}
if (key.endsWith('Id') || key === 'id') {
return {
...acc,
[key]: expect.any(String),
};
}
if (value instanceof Date) {
return {
...acc,
[key]: expect.any(Date),
};
}
if (typeof value === 'object' || Array.isArray(value)) {
return {
...acc,
[key]: extractRecordIdsAndDatesAsExpectAny(
value as Record<string, unknown>,
),
};
}
return acc;
}, {});
};