Skip to content

Commit

Permalink
Update template-utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Nov 4, 2024
1 parent 0bcccaf commit 11a4617
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions generators/client/support/template-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,18 @@ export const generateTsTestEntityForFields = (
): Record<string, string | number | boolean> => {
const entries = fields
.map(field => {
const { fieldWithContentType, contentTypeFieldName } = field;
if (index === 'random') {
if (fieldWithContentType) {
const { fieldWithContentType, contentTypeFieldName, fieldTypeTimed, fieldTypeLocalDate } = field;

Check failure on line 133 in generators/client/support/template-utils.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Property 'fieldTypeTimed' does not exist on type 'Field'.

Check failure on line 133 in generators/client/support/template-utils.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Property 'fieldTypeLocalDate' does not exist on type 'Field'.

Check failure on line 133 in generators/client/support/template-utils.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Property 'fieldTypeTimed' does not exist on type 'Field'.

Check failure on line 133 in generators/client/support/template-utils.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Property 'fieldTypeLocalDate' does not exist on type 'Field'.
const fakeData = field.generateFakeData!('ts');
if (fieldWithContentType) {
return [
[field.propertyName, field.generateFakeData!('ts')],
[field.propertyName, fakeData],
[contentTypeFieldName, 'unknown'],
];
}
}
return [[field.propertyName, field.generateFakeData!('ts')]];
if (fieldTypeTimed || fieldTypeLocalDate) {
return [[field.propertyName, `dayjs(${fakeData})`]];
}
return [[field.propertyName, fakeData]];
})
.flat();
return Object.fromEntries(entries);
Expand All @@ -166,17 +168,14 @@ export const generateTestEntity = (references, index: 0 | 1 | 'random' = 'random
.map(reference => {
if (index === 'random') {
const field = reference.field;
const { fieldWithContentType, contentTypeFieldName, fieldTypeTimed, fieldTypeLocalDate } = field;
const { fieldWithContentType, contentTypeFieldName } = field;
const fakeData = field.generateFakeData('json-serializable');
if (fieldWithContentType) {
return [
[reference.name, fakeData],
[contentTypeFieldName, 'unknown'],
];
}
if (fieldTypeTimed || fieldTypeLocalDate) {
return [[fieldName, `dayjs(${fakeData})`]];
}
return [[reference.name, fakeData]];
}
return [[reference.name, generateTestEntityId(reference.type, index, false)]];
Expand Down

0 comments on commit 11a4617

Please sign in to comment.