accounts_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. ac1cmd := m.CreateAccountCommand{Login: "ac1", Email: "ac1@test.com"}
  12. ac2cmd := m.CreateAccountCommand{Login: "ac2", Email: "ac2@test.com"}
  13. err := CreateAccount(&ac1cmd)
  14. err = CreateAccount(&ac2cmd)
  15. So(err, ShouldBeNil)
  16. ac1 := ac1cmd.Result
  17. ac2 := ac2cmd.Result
  18. Convey("Should be able to read account info projection", func() {
  19. query := m.GetAccountInfoQuery{Id: ac1.Id}
  20. err = GetAccountInfo(&query)
  21. So(err, ShouldBeNil)
  22. So(query.Result.Email, ShouldEqual, "ac1@test.com")
  23. })
  24. Convey("Can add collaborator", func() {
  25. cmd := m.AddCollaboratorCommand{
  26. AccountId: ac1.Id,
  27. CollaboratorId: ac2.Id,
  28. Role: m.ROLE_READ_WRITE,
  29. }
  30. err := AddCollaborator(&cmd)
  31. Convey("Saved without error", func() {
  32. So(err, ShouldBeNil)
  33. })
  34. Convey("Collaborator should be included in account info projection", func() {
  35. query := m.GetAccountInfoQuery{Id: ac1.Id}
  36. err = GetAccountInfo(&query)
  37. So(err, ShouldBeNil)
  38. So(query.Result.Collaborators[0].CollaboratorId, ShouldEqual, ac2.Id)
  39. So(query.Result.Collaborators[0].Role, ShouldEqual, m.ROLE_READ_WRITE)
  40. So(query.Result.Collaborators[0].Email, ShouldEqual, "ac2@test.com")
  41. })
  42. Convey("Can get other accounts", func() {
  43. query := m.GetOtherAccountsQuery{AccountId: ac2.Id}
  44. err := GetOtherAccounts(&query)
  45. So(err, ShouldBeNil)
  46. So(query.Result[0].Email, ShouldEqual, "ac1@test.com")
  47. })
  48. Convey("Can set using account", func() {
  49. cmd := m.SetUsingAccountCommand{AccountId: ac2.Id, UsingAccountId: ac1.Id}
  50. err := SetUsingAccount(&cmd)
  51. So(err, ShouldBeNil)
  52. })
  53. })
  54. })
  55. })
  56. }