gonextcloud/notifications_test.go

91 lines
1.7 KiB
Go
Raw Normal View History

2018-10-17 09:15:27 +00:00
package gonextcloud
import (
"github.com/stretchr/testify/assert"
"testing"
)
var (
notificationID int
createdID int
title = "Short Message"
message = "Longer notification message"
tests = []struct {
string
test
}{
{
"notificationCreate",
func(t *testing.T) {
err := c.Notifications().Create(config.Login, title, message)
2018-10-17 09:15:27 +00:00
assert.NoError(t, err)
},
}, {
"notificationDelete",
func(t *testing.T) {
// Get created Notification ID
ns, err := c.Notifications().List()
2018-10-17 09:15:27 +00:00
if err != nil {
t.SkipNow()
}
for _, n := range ns {
if n.Subject == title {
createdID = n.NotificationID
break
}
}
if createdID == 0 {
t.SkipNow()
}
err = c.Notifications().Delete(createdID)
2018-10-17 09:15:27 +00:00
assert.NoError(t, err)
},
},
}
)
func TestNotificationsList(t *testing.T) {
c = nil
if err := initClient(); err != nil {
t.Fatal(err)
}
if err := c.Notifications().Available(); err != nil {
2018-10-17 09:15:27 +00:00
t.SkipNow()
}
ns, err := c.Notifications().List()
2018-10-17 09:15:27 +00:00
assert.NoError(t, err)
if len(ns) > 0 {
notificationID = ns[0].NotificationID
}
}
func TestNotifications(t *testing.T) {
if notificationID == 0 {
t.SkipNow()
}
c = nil
if err := initClient(); err != nil {
t.Fatal(err)
}
if err := c.Notifications().Available(); err != nil {
2018-10-17 09:15:27 +00:00
t.SkipNow()
}
n, err := c.Notifications().Get(notificationID)
2018-10-17 09:15:27 +00:00
assert.NoError(t, err)
assert.NotEmpty(t, n)
}
// Disable due to very long response time
//func TestNotificationsAdmin(t *testing.T) {
// c = nil
// if err := initClient(); err != nil {
// t.Fatal(err)
// }
// if err := c.AdminAvailable(); err != nil {
2018-10-17 09:15:27 +00:00
// t.SkipNow()
// }
// for _, test := range tests {
// t.Run(test.string, test.test)
// }
//}