statping/handlers/messages_test.go

88 lines
2.4 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package handlers
import (
2020-03-08 18:13:27 +00:00
"github.com/stretchr/testify/assert"
2020-03-04 10:29:00 +00:00
"testing"
)
func TestMessagesApiRoutes(t *testing.T) {
tests := []HTTPTest{
{
Name: "Statping Messages",
URL: "/api/messages",
Method: "GET",
ExpectedStatus: 200,
ExpectedContains: []string{`"title":"Routine Downtime"`},
}, {
Name: "Statping Create Message",
URL: "/api/messages",
Method: "POST",
Body: `{
2020-03-08 18:13:27 +00:00
"title": "API Message",
"description": "This is an example a upcoming message for a service!",
"start_on": "2022-11-17T03:28:16.323797-08:00",
"end_on": "2022-11-17T05:13:16.323798-08:00",
"service": 1,
"notify_users": true,
"notify_method": "email",
"notify_before": 6,
"notify_before_scale": "hour"
}`,
2020-03-04 10:29:00 +00:00
ExpectedStatus: 200,
2020-04-17 03:21:17 +00:00
ExpectedContains: []string{Success, `"type":"message"`, `"method":"create"`, `"title":"API Message"`},
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
AfterTest: UnsetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
},
{
Name: "Statping View Message",
URL: "/api/messages/1",
Method: "GET",
ExpectedStatus: 200,
ExpectedContains: []string{`"title":"Routine Downtime"`},
2020-04-17 03:21:17 +00:00
},
{
2020-03-04 10:29:00 +00:00
Name: "Statping Update Message",
URL: "/api/messages/1",
Method: "POST",
Body: `{
2020-03-08 18:13:27 +00:00
"title": "Updated Message",
"description": "This message was updated",
"start_on": "2022-11-17T03:28:16.323797-08:00",
"end_on": "2022-11-17T05:13:16.323798-08:00",
"service": 1,
"notify_users": true,
"notify_method": "email",
"notify_before": 3,
"notify_before_scale": "hour"
}`,
2020-03-04 10:29:00 +00:00
ExpectedStatus: 200,
ExpectedContains: []string{`"status":"success"`, `"type":"message"`, `"method":"update"`},
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
2020-03-04 10:29:00 +00:00
},
{
Name: "Statping Delete Message",
URL: "/api/messages/1",
Method: "DELETE",
ExpectedStatus: 200,
ExpectedContains: []string{`"status":"success"`, `"method":"delete"`},
2020-03-08 18:13:27 +00:00
BeforeTest: SetTestENV,
2020-03-19 01:50:53 +00:00
SecureRoute: true,
2020-04-17 03:21:17 +00:00
},
{
Name: "Statping Missing Message",
URL: "/api/messages/999999",
Method: "GET",
ExpectedStatus: 404,
},
}
2020-03-04 10:29:00 +00:00
for _, v := range tests {
t.Run(v.Name, func(t *testing.T) {
_, t, err := RunHTTPTest(v, t)
2020-03-08 18:13:27 +00:00
assert.Nil(t, err)
2020-03-04 10:29:00 +00:00
})
}
}