Skip to content
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
11 changes: 11 additions & 0 deletions src/fn/compile-app-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const compileAppSettingsForProject = async (projectDir, options) => {
}
return maxTaskNotifications;
};
const isValidTimeFormat = (time) => /^([01]\d|2[0-3]):[0-5]\d$/.test(time);

// Fail if no eslintrc file is found
if (!fs.exists(esLintFilePath)) {
Expand Down Expand Up @@ -142,6 +143,16 @@ const compileAppSettingsForProject = async (projectDir, options) => {
delete appSettings.max_task_notifications;
}

if (appSettings.task_notification_window) {
const startTime = appSettings.task_notification_window.start;
const endTime = appSettings.task_notification_window.end;
if (!isValidTimeFormat(startTime) || !isValidTimeFormat(endTime)) {
throw new Error(`Invalid task notification window time`);
}
appSettings.tasks.task_notification_window = appSettings.task_notification_window;
delete appSettings.task_notification_window;
}

const purgeConfig = parsePurge(projectDir);
if (purgeConfig) {
appSettings.purge = purgeConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"tasks": {
"rules": "",
"targets": {},
"max_task_notifications": 25
"max_task_notifications": 25,
"task_notification_window": {
"start": "08:00",
"end": "19:00"
}
},
"purge": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"locale": "en",
"forms": {},
"max_task_notifications": 25,
"task_notification_window": {
"start": "08:00",
"end": "25:99"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"locale": "en",
"forms": {},
"max_task_notifications": 25
"max_task_notifications": 25,
"task_notification_window": {
"start": "08:00",
"end": "19:00"
}
}
9 changes: 7 additions & 2 deletions test/fn/compile-app-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const scenarios = [
description: 'should handle a configuration using the assetlinks.json file',
folder: 'android-app-links/project',
},
{
description: 'should compile max_task_notifications to tasks.max_task_notifications',
folder: 'task-notifications/project',
},

// REJECTION SCENARIOS
{
Expand Down Expand Up @@ -128,8 +132,9 @@ const scenarios = [
error: 'Invalid assetlinks: ValidationError: "[0].target.sha256_cert_fingerprints" is required',
},
{
description: 'should compile max_task_notifications to tasks.max_task_notifications',
folder: 'task-notifications/project',
description: 'should reject a task notification window with an invalid time format',
folder: 'task-notifications/invalid-notification-window',
error: 'Invalid task notification window time',
}
];

Expand Down
Loading