Skip to content

Commit

Permalink
fix(JOB-148) : moves id inside activity property to reflect true data
Browse files Browse the repository at this point in the history
  • Loading branch information
ElsaTouzeau committed Oct 16, 2017
1 parent 2e54497 commit 4f474f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client/src/utils/projectStaffingNeededDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function _getArrayOfIdsWithDaysFromToday(jobs) {
return jobs.map((job) => {
const jobDate = moment(job.activity.staffing_needed_from, 'YYYY-MM-DD');
const daysFromToday = jobDate.diff(today, 'days');
return { id: job.id, daysFromToday };
return { activityId: job.activity.id, daysFromToday };
});
}

Expand All @@ -32,7 +32,7 @@ function _sortJobs(idsSorted, jobs) {
idsSorted.forEach((idSorted) => {
let idWasAlreadyFound = false;
jobsToBeSorted = jobsToBeSorted.filter((job) => {
if (!idWasAlreadyFound && idSorted.id === job.id) {
if (!idWasAlreadyFound && idSorted.activityId === job.activity.id) {
jobsSorted.push(job);
idWasAlreadyFound = true;
return false;
Expand Down
8 changes: 4 additions & 4 deletions client/test/unit/specs/utils/jobsSorter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Unit | Utils | Jobs Sorter', () => {
// given
jobs = [
{
id: 1,
activity: {
id: 1,
title: 'Tech Lead mission 1',
staffing_needed_from: '2017-10-01',
},
Expand All @@ -33,8 +33,8 @@ describe('Unit | Utils | Jobs Sorter', () => {
},
},
{
id: 2,
activity: {
id: 2,
title: 'Tech Lead mission 2',
staffing_needed_from: '2017-10-02',
},
Expand All @@ -56,8 +56,8 @@ describe('Unit | Utils | Jobs Sorter', () => {
},
},
{
id: 3,
activity: {
id: 3,
title: 'Tech Lead mission 3',
staffing_needed_from: '2017-10-03',
},
Expand All @@ -79,8 +79,8 @@ describe('Unit | Utils | Jobs Sorter', () => {
},
},
{
id: 4,
activity: {
id: 4,
title: 'Tech Lead mission 4',
staffing_needed_from: '2017-10-04',
},
Expand Down
36 changes: 18 additions & 18 deletions client/test/unit/specs/utils/projectStaffingNeededDate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('Unit | Utils | Project Staffing Needed Date', () => {

it('should sort two jobs according to project staffing needed date', () => {
// Given
const futureJob = { id: 1, activity: { staffing_needed_from: '2017-11-03' } };
const beforeYesterdayJob = { id: 2, activity: { staffing_needed_from: '2017-10-02' } };
const futureJob = { activity: { id: 1, staffing_needed_from: '2017-11-03' } };
const beforeYesterdayJob = { activity: { id: 2, staffing_needed_from: '2017-10-02' } };

const givenJobs = [futureJob, beforeYesterdayJob];
const expectedSortedJobs = [beforeYesterdayJob, futureJob];
Expand All @@ -28,11 +28,11 @@ describe('Unit | Utils | Project Staffing Needed Date', () => {

it('should sort five jobs according to project staffing needed date', () => {
// Given
const todayJob = { id: 1, activity: { staffing_needed_from: '2017-10-04' } };
const yesterdayJob = { id: 2, activity: { staffing_needed_from: '2017-10-03' } };
const beforeYesterdayJob = { id: 3, activity: { staffing_needed_from: '2017-10-02' } };
const oldJob = { id: 4, activity: { staffing_needed_from: '2017-10-01' } };
const tomorrowJob = { id: 5, activity: { staffing_needed_from: '2017-10-05' } };
const todayJob = { activity: { id: 1, staffing_needed_from: '2017-10-04' } };
const yesterdayJob = { activity: { id: 2, staffing_needed_from: '2017-10-03' } };
const beforeYesterdayJob = { activity: { id: 3, staffing_needed_from: '2017-10-02' } };
const oldJob = { activity: { id: 4, staffing_needed_from: '2017-10-01' } };
const tomorrowJob = { activity: { id: 5, staffing_needed_from: '2017-10-05' } };

const givenJobs = [todayJob, yesterdayJob, beforeYesterdayJob, oldJob, tomorrowJob];
const expectedSortedJobs = [todayJob, tomorrowJob, yesterdayJob, beforeYesterdayJob, oldJob];
Expand All @@ -46,11 +46,11 @@ describe('Unit | Utils | Project Staffing Needed Date', () => {

it('should sort five jobs with the same date according to project staffing needed date', () => {
// Given
const todayJob1 = { id: 1, activity: { staffing_needed_from: '2017-10-04' } };
const todayJob2 = { id: 2, activity: { staffing_needed_from: '2017-10-04' } };
const todayJob3 = { id: 3, activity: { staffing_needed_from: '2017-10-04' } };
const todayJob4 = { id: 4, activity: { staffing_needed_from: '2017-10-04' } };
const todayJob5 = { id: 5, activity: { staffing_needed_from: '2017-10-04' } };
const todayJob1 = { activity: { id: 1, staffing_needed_from: '2017-10-04' } };
const todayJob2 = { activity: { id: 2, staffing_needed_from: '2017-10-04' } };
const todayJob3 = { activity: { id: 3, staffing_needed_from: '2017-10-04' } };
const todayJob4 = { activity: { id: 4, staffing_needed_from: '2017-10-04' } };
const todayJob5 = { activity: { id: 5, staffing_needed_from: '2017-10-04' } };

const givenJobs = [todayJob1, todayJob2, todayJob3, todayJob4, todayJob5];
const expectedSortedJobs = [todayJob1, todayJob2, todayJob3, todayJob4, todayJob5];
Expand All @@ -63,12 +63,12 @@ describe('Unit | Utils | Project Staffing Needed Date', () => {

it('should sort jobs according to project staffing needed date', () => {
// Given
const futureJob = { id: 1, activity: { staffing_needed_from: '2017-11-03' } };
const beforeYesterdayJob = { id: 2, activity: { staffing_needed_from: '2017-10-02' } };
const todayJob = { id: 3, activity: { staffing_needed_from: '2017-10-04' } };
const veryOldJob = { id: 4, activity: { staffing_needed_from: '2017-09-15' } };
const yesterdayJob = { id: 5, activity: { staffing_needed_from: '2017-10-03' } };
const oldJob = { id: 6, activity: { staffing_needed_from: '2017-09-08' } };
const futureJob = { activity: { id: 1, staffing_needed_from: '2017-11-03' } };
const beforeYesterdayJob = { activity: { id: 2, staffing_needed_from: '2017-10-02' } };
const todayJob = { activity: { id: 3, staffing_needed_from: '2017-10-04' } };
const veryOldJob = { activity: { id: 4, staffing_needed_from: '2017-09-15' } };
const yesterdayJob = { activity: { id: 5, staffing_needed_from: '2017-10-03' } };
const oldJob = { activity: { id: 6, staffing_needed_from: '2017-09-08' } };

const givenJobs = [futureJob, beforeYesterdayJob, todayJob, veryOldJob, yesterdayJob, oldJob];
const expectedSortedJobs = [todayJob, yesterdayJob, beforeYesterdayJob, veryOldJob, oldJob, futureJob];
Expand Down

0 comments on commit 4f474f6

Please sign in to comment.