2014-12-19 02:43:16 -06:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
|
|
|
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccountDataAccess(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("Testing Account DB Access", t, func() {
|
|
|
|
InitTestDB(t)
|
|
|
|
|
2014-12-19 03:45:22 -06:00
|
|
|
Convey("Given two saved accounts", func() {
|
|
|
|
ac1 := m.Account{
|
|
|
|
Login: "ac1",
|
|
|
|
Email: "ac1@test.com",
|
|
|
|
Name: "ac1_name",
|
2014-12-19 02:43:16 -06:00
|
|
|
}
|
2014-12-19 03:45:22 -06:00
|
|
|
ac2 := m.Account{
|
|
|
|
Login: "ac2",
|
|
|
|
Email: "ac2@test.com",
|
|
|
|
Name: "ac2_name",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := SaveAccount(&ac1)
|
|
|
|
err = SaveAccount(&ac2)
|
|
|
|
So(err, ShouldBeNil)
|
2014-12-19 02:43:16 -06:00
|
|
|
|
2014-12-19 03:45:22 -06:00
|
|
|
Convey("Should be able to read account info projection", func() {
|
|
|
|
query := m.GetAccountInfoQuery{Id: ac1.Id}
|
|
|
|
err = GetAccountInfo(&query)
|
2014-12-19 02:43:16 -06:00
|
|
|
|
2014-12-19 03:45:22 -06:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(query.Result.Name, ShouldEqual, "ac1_name")
|
|
|
|
})
|
2014-12-19 02:43:16 -06:00
|
|
|
|
2014-12-19 03:45:22 -06:00
|
|
|
Convey("Can add collaborator", func() {
|
|
|
|
cmd := m.AddCollaboratorCommand{
|
|
|
|
AccountId: ac2.Id,
|
|
|
|
ForAccountId: ac1.Id,
|
|
|
|
Role: m.ROLE_READ_WRITE,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := AddCollaborator(&cmd)
|
|
|
|
Convey("Saved without error", func() {
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Collaborator should be included in account info projection", func() {
|
|
|
|
query := m.GetAccountInfoQuery{Id: ac1.Id}
|
|
|
|
err = GetAccountInfo(&query)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(query.Result.Collaborators[0].AccountId, ShouldEqual, ac2.Id)
|
|
|
|
So(query.Result.Collaborators[0].Role, ShouldEqual, m.ROLE_READ_WRITE)
|
|
|
|
So(query.Result.Collaborators[0].Email, ShouldEqual, "ac2@test.com")
|
|
|
|
})
|
2014-12-19 04:08:49 -06:00
|
|
|
|
|
|
|
Convey("Can get other accounts", func() {
|
|
|
|
query := m.GetOtherAccountsQuery{AccountId: ac2.Id}
|
|
|
|
err := GetOtherAccounts(&query)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(query.Result[0].Email, ShouldEqual, "ac1@test.com")
|
|
|
|
})
|
2014-12-19 03:45:22 -06:00
|
|
|
})
|
2014-12-19 02:43:16 -06:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|