project decides if task is new

This commit is contained in:
Erik Winter 2021-09-22 18:38:45 +02:00
parent f500150974
commit f8cd648119
3 changed files with 26 additions and 23 deletions

View File

@ -35,15 +35,15 @@ func TestInboxProcess(t *testing.T) {
}, },
{ {
Subject: "to recurring", Subject: "to recurring",
Body: "recur: 2021-05-14, daily\nid: xxx-xxx-a\nversion: 1", Body: "recur: 2021-05-14, daily\nid: xxx-xxx-a\nversion: 1\nproject: project\n",
}, },
{ {
Subject: "to planned", Subject: "to planned",
Body: "due: 2021-05-14\nid: xxx-xxx-b\nversion: 1", Body: "due: 2021-05-14\nid: xxx-xxx-b\nversion: 1\nproject: project\n",
}, },
{ {
Subject: "to unplanned", Subject: "to unplanned",
Body: "id: xxx-xxx-c\nversion: 1", Body: "id: xxx-xxx-c\nversion: 1\nproject: project\n",
}, },
}, },
}, },
@ -51,45 +51,45 @@ func TestInboxProcess(t *testing.T) {
expMsgs: map[string][]*mstore.Message{ expMsgs: map[string][]*mstore.Message{
task.FOLDER_INBOX: {}, task.FOLDER_INBOX: {},
task.FOLDER_NEW: {{Subject: "to new"}}, task.FOLDER_NEW: {{Subject: "to new"}},
task.FOLDER_RECURRING: {{Subject: "to recurring"}}, task.FOLDER_RECURRING: {{Subject: "project - to recurring"}},
task.FOLDER_PLANNED: {{Subject: "2021-05-14 (friday) - to planned"}}, task.FOLDER_PLANNED: {{Subject: "2021-05-14 (friday) - project - to planned"}},
task.FOLDER_UNPLANNED: {{Subject: "to unplanned"}}, task.FOLDER_UNPLANNED: {{Subject: "project - to unplanned"}},
}, },
}, },
{ {
name: "cleanup", name: "cleanup",
messages: map[string][]*mstore.Message{ messages: map[string][]*mstore.Message{
task.FOLDER_INBOX: {{ task.FOLDER_INBOX: {{
Subject: "new version", Subject: "project - new version",
Body: "id: xxx-xxx\nversion: 3", Body: "id: xxx-xxx\nversion: 3\nproject: project\n",
}}, }},
task.FOLDER_UNPLANNED: {{ task.FOLDER_UNPLANNED: {{
Subject: "old version", Subject: "old version",
Body: "id: xxx-xxx\nversion: 3", Body: "id: xxx-xxx\nversion: 3\nproject: project\n",
}}, }},
}, },
expCount: 1, expCount: 1,
expMsgs: map[string][]*mstore.Message{ expMsgs: map[string][]*mstore.Message{
task.FOLDER_INBOX: {}, task.FOLDER_INBOX: {},
task.FOLDER_UNPLANNED: {{Subject: "new version"}}, task.FOLDER_UNPLANNED: {{Subject: "project - new version"}},
}, },
}, },
{ {
name: "cleanup version conflict", name: "cleanup version conflict",
messages: map[string][]*mstore.Message{ messages: map[string][]*mstore.Message{
task.FOLDER_INBOX: {{ task.FOLDER_INBOX: {{
Subject: "new version", Subject: "project - new version",
Body: "id: xxx-xxx\nversion: 3", Body: "id: xxx-xxx\nversion: 3\nproject\n",
}}, }},
task.FOLDER_UNPLANNED: {{ task.FOLDER_UNPLANNED: {{
Subject: "not really old version", Subject: "project - not really old version",
Body: "id: xxx-xxx\nversion: 5", Body: "id: xxx-xxx\nversion: 5\nproject: project\n",
}}, }},
}, },
expCount: 1, expCount: 1,
expMsgs: map[string][]*mstore.Message{ expMsgs: map[string][]*mstore.Message{
task.FOLDER_INBOX: {}, task.FOLDER_INBOX: {},
task.FOLDER_UNPLANNED: {{Subject: "not really old version"}}, task.FOLDER_UNPLANNED: {{Subject: "project - not really old version"}},
}, },
}, },
{ {
@ -115,23 +115,23 @@ func TestInboxProcess(t *testing.T) {
messages: map[string][]*mstore.Message{ messages: map[string][]*mstore.Message{
task.FOLDER_INBOX: { task.FOLDER_INBOX: {
{ {
Subject: "version 2", Subject: "project - version 2",
Body: "id: xxx-xxx\nversion: 1\n", Body: "id: xxx-xxx\nversion: 1\nproject: project\n",
}, },
{ {
Subject: "version 2b", Subject: "project - version 2b",
Body: "id: xxx-xxx\nversion: 1\n", Body: "id: xxx-xxx\nversion: 1\nproject: project\n",
}, },
}, },
task.FOLDER_UNPLANNED: {{ task.FOLDER_UNPLANNED: {{
Subject: "the task", Subject: "project - the task",
Body: "id: xxx-xxx\nversion: 1\n", Body: "id: xxx-xxx\nversion: 1\nproject: project\n",
}}, }},
}, },
expCount: 1, expCount: 1,
expMsgs: map[string][]*mstore.Message{ expMsgs: map[string][]*mstore.Message{
task.FOLDER_INBOX: {}, task.FOLDER_INBOX: {},
task.FOLDER_UNPLANNED: {{Subject: "version 2b"}}, task.FOLDER_UNPLANNED: {{Subject: "project - version 2b"}},
}, },
}, },
} { } {

View File

@ -118,7 +118,7 @@ func NewFromMessage(msg *mstore.Message) *Task {
func (t *Task) TargetFolder() string { func (t *Task) TargetFolder() string {
switch { switch {
case t.Version == 0: case t.Project == "":
return FOLDER_NEW return FOLDER_NEW
case t.IsRecurrer(): case t.IsRecurrer():
return FOLDER_RECURRING return FOLDER_RECURRING

View File

@ -198,6 +198,7 @@ func TestTaskTargetFolder(t *testing.T) {
tsk: &task.Task{ tsk: &task.Task{
Id: "id", Id: "id",
Version: 2, Version: 2,
Project: "project",
Recur: task.Daily{Start: task.NewDate(2021, 06, 21)}, Recur: task.Daily{Start: task.NewDate(2021, 06, 21)},
}, },
expFolder: task.FOLDER_RECURRING, expFolder: task.FOLDER_RECURRING,
@ -207,6 +208,7 @@ func TestTaskTargetFolder(t *testing.T) {
tsk: &task.Task{ tsk: &task.Task{
Id: "id", Id: "id",
Version: 2, Version: 2,
Project: "project",
Due: task.NewDate(2021, 06, 21), Due: task.NewDate(2021, 06, 21),
}, },
expFolder: task.FOLDER_PLANNED, expFolder: task.FOLDER_PLANNED,
@ -216,6 +218,7 @@ func TestTaskTargetFolder(t *testing.T) {
tsk: &task.Task{ tsk: &task.Task{
Id: "id", Id: "id",
Version: 2, Version: 2,
Project: "project",
}, },
expFolder: task.FOLDER_UNPLANNED, expFolder: task.FOLDER_UNPLANNED,
}, },