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:
@ -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;
|
||||
}, {});
|
||||
};
|
||||
Reference in New Issue
Block a user