Skip to content

Commit

Permalink
Adding test to ensure we save notifications as alerted
Browse files Browse the repository at this point in the history
  • Loading branch information
Danzabar committed Apr 21, 2017
1 parent 22e04af commit 8d03807
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
13 changes: 13 additions & 0 deletions alert_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func SendAlerts() {
Preload("Tags.AlertGroups").
Where(Notification{Alerted: false, Read: false}).
Find(&n)

FilterCorrespondence(n)
}

func FilterCorrespondence(n []Notification) {
Expand Down Expand Up @@ -44,6 +46,17 @@ func FilterCorrespondence(n []Notification) {
}
}
}

UpdateNotifications(s)
}

func UpdateNotifications(n []Notification) {
for _, v := range n {
v.Alerted = true
v.Read = true

App.db.Save(&v)
}
}

func SendPushNotification(a AlertGroup, n []Notification) bool {
Expand Down
35 changes: 28 additions & 7 deletions alert_task_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
"testing"
)

func init() {
App = NewApp(":8888", "sqlite3", "/tmp/test.db", "test", "test")
App = NewApp(":8888", "sqlite3", "/tmp/test.db", "test", "test")

Migrate()
Migrate()

App.db.Delete(&Notification{})
App.db.Delete(&AlertGroup{})
App.db.Delete(&Tag{})
App.db.Delete(&Notification{})
App.db.Delete(&AlertGroup{})
App.db.Delete(&Tag{})
}

func TestItShouldUpdateNotificationsOnSend(t *testing.T) {
a := AlertGroup{Name: "NewTestGroup", Type: "email", Emails: "danzabian@gmail.com"}
App.db.Create(&a)

f := Tag{Name: "test"}
f.AlertGroups = append(f.AlertGroups, a)
App.db.Create(&f)

n := Notification{Message: "Test message"}
n.Tags = append(n.Tags, f)
App.db.Create(&n)

SendAlerts()

var o Notification
App.db.Where("ext_id = ?", n.ExtId).Find(&o)

assert.Equal(t, true, o.Alerted)
assert.Equal(t, true, o.Read)
}
2 changes: 1 addition & 1 deletion tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestPostTagSuccess(t *testing.T) {
json.NewDecoder(resp.Body).Decode(&tag)

assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "Test", tag.Name)
assert.Equal(t, "test1", tag.Name)
}

func TestPostTagValidation(t *testing.T) {
Expand Down

0 comments on commit 8d03807

Please sign in to comment.