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) {
|
2018-10-21 12:53:12 +00:00
|
|
|
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
|
2018-10-21 12:53:12 +00:00
|
|
|
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()
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
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)
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
if err := c.Notifications.Available(); err != nil {
|
2018-10-17 09:15:27 +00:00
|
|
|
t.SkipNow()
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
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)
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
if err := c.Notifications.Available(); err != nil {
|
2018-10-17 09:15:27 +00:00
|
|
|
t.SkipNow()
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
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)
|
|
|
|
// }
|
2018-10-21 12:53:12 +00:00
|
|
|
// 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)
|
|
|
|
// }
|
|
|
|
//}
|