2020-07-07 17:18:11 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2020-11-21 18:08:41 +01:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
2020-07-07 17:18:11 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetConfig(t *testing.T) {
|
|
|
|
t.Run("successful request", func(t *testing.T) {
|
|
|
|
app, router, _ := NewApiTest()
|
2022-09-28 09:01:17 +02:00
|
|
|
GetClientConfig(router)
|
2020-07-07 17:18:11 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/config")
|
|
|
|
val := gjson.Get(r.Body.String(), "flags")
|
2022-03-16 17:41:50 +01:00
|
|
|
assert.Equal(t, "public debug test sponsor experimental settings", val.String())
|
2020-07-07 17:18:11 +02:00
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
|
|
})
|
|
|
|
}
|
2021-03-10 16:55:55 +01:00
|
|
|
|
|
|
|
func TestGetConfigOptions(t *testing.T) {
|
|
|
|
t.Run("unauthorised", func(t *testing.T) {
|
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetConfigOptions(router)
|
|
|
|
r := PerformRequest(app, "GET", "/api/v1/config/options")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
2021-03-10 16:55:55 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSaveConfigOptions(t *testing.T) {
|
|
|
|
t.Run("unauthorised", func(t *testing.T) {
|
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
SaveConfigOptions(router)
|
|
|
|
r := PerformRequest(app, "POST", "/api/v1/config/options")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, http.StatusForbidden, r.Code)
|
2021-03-10 16:55:55 +01:00
|
|
|
})
|
|
|
|
}
|