handle schedule end date for galas

This commit is contained in:
Phillip Thelen
2024-04-26 13:03:34 +02:00
parent 30e81297da
commit fbdaa50fcf
2 changed files with 67 additions and 24 deletions

View File

@@ -3,33 +3,66 @@ import {
expectValidTranslationString, expectValidTranslationString,
} from '../helpers/content.helper'; */ } from '../helpers/content.helper'; */
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
// import { assembleScheduledMatchers } from '../../website/common/script/content/constants/schedule'; import { getAllScheduleMatchingGroups } from '../../website/common/script/content/constants/schedule';
function validateMatcher(matcher, checkedDate) {
expect(matcher.end).to.be.a('date');
expect(matcher.end).to.be.greaterThan(checkedDate);
}
describe('Content Schedule', () => { describe('Content Schedule', () => {
it('assembles scheduled items on january 15th', () => { it('assembles scheduled items on january 15th', () => {
// const items = assembleScheduledMatchers(new Date('2024-01-15')); const date = new Date('2024-01-15');
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on january 31th', () => { it('assembles scheduled items on january 31th', () => {
// const items = assembleScheduledMatchers(new Date('2024-01-31')); const date = new Date('2024-01-31')
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on march 2nd', () => { it('assembles scheduled items on march 2nd', () => {
// const items = assembleScheduledMatchers(new Date('2024-03-02')); const date = new Date('2024-03-02');
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on march 21st', () => { it('assembles scheduled items on march 21st', () => {
// const items = assembleScheduledMatchers(new Date('2024-03-21')); const date = new Date('2024-03-21');
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on october 7th', () => { it('assembles scheduled items on october 7th', () => {
// const items = assembleScheduledMatchers(new Date('2024-10-07')); const date = new Date('2024-10-07')
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on november 1th', () => { it('assembles scheduled items on november 1th', () => {
// const items = assembleScheduledMatchers(new Date('2024-11-01')); const date = new Date('2024-11-01');
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
it('assembles scheduled items on december 20th', () => { it('assembles scheduled items on december 20th', () => {
// const items = assembleScheduledMatchers(new Date('2024-12-20')); const date = new Date('2024-12-20');
const matchers = getAllScheduleMatchingGroups(date);
for (const key in matchers) {
validateMatcher(matchers[key], date);
}
}); });
}); });

View File

@@ -641,8 +641,8 @@ export const GALA_SCHEDULE = {
// Winter // Winter
0: { 0: {
startMonth: 11, startMonth: 11,
endMonth: 1, endMonth: 2,
filters: [ matchers: [
{ {
type: 'seasonalGear', type: 'seasonalGear',
items: SEASONAL_SETS.winter, items: SEASONAL_SETS.winter,
@@ -672,8 +672,8 @@ export const GALA_SCHEDULE = {
// Spring // Spring
1: { 1: {
startMonth: 2, startMonth: 2,
endMonth: 4, endMonth: 5,
filters: [ matchers: [
{ {
type: 'seasonalGear', type: 'seasonalGear',
items: SEASONAL_SETS.spring, items: SEASONAL_SETS.spring,
@@ -703,8 +703,8 @@ export const GALA_SCHEDULE = {
// Summer // Summer
2: { 2: {
startMonth: 5, startMonth: 5,
endMonth: 7, endMonth: 8,
filters: [ matchers: [
{ {
type: 'seasonalGear', type: 'seasonalGear',
items: SEASONAL_SETS.summer, items: SEASONAL_SETS.summer,
@@ -731,8 +731,8 @@ export const GALA_SCHEDULE = {
// Fall // Fall
3: { 3: {
startMonth: 8, startMonth: 8,
endMonth: 10, endMonth: 11,
filters: [ matchers: [
{ {
type: 'seasonalGear', type: 'seasonalGear',
items: SEASONAL_SETS.fall, items: SEASONAL_SETS.fall,
@@ -815,8 +815,12 @@ export function assembleScheduledMatchers (date) {
items.push(...value); items.push(...value);
} }
} }
const gala = GALA_SCHEDULE[getGalaIndex(date)];
items.push(...GALA_SCHEDULE[getGalaIndex(date)].filters); const galaMatchers = gala.matchers;
galaMatchers.forEach(matcher => {
matcher.endMonth = gala.endMonth;
});
items.push(...galaMatchers);
for (const event in getRepeatingEvents(date)) { for (const event in getRepeatingEvents(date)) {
if (event.content) { if (event.content) {
items.push(...event.content); items.push(...event.content);
@@ -849,6 +853,17 @@ function makeMatcherClass () {
}; };
} }
function makeEndDate(checkedDate, matcher) {
let end = moment(checkedDate);
end.date(TYPE_SCHEDULE[matcher.type]);
if (matcher.endMonth !== undefined) {
end.month(matcher.endMonth);
} else if (end.date() <= moment(checkedDate).date()) {
end = moment(end).add(1, 'months');
}
return end.toDate();
}
export function getAllScheduleMatchingGroups (date) { export function getAllScheduleMatchingGroups (date) {
const checkedDate = date || new Date(); const checkedDate = date || new Date();
if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate) if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate)
@@ -865,12 +880,7 @@ export function getAllScheduleMatchingGroups (date) {
if (!cachedScheduleMatchers[matcher.type]) { if (!cachedScheduleMatchers[matcher.type]) {
cachedScheduleMatchers[matcher.type] = makeMatcherClass(); cachedScheduleMatchers[matcher.type] = makeMatcherClass();
} }
const end = moment(checkedDate); cachedScheduleMatchers[matcher.type].end = makeEndDate(checkedDate, matcher);
end.date(TYPE_SCHEDULE[type]);
if (end.date() <= moment(checkedDate).date()) {
moment(end).add(1, 'months');
}
cachedScheduleMatchers[matcher.type].end = end.toDate();
if (matcher.matcher instanceof Function) { if (matcher.matcher instanceof Function) {
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher); cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
} else if (matcher.items instanceof Array) { } else if (matcher.items instanceof Array) {