accounts_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package sqlstore
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. m "github.com/torkelo/grafana-pro/pkg/models"
  6. )
  7. func TestAccountDataAccess(t *testing.T) {
  8. Convey("Testing Account DB Access", t, func() {
  9. InitTestDB(t)
  10. Convey("Given two saved accounts", func() {
  11. ac1 := m.Account{
  12. Login: "ac1",
  13. Email: "ac1@test.com",
  14. Name: "ac1_name",
  15. }
  16. ac2 := m.Account{
  17. Login: "ac2",
  18. Email: "ac2@test.com",
  19. Name: "ac2_name",
  20. }
  21. err := SaveAccount(&ac1)
  22. err = SaveAccount(&ac2)
  23. So(err, ShouldBeNil)
  24. Convey("Should be able to read account info projection", func() {
  25. query := m.GetAccountInfoQuery{Id: ac1.Id}
  26. err = GetAccountInfo(&query)
  27. So(err, ShouldBeNil)
  28. So(query.Result.Name, ShouldEqual, "ac1_name")
  29. })
  30. Convey("Can add collaborator", func() {
  31. cmd := m.AddCollaboratorCommand{
  32. AccountId: ac2.Id,
  33. ForAccountId: ac1.Id,
  34. Role: m.ROLE_READ_WRITE,
  35. }
  36. err := AddCollaborator(&cmd)
  37. Convey("Saved without error", func() {
  38. So(err, ShouldBeNil)
  39. })
  40. Convey("Collaborator should be included in account info projection", func() {
  41. query := m.GetAccountInfoQuery{Id: ac1.Id}
  42. err = GetAccountInfo(&query)
  43. So(err, ShouldBeNil)
  44. So(query.Result.Collaborators[0].AccountId, ShouldEqual, ac2.Id)
  45. So(query.Result.Collaborators[0].Role, ShouldEqual, m.ROLE_READ_WRITE)
  46. So(query.Result.Collaborators[0].Email, ShouldEqual, "ac2@test.com")
  47. })
  48. Convey("Can get other accounts", func() {
  49. query := m.GetOtherAccountsQuery{AccountId: ac2.Id}
  50. err := GetOtherAccounts(&query)
  51. So(err, ShouldBeNil)
  52. So(query.Result[0].Email, ShouldEqual, "ac1@test.com")
  53. })
  54. })
  55. })
  56. })
  57. }