Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Map all dates from server in HTTP services #632

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ export default class <%= entityAngularName %>Update extends <% if (fieldsContain
return null;
}

public mapAllDatesFromServer(dates: Date[]): string[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not called from anywhere?

if (dates) {
return dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
}
return null;
}

public updateInstantField(field, event) {
if (event.target.value) {
this.<%= entityInstance %>[field] = parse(event.target.value, DATE_TIME_LONG_FORMAT, new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ describe('Component Tests', () => {
expect(convertedDate).toEqual(format(date, DATE_TIME_LONG_FORMAT));
});

it('Should map all dates from server', () => {
// GIVEN
const date1 = new Date('2020-10-15T11:42:02Z');
const date2 = new Date('2020-11-15T11:42:02Z');
const date3 = new Date('2020-12-15T11:42:02Z');
const dates = [date1, date2, date3];
// WHEN
const convertedDates = comp.mapAllDatesFromServer(dates);

// THEN
const exceptedDates = dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
expect(convertedDates).toEqual(exceptedDates);
});

it('Should not map dates if dates are not present', () => {
expect(comp.mapAllDatesFromServer(null)).toBeNull();
});

it('Should not convert date if date is not present', () => {
expect(comp.convertDateTimeFromServer(null)).toBeNull();
});
Expand Down