Add notification interface and mail type
This commit is contained in:
parent
9fe46f9a61
commit
b6205de08b
|
@ -0,0 +1,75 @@
|
|||
// Vikunja is a to-do list application to facilitate your life.
|
||||
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public Licensee for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public Licensee
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package notifications
|
||||
|
||||
type Mail struct {
|
||||
from string
|
||||
to string
|
||||
subject string
|
||||
actionText string
|
||||
actionURL string
|
||||
greeting string
|
||||
introLines []string
|
||||
outroLines []string
|
||||
}
|
||||
|
||||
func NewMail() *Mail {
|
||||
return &Mail{
|
||||
greeting: "Hi,",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mail) From(from string) *Mail {
|
||||
m.from = from
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) To(to string) *Mail {
|
||||
m.to = to
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) Subject(subject string) *Mail {
|
||||
m.subject = subject
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) Greeting(greeting string) *Mail {
|
||||
m.greeting = greeting
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) Action(text, url string) *Mail {
|
||||
m.actionText = text
|
||||
m.actionURL = url
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Mail) Line(line string) *Mail {
|
||||
if m.actionURL == "" {
|
||||
m.introLines = append(m.introLines, line)
|
||||
return m
|
||||
}
|
||||
|
||||
m.outroLines = append(m.outroLines, line)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func RenderMail(mail *Mail) {
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
// Vikunja is a to-do list application to facilitate your life.
|
||||
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public Licensee for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public Licensee
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewMail(t *testing.T) {
|
||||
t.Run("Full mail", func(t *testing.T) {
|
||||
mail := NewMail().
|
||||
From("test@example.com").
|
||||
To("test@otherdomain.com").
|
||||
Subject("Testmail").
|
||||
Greeting("Hi there,").
|
||||
Line("This is a line").
|
||||
Line("And another one").
|
||||
Action("the actiopn", "https://example.com").
|
||||
Line("This should be an outro line").
|
||||
Line("And one more, because why not?")
|
||||
|
||||
assert.Equal(t, "test@example.com", mail.from)
|
||||
assert.Equal(t, "test@otherdomain.com", mail.to)
|
||||
assert.Equal(t, "Testmail", mail.subject)
|
||||
assert.Equal(t, "Hi there,", mail.greeting)
|
||||
assert.Len(t, mail.introLines, 2)
|
||||
assert.Equal(t, "This is a line", mail.introLines[0])
|
||||
assert.Equal(t, "And another one", mail.introLines[1])
|
||||
assert.Len(t, mail.outroLines, 2)
|
||||
assert.Equal(t, "This should be an outro line", mail.outroLines[0])
|
||||
assert.Equal(t, "And one more, because why not?", mail.outroLines[1])
|
||||
})
|
||||
t.Run("No greeting", func(t *testing.T) {
|
||||
mail := NewMail().
|
||||
From("test@example.com").
|
||||
To("test@otherdomain.com").
|
||||
Subject("Testmail").
|
||||
Line("This is a line").
|
||||
Line("And another one")
|
||||
|
||||
assert.Equal(t, "test@example.com", mail.from)
|
||||
assert.Equal(t, "test@otherdomain.com", mail.to)
|
||||
assert.Equal(t, "Testmail", mail.subject)
|
||||
assert.Equal(t, "Hi,", mail.greeting) // Default greeting
|
||||
assert.Len(t, mail.introLines, 2)
|
||||
assert.Equal(t, "This is a line", mail.introLines[0])
|
||||
assert.Equal(t, "And another one", mail.introLines[1])
|
||||
})
|
||||
t.Run("No action", func(t *testing.T) {
|
||||
mail := NewMail().
|
||||
From("test@example.com").
|
||||
To("test@otherdomain.com").
|
||||
Subject("Testmail").
|
||||
Line("This is a line").
|
||||
Line("And another one").
|
||||
Line("This should be an outro line").
|
||||
Line("And one more, because why not?")
|
||||
|
||||
assert.Equal(t, "test@example.com", mail.from)
|
||||
assert.Equal(t, "test@otherdomain.com", mail.to)
|
||||
assert.Equal(t, "Testmail", mail.subject)
|
||||
assert.Len(t, mail.introLines, 4)
|
||||
assert.Equal(t, "This is a line", mail.introLines[0])
|
||||
assert.Equal(t, "And another one", mail.introLines[1])
|
||||
assert.Equal(t, "This should be an outro line", mail.introLines[2])
|
||||
assert.Equal(t, "And one more, because why not?", mail.introLines[3])
|
||||
})
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// Vikunja is a to-do list application to facilitate your life.
|
||||
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public Licensee for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public Licensee
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package notifications
|
||||
|
||||
type Notification interface {
|
||||
ToMail() *Mail
|
||||
ToDB() interface{}
|
||||
}
|
Loading…
Reference in New Issue