Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): use timestamp if neither localized or universal are set #714

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/core/src/__tests__/e2e/api/records/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Records', () => {
values: [
{
id_value: null,
valuePayload: expect.any(String)
valuePayload: expect.any(Number)
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/__tests__/e2e/api/values/values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ describe('Values', () => {

expect(res.data.errors).toBeUndefined();
expect(res.data.data.saveValue[0].payload).toEqual({
from: '1/1/1970, 12:16:40 AM',
to: '1/1/1970, 12:33:20 AM'
from: 1000,
to: 2000
});
});

Expand Down
5 changes: 2 additions & 3 deletions apps/core/src/domain/actions/formatDateAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ describe('formatDateAction', () => {
});

describe('edge cases', () => {
test('should fallback to empty localized param when neither params provided', async () => {
test('should fallback to timestamp when no param is provided', async () => {
const resultWithoutParams = await action([testValue], {}, ctx);
const resultWithEmptyLocalizedParam = await action([testValue], {localized: '{}'}, ctx);
expect(resultWithoutParams).toEqual(resultWithEmptyLocalizedParam);
expect(resultWithoutParams.values[0].payload).toBe(2119477320);
});
test('should return empty string on non numerical value in DB', async () => {
expect((await action([{payload: 'aaaa', raw_payload: 'aaa'}], {}, ctx)).values[0].payload).toBe('');
Expand Down
4 changes: 4 additions & 0 deletions apps/core/src/domain/actions/formatDateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export default function (): IActionsListFunction<{localized: false; universal: f
return elementValue;
}

if (!localized) {
return elementValue;
}

let options: Intl.DateTimeFormatOptions = {};
try {
options = JSON.parse(localized ?? '{}');
Expand Down
6 changes: 6 additions & 0 deletions apps/core/src/domain/actions/formatDateRangeAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ describe('formatDateRangeAction', () => {
});

describe('edge cases', () => {
test('should fallback to timestamp when no param is provided', async () => {
const resultWithoutParams = await action([testValue], {}, ctx);
expect(resultWithoutParams.values[0].payload).toStrictEqual({from: '2119477320', to: '2119477380'});
});

test('should return null value if properties are omitted', async () => {
expect((await action([{payload: 'aaaa', raw_payload: 'aaa'}], {}, ctx)).values[0].payload).toBe(null);
expect((await action([{payload: {}, raw_payload: {}}], {}, ctx)).values[0].payload).toBe(null);
Expand All @@ -101,6 +106,7 @@ describe('formatDateRangeAction', () => {
).toBe(null);
expect((await action([{payload: null, raw_payload: null}], {}, ctx)).values[0].payload).toBe(null);
});

test('should return empty string couple on non numerical value in DB', async () => {
expect(
(
Expand Down
4 changes: 4 additions & 0 deletions apps/core/src/domain/actions/formatDateRangeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export default function (): IActionsListFunction<{localized: false; universal: f
};
}

if (!localized) {
return elementValue;
}

let options: Intl.DateTimeFormatOptions = {};
try {
options = JSON.parse(localized ?? '{}');
Expand Down
Loading