2015-07-16 10:59:11 -05:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTempUserCommandsAndQueries(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("Testing Temp User commands & queries", t, func() {
|
|
|
|
InitTestDB(t)
|
|
|
|
|
|
|
|
Convey("Given saved api key", func() {
|
|
|
|
cmd := m.CreateTempUserCommand{
|
2015-07-20 03:57:39 -05:00
|
|
|
OrgId: 2256,
|
|
|
|
Name: "hello",
|
2015-07-20 10:46:48 -05:00
|
|
|
Code: "asd",
|
2015-07-20 03:57:39 -05:00
|
|
|
Email: "e@as.co",
|
|
|
|
Status: m.TmpUserInvitePending,
|
2015-07-16 10:59:11 -05:00
|
|
|
}
|
|
|
|
err := CreateTempUser(&cmd)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
Convey("Should be able to get temp users by org id", func() {
|
2015-08-28 08:14:24 -05:00
|
|
|
query := m.GetTempUsersQuery{OrgId: 2256, Status: m.TmpUserInvitePending}
|
|
|
|
err = GetTempUsersQuery(&query)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(query.Result), ShouldEqual, 1)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Should be able to get temp users by email", func() {
|
|
|
|
query := m.GetTempUsersQuery{Email: "e@as.co", Status: m.TmpUserInvitePending}
|
|
|
|
err = GetTempUsersQuery(&query)
|
2015-07-16 10:59:11 -05:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(query.Result), ShouldEqual, 1)
|
|
|
|
})
|
|
|
|
|
2015-08-10 06:46:59 -05:00
|
|
|
Convey("Should be able to get temp users by code", func() {
|
|
|
|
query := m.GetTempUserByCodeQuery{Code: "asd"}
|
|
|
|
err = GetTempUserByCode(&query)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(query.Result.Name, ShouldEqual, "hello")
|
|
|
|
})
|
|
|
|
|
2015-07-20 03:57:39 -05:00
|
|
|
Convey("Should be able update status", func() {
|
2015-07-20 10:46:48 -05:00
|
|
|
cmd2 := m.UpdateTempUserStatusCommand{Code: "asd", Status: m.TmpUserRevoked}
|
2015-07-20 03:57:39 -05:00
|
|
|
err := UpdateTempUserStatus(&cmd2)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
|
2017-06-30 13:21:05 -05:00
|
|
|
Convey("Should be able update email sent and email sent on", func() {
|
|
|
|
cmd3 := m.UpdateTempUserWithEmailSentCommand{Code: cmd.Result.Code}
|
|
|
|
err := UpdateTempUserWithEmailSent(&cmd3)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
query := m.GetTempUsersQuery{OrgId: 2256, Status: m.TmpUserInvitePending}
|
|
|
|
err = GetTempUsersQuery(&query)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(query.Result[0].EmailSent, ShouldBeTrue)
|
|
|
|
So(query.Result[0].EmailSentOn, ShouldHappenOnOrAfter, (query.Result[0].Created))
|
|
|
|
})
|
|
|
|
|
2015-07-16 10:59:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|