diff --git a/.travis.yml b/.travis.yml
index 0e0ee860..9289565b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -61,6 +61,7 @@ before_install:
- curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o $GOPATH/bin/dep
- chmod +x $GOPATH/bin/dep
- npm install -g sass
+ - npm install -g newman
install:
- make dev-deps
@@ -73,6 +74,8 @@ before_script:
script:
- make test-all
+ - DB_CONN=postgres statup &
+ - sleep 15 && newman run source/tmpl/postman.json -e dev/postman_environment.json
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" = "false" ]]; then make coverage; fi
after_success:
diff --git a/Makefile b/Makefile
index 94a3ae76..1fb265ca 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=0.79.83
+VERSION=0.79.84
BINARY_NAME=statup
GOPATH:=$(GOPATH)
GOCMD=go
diff --git a/core/database.go b/core/database.go
index 9a79ec86..44a2473a 100644
--- a/core/database.go
+++ b/core/database.go
@@ -133,6 +133,12 @@ func (c *checkinHit) AfterFind() (err error) {
return
}
+// AfterFind for Message will set the timezone
+func (u *Message) AfterFind() (err error) {
+ u.CreatedAt = utils.Timezoner(u.CreatedAt, CoreApp.Timezone)
+ return
+}
+
// BeforeCreate for Hit will set CreatedAt to UTC
func (h *Hit) BeforeCreate() (err error) {
if h.CreatedAt.IsZero() {
@@ -157,6 +163,14 @@ func (u *User) BeforeCreate() (err error) {
return
}
+// BeforeCreate for Message will set CreatedAt to UTC
+func (u *Message) BeforeCreate() (err error) {
+ if u.CreatedAt.IsZero() {
+ u.CreatedAt = time.Now().UTC()
+ }
+ return
+}
+
// BeforeCreate for Service will set CreatedAt to UTC
func (s *Service) BeforeCreate() (err error) {
if s.CreatedAt.IsZero() {
diff --git a/dev/postman_environment.json b/dev/postman_environment.json
new file mode 100644
index 00000000..1a44e9e6
--- /dev/null
+++ b/dev/postman_environment.json
@@ -0,0 +1,15 @@
+{
+ "id": "0ff1dcd6-54f3-44a7-9c18-cc3c8e7df357",
+ "name": "Local Statup",
+ "values": [
+ {
+ "key": "endpoint",
+ "value": "http://127.0.0.1:8080",
+ "description": "",
+ "enabled": true
+ }
+ ],
+ "_postman_variable_scope": "environment",
+ "_postman_exported_at": "2018-11-17T16:55:15.031Z",
+ "_postman_exported_using": "Postman/6.5.2"
+}
\ No newline at end of file
diff --git a/handlers/api.go b/handlers/api.go
index cc4bf4b0..a383b1c2 100644
--- a/handlers/api.go
+++ b/handlers/api.go
@@ -18,7 +18,6 @@ package handlers
import (
"encoding/json"
"errors"
- "fmt"
"github.com/gorilla/mux"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/core/notifier"
@@ -30,11 +29,12 @@ import (
)
type apiResponse struct {
- Status string `json:"status"`
- Object string `json:"type,omitempty"`
- Id int64 `json:"id,omitempty"`
- Method string `json:"method,omitempty"`
- Error string `json:"error,omitempty"`
+ Status string `json:"status"`
+ Object string `json:"type,omitempty"`
+ Method string `json:"method,omitempty"`
+ Error string `json:"error,omitempty"`
+ Id int64 `json:"id,omitempty"`
+ Output interface{} `json:"output,omitempty"`
}
func apiIndexHandler(w http.ResponseWriter, r *http.Request) {
@@ -147,8 +147,7 @@ func apiCreateServiceHandler(w http.ResponseWriter, r *http.Request) {
sendErrorJson(err, w, r)
return
}
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(service)
+ sendJsonAction(newService, "create", w, r)
}
func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
@@ -157,24 +156,21 @@ func apiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
return
}
vars := mux.Vars(r)
- srv := core.SelectServicer(utils.StringInt(vars["id"]))
- if srv.Select() == nil {
+ service := core.SelectServicer(utils.StringInt(vars["id"]))
+ if service.Select() == nil {
sendErrorJson(errors.New("service not found"), w, r)
return
}
- var updatedService *core.Service
decoder := json.NewDecoder(r.Body)
- decoder.Decode(&updatedService)
- updatedService.Id = srv.Select().Id
-
- err := updatedService.Update(true)
+ decoder.Decode(&service)
+ err := service.Update(true)
if err != nil {
sendErrorJson(err, w, r)
return
}
- go updatedService.Check(true)
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(updatedService)
+ go service.Check(true)
+
+ sendJsonAction(service, "update", w, r)
}
func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
@@ -193,14 +189,7 @@ func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) {
sendErrorJson(err, w, r)
return
}
- output := apiResponse{
- Object: "service",
- Method: "delete",
- Id: service.Id,
- Status: "success",
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(output)
+ sendJsonAction(service, "delete", w, r)
}
func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
@@ -234,154 +223,24 @@ func apiNotifierUpdateHandler(w http.ResponseWriter, r *http.Request) {
return
}
vars := mux.Vars(r)
- var notification *notifier.Notification
- decoder := json.NewDecoder(r.Body)
- err := decoder.Decode(¬ification)
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
notifer, not, err := notifier.SelectNotifier(vars["notifier"])
if err != nil {
sendErrorJson(err, w, r)
return
}
- notifer.Var1 = notification.Var1
- notifer.Var2 = notification.Var2
- notifer.Host = notification.Host
- notifer.Port = notification.Port
- notifer.Password = notification.Password
- notifer.Username = notification.Username
- notifer.ApiKey = notification.ApiKey
- notifer.ApiSecret = notification.ApiSecret
- notifer.Enabled = types.NewNullBool(notification.Enabled.Bool)
-
+ decoder := json.NewDecoder(r.Body)
+ err = decoder.Decode(¬ifer)
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
_, err = notifier.Update(not, notifer)
if err != nil {
sendErrorJson(err, w, r)
return
}
notifier.OnSave(notifer.Method)
-
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(notifer)
-}
-
-func apiAllMessagesHandler(w http.ResponseWriter, r *http.Request) {
- if !isAPIAuthorized(r) {
- sendUnauthorizedJson(w, r)
- return
- }
- messages, err := core.SelectMessages()
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(messages)
-}
-
-func apiMessageCreateHandler(w http.ResponseWriter, r *http.Request) {
- if !isAPIAuthorized(r) {
- sendUnauthorizedJson(w, r)
- return
- }
- var message *types.Message
- decoder := json.NewDecoder(r.Body)
- err := decoder.Decode(&message)
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
- msg := core.ReturnMessage(message)
- _, err = msg.Create()
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(msg)
-}
-
-func apiMessageGetHandler(w http.ResponseWriter, r *http.Request) {
- if !isAPIAuthorized(r) {
- sendUnauthorizedJson(w, r)
- return
- }
- vars := mux.Vars(r)
- message, err := core.SelectMessage(utils.StringInt(vars["id"]))
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(message)
-}
-
-func apiMessageDeleteHandler(w http.ResponseWriter, r *http.Request) {
- if !isAPIAuthorized(r) {
- sendUnauthorizedJson(w, r)
- return
- }
- vars := mux.Vars(r)
- message, err := core.SelectMessage(utils.StringInt(vars["id"]))
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
- err = message.Delete()
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
-
- output := apiResponse{
- Object: "message",
- Method: "delete",
- Id: message.Id,
- Status: "success",
- }
-
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(output)
-}
-
-func apiMessageUpdateHandler(w http.ResponseWriter, r *http.Request) {
- if !isAPIAuthorized(r) {
- sendUnauthorizedJson(w, r)
- return
- }
- vars := mux.Vars(r)
- message, err := core.SelectMessage(utils.StringInt(vars["id"]))
- if err != nil {
- sendErrorJson(fmt.Errorf("message #%v was not found", vars["id"]), w, r)
- return
- }
- var messageBody *types.Message
- decoder := json.NewDecoder(r.Body)
- err = decoder.Decode(&messageBody)
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
-
- messageBody.Id = message.Id
- message = core.ReturnMessage(messageBody)
- _, err = message.Update()
- if err != nil {
- sendErrorJson(err, w, r)
- return
- }
-
- output := apiResponse{
- Object: "message",
- Method: "update",
- Id: message.Id,
- Status: "success",
- }
-
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(output)
+ sendJsonAction(notifer, "update", w, r)
}
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
@@ -407,6 +266,49 @@ func sendErrorJson(err error, w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(output)
}
+func sendJsonAction(obj interface{}, method string, w http.ResponseWriter, r *http.Request) {
+ var objName string
+ var objId int64
+ switch v := obj.(type) {
+ case types.ServiceInterface:
+ objName = "service"
+ objId = v.Select().Id
+ case *notifier.Notification:
+ objName = "notifier"
+ objId = v.Id
+ case *core.Core, *types.Core:
+ objName = "core"
+ case *types.User:
+ objName = "user"
+ objId = v.Id
+ case *core.User:
+ objName = "user"
+ objId = v.Id
+ case *types.Message:
+ objName = "message"
+ objId = v.Id
+ case *core.Message:
+ objName = "message"
+ objId = v.Id
+ case *types.Checkin:
+ objName = "checkin"
+ objId = v.Id
+ default:
+ objName = "missing"
+ }
+
+ output := apiResponse{
+ Object: objName,
+ Method: method,
+ Id: objId,
+ Status: "success",
+ Output: obj,
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(output)
+}
+
func sendUnauthorizedJson(w http.ResponseWriter, r *http.Request) {
output := apiResponse{
Status: "error",
@@ -418,6 +320,7 @@ func sendUnauthorizedJson(w http.ResponseWriter, r *http.Request) {
}
func isAPIAuthorized(r *http.Request) bool {
+ utils.Http(r)
if os.Getenv("GO_ENV") == "test" {
return true
}
diff --git a/handlers/messages.go b/handlers/messages.go
index c7270536..fc72ed79 100644
--- a/handlers/messages.go
+++ b/handlers/messages.go
@@ -16,8 +16,11 @@
package handlers
import (
+ "encoding/json"
+ "fmt"
"github.com/gorilla/mux"
"github.com/hunterlong/statup/core"
+ "github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils"
"net/http"
)
@@ -45,3 +48,97 @@ func viewMessageHandler(w http.ResponseWriter, r *http.Request) {
}
executeResponse(w, r, "message.html", message, nil)
}
+
+func apiAllMessagesHandler(w http.ResponseWriter, r *http.Request) {
+ if !isAPIAuthorized(r) {
+ sendUnauthorizedJson(w, r)
+ return
+ }
+ messages, err := core.SelectMessages()
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(messages)
+}
+
+func apiMessageCreateHandler(w http.ResponseWriter, r *http.Request) {
+ if !isAPIAuthorized(r) {
+ sendUnauthorizedJson(w, r)
+ return
+ }
+ var message *types.Message
+ decoder := json.NewDecoder(r.Body)
+ err := decoder.Decode(&message)
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ msg := core.ReturnMessage(message)
+ _, err = msg.Create()
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ sendJsonAction(msg, "create", w, r)
+}
+
+func apiMessageGetHandler(w http.ResponseWriter, r *http.Request) {
+ if !isAPIAuthorized(r) {
+ sendUnauthorizedJson(w, r)
+ return
+ }
+ vars := mux.Vars(r)
+ message, err := core.SelectMessage(utils.StringInt(vars["id"]))
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(message)
+}
+
+func apiMessageDeleteHandler(w http.ResponseWriter, r *http.Request) {
+ if !isAPIAuthorized(r) {
+ sendUnauthorizedJson(w, r)
+ return
+ }
+ vars := mux.Vars(r)
+ message, err := core.SelectMessage(utils.StringInt(vars["id"]))
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ err = message.Delete()
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ sendJsonAction(message, "delete", w, r)
+}
+
+func apiMessageUpdateHandler(w http.ResponseWriter, r *http.Request) {
+ if !isAPIAuthorized(r) {
+ sendUnauthorizedJson(w, r)
+ return
+ }
+ vars := mux.Vars(r)
+ message, err := core.SelectMessage(utils.StringInt(vars["id"]))
+ if err != nil {
+ sendErrorJson(fmt.Errorf("message #%v was not found", vars["id"]), w, r)
+ return
+ }
+ decoder := json.NewDecoder(r.Body)
+ err = decoder.Decode(&message)
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ _, err = message.Update()
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
+ sendJsonAction(message, "update", w, r)
+}
diff --git a/handlers/routes.go b/handlers/routes.go
index 258fbd5e..1042fbf3 100644
--- a/handlers/routes.go
+++ b/handlers/routes.go
@@ -77,7 +77,6 @@ func Router() *mux.Router {
r.Handle("/settings/css", http.HandlerFunc(saveSASSHandler)).Methods("POST")
r.Handle("/settings/build", http.HandlerFunc(saveAssetsHandler)).Methods("GET")
r.Handle("/settings/delete_assets", http.HandlerFunc(deleteAssetsHandler)).Methods("GET")
- r.Handle("/settings/notifier/{method}/test", http.HandlerFunc(testNotificationHandler)).Methods("POST")
r.Handle("/settings/export", http.HandlerFunc(exportHandler)).Methods("GET")
// SERVICE Routes
@@ -117,6 +116,7 @@ func Router() *mux.Router {
r.Handle("/api/notifiers", http.HandlerFunc(apiNotifiersHandler)).Methods("GET")
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("GET")
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierUpdateHandler)).Methods("POST")
+ r.Handle("/api/notifier/{method}/test", http.HandlerFunc(testNotificationHandler)).Methods("POST")
// API MESSAGES Routes
r.Handle("/api/messages", http.HandlerFunc(apiAllMessagesHandler)).Methods("GET")
diff --git a/handlers/users.go b/handlers/users.go
index c1b4d9e8..d6abf4ed 100644
--- a/handlers/users.go
+++ b/handlers/users.go
@@ -18,6 +18,7 @@ package handlers
import (
"encoding/json"
"errors"
+ "fmt"
"github.com/gorilla/mux"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/types"
@@ -70,21 +71,17 @@ func apiUserUpdateHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
user, err := core.SelectUser(utils.StringInt(vars["id"]))
if err != nil {
- sendErrorJson(err, w, r)
+ sendErrorJson(fmt.Errorf("user #%v was not found", vars["id"]), w, r)
return
}
- var updateUser *types.User
decoder := json.NewDecoder(r.Body)
- decoder.Decode(&updateUser)
- updateUser.Id = user.Id
- user = core.ReturnUser(updateUser)
+ decoder.Decode(&user)
err = user.Update()
if err != nil {
- sendErrorJson(err, w, r)
+ sendErrorJson(fmt.Errorf("issue updating user #%v: %v", user.Id, err), w, r)
return
}
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(user)
+ sendJsonAction(user, "update", w, r)
}
func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
@@ -108,14 +105,7 @@ func apiUserDeleteHandler(w http.ResponseWriter, r *http.Request) {
sendErrorJson(err, w, r)
return
}
- output := apiResponse{
- Object: "user",
- Method: "delete",
- Id: user.Id,
- Status: "success",
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(output)
+ sendJsonAction(user, "delete", w, r)
}
func apiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
@@ -145,17 +135,10 @@ func apiCreateUsersHandler(w http.ResponseWriter, r *http.Request) {
return
}
newUser := core.ReturnUser(user)
- uId, err := newUser.Create()
+ _, err = newUser.Create()
if err != nil {
sendErrorJson(err, w, r)
return
}
- output := apiResponse{
- Object: "user",
- Method: "create",
- Id: uId,
- Status: "success",
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(output)
+ sendJsonAction(newUser, "create", w, r)
}
diff --git a/source/js/main.js b/source/js/main.js
index 749f585a..917aa56a 100644
--- a/source/js/main.js
+++ b/source/js/main.js
@@ -30,10 +30,7 @@ $('.test_notifier').on('click', function(e) {
var notifier = form.find('input[name=notifier]').val();
var success = $('#'+notifier+'-success');
var error = $('#'+notifier+'-error');
- var spinner = '';
- var btnHtml = btn.html();
- btn.prop("disabled", true);
- btn.html(spinner);
+ Spinner(btn);
$.ajax({
url: form.attr("action")+"/test",
type: 'POST',
@@ -51,8 +48,7 @@ $('.test_notifier').on('click', function(e) {
error.addClass('d-none');
}, 8000)
}
- btn.prop("disabled", false);
- btn.html(btnHtml);
+ Spinner(btn, true);
}
});
e.preventDefault();
@@ -186,6 +182,12 @@ $('form.ajax_form').on('submit', function() {
if (k.value === "on") {
k.value = (k.value === "on")
}
+ if (k.value === "false") {
+ k.value = false
+ }
+ if (k.value === "true") {
+ k.value = true
+ }
if($.isNumeric(k.value)){
if (k.name !== "password") {
k.value = parseInt(k.value)
@@ -225,7 +227,7 @@ $('form.ajax_form').on('submit', function() {
function CreateService(output) {
console.log('creating service', output)
let form = output.form;
- let data = output.data;
+ let data = output.data.output;
let objTbl = `
${form.name} |
${data.online}ONLINE |
@@ -242,7 +244,7 @@ function CreateService(output) {
function CreateUser(output) {
console.log('creating user', output)
let form = output.form;
- let data = output.data;
+ let data = output.data.output;
let objTbl = `
${form.username} |
diff --git a/source/tmpl/postman.json b/source/tmpl/postman.json
index 8af2d66b..3f03c12b 100644
--- a/source/tmpl/postman.json
+++ b/source/tmpl/postman.json
@@ -11,6 +11,27 @@
"item": [
{
"name": "Statup Details",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "08b8f487-2318-44b9-bdb8-f1f1041e9462",
+ "exec": [
+ "pm.test(\"Check Core API Route\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.name).to.eql(\"Statup\");",
+ " pm.expect(jsonData.description).to.eql(\"Statup Monitoring Sample Data\");",
+ " pm.expect(jsonData.using_cdn).to.eql(false);",
+ " pm.expect(jsonData.database).to.eql(\"sqlite\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "protocolProfileBehavior": {
+ "disableBodyPruning": true
+ },
"request": {
"auth": {
"type": "bearer",
@@ -53,7 +74,22 @@
"name": "Services",
"item": [
{
- "name": "View All Services",
+ "name": "All Services",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "d87f8a4e-7640-45b8-9d45-4f6e6f2463ee",
+ "exec": [
+ "pm.test(\"View All Services\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.length).to.eql(5);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -67,7 +103,10 @@
},
"method": "GET",
"header": [],
- "body": {},
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
"url": {
"raw": "{{endpoint}}/api/services",
"host": [
@@ -83,6 +122,26 @@
},
{
"name": "View Service",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "023c5643-6cb1-4cd0-b775-566f232d68f8",
+ "exec": [
+ "pm.test(\"View Service\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.name).to.eql(\"Google\");",
+ " pm.expect(jsonData.status_code).to.eql(200);",
+ " pm.expect(jsonData.type).to.eql(\"http\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "protocolProfileBehavior": {
+ "disableBodyPruning": true
+ },
"request": {
"auth": {
"type": "bearer",
@@ -95,8 +154,18 @@
]
},
"method": "GET",
- "header": [],
- "body": {},
+ "header": [
+ {
+ "key": "Content-Type",
+ "name": "Content-Type",
+ "value": "application/json",
+ "type": "text"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n\t\"token\": {\n\t\t\"value\": \"ExponentPushToken[SBryVgIxjgaMKCP5MBtt2J]\"\n\t},\n\t\"user\": {\n\t\t\"username\": \"Brent\"\n\t}\n}"
+ },
"url": {
"raw": "{{endpoint}}/api/services/1",
"host": [
@@ -111,8 +180,86 @@
},
"response": []
},
+ {
+ "name": "View Service Chart Data",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "023c5643-6cb1-4cd0-b775-566f232d68f8",
+ "exec": [
+ "pm.test(\"Service Chart Default\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.data.length).to.be.at.least(100);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "protocolProfileBehavior": {
+ "disableBodyPruning": true
+ },
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{api_key}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "GET",
+ "header": [
+ {
+ "key": "Content-Type",
+ "name": "Content-Type",
+ "type": "text",
+ "value": "application/json"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/services/1/data",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "services",
+ "1",
+ "data"
+ ]
+ }
+ },
+ "response": []
+ },
{
"name": "Create Service",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "d4eb16fe-8495-40e5-9ca3-be20951e5133",
+ "exec": [
+ "pm.test(\"Create Service\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.output.name).to.eql(\"New Service\");",
+ " pm.expect(jsonData.output.domain).to.eql(\"https://statup.io\");",
+ " pm.expect(jsonData.output.type).to.eql(\"http\");",
+ " pm.expect(jsonData.output.method).to.eql(\"GET\");",
+ " pm.expect(jsonData.output.expected_status).to.eql(200);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -133,7 +280,7 @@
],
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"New Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 15,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0\n}"
+ "raw": "{\n \"name\": \"New Service\",\n \"domain\": \"https://statup.io\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 30,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 30,\n \"order_id\": 0\n}"
},
"url": {
"raw": "{{endpoint}}/api/services",
@@ -150,6 +297,25 @@
},
{
"name": "Update Service",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "b5a67a19-fd08-40b0-a961-3e9474ab78c6",
+ "exec": [
+ "pm.test(\"Update Service\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.output.name).to.eql(\"Updated Google Service\");",
+ " pm.expect(jsonData.output.domain).to.eql(\"https://google.com\");",
+ " pm.expect(jsonData.output.type).to.eql(\"http\");",
+ " pm.expect(jsonData.output.method).to.eql(\"GET\");",
+ " pm.expect(jsonData.output.expected_status).to.eql(200);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -170,17 +336,17 @@
],
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"Updated Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 60,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0\n}"
+ "raw": "{\n\t\"id\": 1,\n \"name\": \"Updated Google Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 60,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0\n}"
},
"url": {
- "raw": "{{endpoint}}/api/services/19",
+ "raw": "{{endpoint}}/api/services/1",
"host": [
"{{endpoint}}"
],
"path": [
"api",
"services",
- "19"
+ "1"
]
}
},
@@ -188,6 +354,23 @@
},
{
"name": "Delete Service",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "dd4d721d-d874-448b-abc9-59c1afceb58e",
+ "exec": [
+ "pm.test(\"Delete Service\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ " pm.expect(jsonData.type).to.eql(\"service\");",
+ " pm.expect(jsonData.method).to.eql(\"delete\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -255,6 +438,28 @@
"item": [
{
"name": "View All Users",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "9a2977fe-9689-4039-bdcb-eaa34abee958",
+ "exec": [
+ "pm.test(\"View All Users\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.length).to.eql(1);",
+ " var user = jsonData[0];",
+ " pm.expect(user.id).to.eql(1);",
+ " pm.expect(user.username).to.eql(\"admin\");",
+ " pm.expect(user.email).to.eql(\"info@admin.com\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "protocolProfileBehavior": {
+ "disableBodyPruning": true
+ },
"request": {
"auth": {
"type": "bearer",
@@ -282,8 +487,80 @@
},
"response": []
},
+ {
+ "name": "Create User",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "1913466d-83b2-4d5b-ac48-89c9abdd0c8d",
+ "exec": [
+ "pm.test(\"Create User\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ " pm.expect(jsonData.type).to.eql(\"user\");",
+ " pm.expect(jsonData.method).to.eql(\"create\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "{{api_key}}",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "value": "application/json"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"username\": \"admissdsn2\",\n \"email\": \"info@emsdssssail.com\",\n \"password\": \"passsword123\",\n \"admin\": true\n}"
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/users",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "users"
+ ]
+ }
+ },
+ "response": []
+ },
{
"name": "View User",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "555b7ba4-bb36-4e86-a541-fa5a5008f951",
+ "exec": [
+ "pm.test(\"View User\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.id).to.eql(1);",
+ " pm.expect(jsonData.username).to.eql(\"admin\");",
+ " pm.expect(jsonData.email).to.eql(\"info@admin.com\");",
+ " pm.expect(jsonData.admin).to.eql(true);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -297,7 +574,10 @@
},
"method": "GET",
"header": [],
- "body": {},
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
"url": {
"raw": "{{endpoint}}/api/users/1",
"host": [
@@ -312,45 +592,33 @@
},
"response": []
},
- {
- "name": "Create User",
- "request": {
- "auth": {
- "type": "bearer",
- "bearer": [
- {
- "key": "token",
- "value": "{{api_key}}",
- "type": "string"
- }
- ]
- },
- "method": "POST",
- "header": [
- {
- "key": "Content-Type",
- "value": "application/json"
- }
- ],
- "body": {
- "mode": "raw",
- "raw": "{\n \"username\": \"admin\",\n \"email\": \"info@email.com\",\n \"password\": \"password123\",\n \"admin\": true\n}"
- },
- "url": {
- "raw": "{{endpoint}}/api/users",
- "host": [
- "{{endpoint}}"
- ],
- "path": [
- "api",
- "users"
- ]
- }
- },
- "response": []
- },
{
"name": "Update User",
+ "event": [
+ {
+ "listen": "prerequest",
+ "script": {
+ "id": "d23b1822-d1de-4545-9a82-3cf4719a7e82",
+ "exec": [
+ ""
+ ],
+ "type": "text/javascript"
+ }
+ },
+ {
+ "listen": "test",
+ "script": {
+ "id": "b0d22bbd-a428-4df3-8295-b40542bfa21f",
+ "exec": [
+ "pm.test(\"Update User\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -371,17 +639,17 @@
],
"body": {
"mode": "raw",
- "raw": "{\n \"username\": \"adminupdated\",\n \"email\": \"info@email.com\",\n \"password\": \"password123\",\n \"admin\": true\n}"
+ "raw": "{\n \"username\": \"adminupdated\",\n \"email\": \"info@email.com\",\n \"password\": \"password12345\",\n \"admin\": true\n}"
},
"url": {
- "raw": "{{endpoint}}/api/users/4",
+ "raw": "{{endpoint}}/api/users/1",
"host": [
"{{endpoint}}"
],
"path": [
"api",
"users",
- "4"
+ "1"
]
}
},
@@ -389,6 +657,24 @@
},
{
"name": "Delete User",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "bd8c3425-a97f-4f8c-b849-71b65dd543ee",
+ "exec": [
+ "pm.test(\"Delete User\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ " pm.expect(jsonData.type).to.eql(\"user\");",
+ " pm.expect(jsonData.id).to.eql(1);",
+ " pm.expect(jsonData.method).to.eql(\"delete\");",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
@@ -404,14 +690,14 @@
"header": [],
"body": {},
"url": {
- "raw": "{{endpoint}}/api/users/4",
+ "raw": "{{endpoint}}/api/users/1",
"host": [
"{{endpoint}}"
],
"path": [
"api",
"users",
- "4"
+ "1"
]
}
},
@@ -454,6 +740,53 @@
{
"name": "Notifiers",
"item": [
+ {
+ "name": "All Notifiers",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "e9105618-6db8-4a57-ae7f-782989842f4a",
+ "exec": [
+ "pm.test(\"View All Notifiers\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.length).to.eql(8);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "auth": {
+ "type": "bearer",
+ "bearer": [
+ {
+ "key": "token",
+ "value": "e351393306ea245de5f9588cbe8627c74db007c6",
+ "type": "string"
+ }
+ ]
+ },
+ "method": "GET",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/notifiers",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "notifiers"
+ ]
+ }
+ },
+ "response": []
+ },
{
"name": "View Notifier",
"request": {
@@ -462,7 +795,7 @@
"bearer": [
{
"key": "token",
- "value": "",
+ "value": "e351393306ea245de5f9588cbe8627c74db007c6",
"type": "string"
}
]
@@ -489,13 +822,31 @@
},
{
"name": "Update Notifier",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "d714d71d-4d6a-4b2e-a6ea-16c34dec3041",
+ "exec": [
+ "pm.test(\"Update Notifier\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.output.method).to.eql(\"mobile\");",
+ " pm.expect(jsonData.output.enabled).to.eql(true);",
+ " pm.expect(jsonData.output.limits).to.eql(55);",
+ " pm.expect(jsonData.output.removeable).to.eql(false);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
- "value": "",
+ "value": "e351393306ea245de5f9588cbe8627c74db007c6",
"type": "string"
}
]
@@ -511,7 +862,7 @@
],
"body": {
"mode": "raw",
- "raw": "{\n \"method\": \"mobile\",\n \"host\": \"\",\n \"port\": 0,\n \"username\": \"\",\n \"var1\": \"ExponentPushToken[XmsQVgIxjgaMKCP5MBoOp9]\",\n \"var2\": \"\",\n \"api_key\": \"\",\n \"api_secret\": \"\",\n \"enabled\": true,\n \"limits\": 3\n}"
+ "raw": "{\n \"method\": \"mobile\",\n \"host\": \"\",\n \"port\": 0,\n \"username\": \"\",\n \"var1\": \"ExponentPushToken[ToBadIWillError123456]\",\n \"var2\": \"\",\n \"api_key\": \"\",\n \"api_secret\": \"\",\n \"enabled\": true,\n \"limits\": 55\n}"
},
"url": {
"raw": "{{endpoint}}/api/notifier/mobile",
@@ -533,11 +884,225 @@
"bearer": [
{
"key": "token",
- "value": "",
+ "value": "e351393306ea245de5f9588cbe8627c74db007c6",
"type": "string"
}
]
}
+ },
+ {
+ "name": "Messages",
+ "item": [
+ {
+ "name": "All Messages",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "3c484d1b-6e77-4084-b844-3ca77dc50108",
+ "exec": [
+ "pm.test(\"View All Messages\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.length).to.eql(2);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "method": "GET",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/messages",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "messages"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "Create Message",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "12caf74a-61d7-4f6e-89b5-fca2f65464c4",
+ "exec": [
+ "pm.test(\"Create Message\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.output.title).to.eql(\"API Message\");",
+ " pm.expect(jsonData.output.service).to.eql(1);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "name": "Content-Type",
+ "value": "application/json",
+ "type": "text"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"title\": \"API Message\",\n \"description\": \"This is an example a upcoming message for a service!\",\n \"start_on\": \"2022-11-17T03:28:16.323797-08:00\",\n \"end_on\": \"2022-11-17T05:13:16.323798-08:00\",\n \"service\": 1,\n \"notify_users\": null,\n \"notify_method\": \"\",\n \"notify_before\": 0\n}"
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/messages",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "messages"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "View Message",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "abbb5178-9613-418c-b5ee-be2d6b4fdb8f",
+ "exec": [
+ "pm.test(\"View Message\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.title).to.eql(\"Routine Downtime\");",
+ " pm.expect(jsonData.service).to.eql(1);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "method": "GET",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/messages/1",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "messages",
+ "1"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "Update Message",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "a0403c03-0838-4fd2-9cce-aebaf8a128c3",
+ "exec": [
+ "pm.test(\"Update Message\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ " pm.expect(jsonData.method).to.eql(\"update\");",
+ " pm.expect(jsonData.id).to.eql(1);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "method": "POST",
+ "header": [
+ {
+ "key": "Content-Type",
+ "name": "Content-Type",
+ "value": "application/json",
+ "type": "text"
+ }
+ ],
+ "body": {
+ "mode": "raw",
+ "raw": "{\n \"title\": \"Routine Downtime\",\n \"description\": \"This is an example a upcoming message for a service!\",\n \"start_on\": \"2055-11-17T03:28:16.323797-08:00\",\n \"end_on\": \"2055-11-17T05:13:16.323798-08:00\",\n \"service\": 2,\n \"notify_users\": true,\n \"notify_method\": \"email\",\n \"notify_before\": 900\n}"
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/messages/1",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "messages",
+ "1"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "Delete Message",
+ "event": [
+ {
+ "listen": "test",
+ "script": {
+ "id": "6cb2527f-41c2-4feb-9573-1e4d59efa116",
+ "exec": [
+ "pm.test(\"Delete Message\", function () {",
+ " var jsonData = pm.response.json();",
+ " pm.expect(jsonData.status).to.eql(\"success\");",
+ " pm.expect(jsonData.method).to.eql(\"delete\");",
+ " pm.expect(jsonData.type).to.eql(\"message\");",
+ " pm.expect(jsonData.id).to.eql(1);",
+ "});"
+ ],
+ "type": "text/javascript"
+ }
+ }
+ ],
+ "request": {
+ "method": "DELETE",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": ""
+ },
+ "url": {
+ "raw": "{{endpoint}}/api/messages/1",
+ "host": [
+ "{{endpoint}}"
+ ],
+ "path": [
+ "api",
+ "messages",
+ "1"
+ ]
+ }
+ },
+ "response": []
+ }
+ ]
}
]
}
\ No newline at end of file
|