forked from ecamp/ecamp3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ecamp#3580 from usu/chore/period-dayResponsibles-f…
…ilter chore: add filter to query for all dayResponsibles of a period
- Loading branch information
Showing
10 changed files
with
127 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,82 @@ | ||
import { dayResponsiblesCommaSeparated } from '../dayResponsibles' | ||
import { | ||
dayResponsiblesCommaSeparated, | ||
filterDayResponsiblesByDay, | ||
} from '../dayResponsibles' | ||
|
||
describe('dayResponsibles', () => { | ||
it('resolves camp collaboration with and without user', () => { | ||
expect( | ||
dayResponsiblesCommaSeparated( | ||
const dayWith2Responsibles = { | ||
_meta: { | ||
self: '/day/1', | ||
}, | ||
period: () => ({ | ||
dayResponsibles: () => ({ | ||
items: [ | ||
{ | ||
dayResponsibles: () => ({ | ||
items: [ | ||
{ | ||
campCollaboration: () => ({ | ||
inviteEmail: '[email protected]', | ||
}), | ||
}, | ||
{ | ||
campCollaboration: () => ({ | ||
user: () => ({ | ||
displayName: 'dummyUser', | ||
}), | ||
}), | ||
}, | ||
], | ||
campCollaboration: () => ({ | ||
inviteEmail: '[email protected]', | ||
}), | ||
day: () => ({ | ||
_meta: { self: '/day/1' }, | ||
}), | ||
}, | ||
{ | ||
campCollaboration: () => ({ | ||
user: () => ({ | ||
displayName: 'dummyUser', | ||
}), | ||
}), | ||
day: () => ({ | ||
_meta: { self: '/day/1' }, | ||
}), | ||
}, | ||
null | ||
) | ||
).toEqual('[email protected], dummyUser') | ||
}) | ||
|
||
it('return empty string if no resonsibles', () => { | ||
expect( | ||
dayResponsiblesCommaSeparated( | ||
{ | ||
dayResponsibles: () => ({ | ||
items: [], | ||
campCollaboration: () => ({ | ||
user: () => ({ | ||
displayName: 'responsibleUserOnAnotherDay', | ||
}), | ||
}), | ||
day: () => ({ | ||
_meta: { self: '/day/2' }, | ||
}), | ||
}, | ||
null | ||
) | ||
).toEqual('') | ||
], | ||
}), | ||
}), | ||
} | ||
|
||
const dayWithoutResponsibles = { | ||
period: () => ({ | ||
dayResponsibles: () => ({ | ||
items: [], | ||
}), | ||
}), | ||
} | ||
|
||
describe('dayResponsiblesCommaSeparated', () => { | ||
it('resolves camp collaboration with and without user', () => { | ||
expect(dayResponsiblesCommaSeparated(dayWith2Responsibles, null)).toEqual( | ||
'[email protected], dummyUser' | ||
) | ||
}) | ||
|
||
it('return empty string if no responsibles', () => { | ||
expect(dayResponsiblesCommaSeparated(dayWithoutResponsibles, null)).toEqual('') | ||
}) | ||
|
||
it('return empty string for null object', () => { | ||
expect(dayResponsiblesCommaSeparated(null, null)).toEqual('') | ||
}) | ||
}) | ||
|
||
describe('filterDayResponsiblesByDay', () => { | ||
it('resolves camp collaboration with and without user', () => { | ||
expect(filterDayResponsiblesByDay(dayWith2Responsibles).length).toEqual(2) | ||
}) | ||
|
||
it('return empty string if no responsibles', () => { | ||
expect(filterDayResponsiblesByDay(dayWithoutResponsibles)).toEqual([]) | ||
}) | ||
|
||
it('return empty string for null object', () => { | ||
expect(filterDayResponsiblesByDay(null)).toEqual([]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import campCollaborationDisplayName from './campCollaborationDisplayName.js' | ||
|
||
const dayResponsiblesCommaSeparated = (day, tc) => { | ||
if (!day) return '' | ||
/** | ||
* Local filtering of dayResponsibles by day | ||
* (avoids separate network request for each day) | ||
*/ | ||
const filterDayResponsiblesByDay = (day) => { | ||
if (!day) return [] | ||
|
||
return day | ||
.period() | ||
.dayResponsibles() | ||
.items.map((dayResponsible) => | ||
.items.filter((dayResponsible) => dayResponsible.day()._meta.self === day._meta.self) | ||
} | ||
|
||
const dayResponsiblesCommaSeparated = (day, tc) => { | ||
if (!day) return '' | ||
|
||
return filterDayResponsiblesByDay(day) | ||
.map((dayResponsible) => | ||
campCollaborationDisplayName(dayResponsible.campCollaboration(), tc) | ||
) | ||
.join(', ') | ||
} | ||
|
||
export { dayResponsiblesCommaSeparated } | ||
export { filterDayResponsiblesByDay, dayResponsiblesCommaSeparated } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters