|
@@ -1,13 +1,15 @@
|
|
|
package api
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "net/http"
|
|
|
"testing"
|
|
"testing"
|
|
|
-
|
|
|
|
|
- "github.com/grafana/grafana/pkg/models"
|
|
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
|
+ "github.com/grafana/grafana/pkg/models"
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
+ "github.com/stretchr/testify/require"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func TestUserApiEndpoint(t *testing.T) {
|
|
func TestUserApiEndpoint(t *testing.T) {
|
|
@@ -20,6 +22,55 @@ func TestUserApiEndpoint(t *testing.T) {
|
|
|
TotalCount: 2,
|
|
TotalCount: 2,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ loggedInUserScenario("When calling GET on", "api/users/:id", func(sc *scenarioContext) {
|
|
|
|
|
+ fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
|
|
|
|
|
+ bus.AddHandler("test", func(query *models.GetUserProfileQuery) error {
|
|
|
|
|
+ query.Result = models.UserProfileDTO{
|
|
|
|
|
+ Id: int64(1),
|
|
|
|
|
+ Email: "daniel@grafana.com",
|
|
|
|
|
+ Name: "Daniel",
|
|
|
|
|
+ Login: "danlee",
|
|
|
|
|
+ OrgId: int64(2),
|
|
|
|
|
+ IsGrafanaAdmin: true,
|
|
|
|
|
+ IsDisabled: false,
|
|
|
|
|
+ IsExternal: false,
|
|
|
|
|
+ UpdatedAt: fakeNow,
|
|
|
|
|
+ }
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ bus.AddHandler("test", func(query *models.GetAuthInfoQuery) error {
|
|
|
|
|
+ query.Result = &models.UserAuth{
|
|
|
|
|
+ AuthModule: models.AuthModuleLDAP,
|
|
|
|
|
+ }
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ sc.handlerFunc = GetUserByID
|
|
|
|
|
+ sc.fakeReqWithParams("GET", sc.url, map[string]string{}).exec()
|
|
|
|
|
+
|
|
|
|
|
+ expected := `
|
|
|
|
|
+ {
|
|
|
|
|
+ "id": 1,
|
|
|
|
|
+ "email": "daniel@grafana.com",
|
|
|
|
|
+ "name": "Daniel",
|
|
|
|
|
+ "login": "danlee",
|
|
|
|
|
+ "theme": "",
|
|
|
|
|
+ "orgId": 2,
|
|
|
|
|
+ "isGrafanaAdmin": true,
|
|
|
|
|
+ "isDisabled": false,
|
|
|
|
|
+ "isExternal": true,
|
|
|
|
|
+ "authLabels": [
|
|
|
|
|
+ "LDAP"
|
|
|
|
|
+ ],
|
|
|
|
|
+ "updatedAt": "2019-02-11T17:30:40Z"
|
|
|
|
|
+ }
|
|
|
|
|
+ `
|
|
|
|
|
+
|
|
|
|
|
+ require.Equal(t, http.StatusOK, sc.resp.Code)
|
|
|
|
|
+ require.JSONEq(t, expected, sc.resp.Body.String())
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
loggedInUserScenario("When calling GET on", "/api/users", func(sc *scenarioContext) {
|
|
loggedInUserScenario("When calling GET on", "/api/users", func(sc *scenarioContext) {
|
|
|
var sentLimit int
|
|
var sentLimit int
|
|
|
var sendPage int
|
|
var sendPage int
|