More migration to command/query and sql tests, looking good
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
func init() {
|
||||
bus.AddHandler("sql", GetAccountInfo)
|
||||
bus.AddHandler("sql", AddCollaborator)
|
||||
bus.AddHandler("sql", GetOtherAccounts)
|
||||
}
|
||||
|
||||
func GetAccountInfo(query *m.GetAccountInfoQuery) error {
|
||||
@@ -114,12 +115,12 @@ func GetAccountByLogin(emailOrLogin string) (*m.Account, error) {
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func GetOtherAccountsFor(accountId int64) ([]*m.OtherAccount, error) {
|
||||
collaborators := make([]*m.OtherAccount, 0)
|
||||
func GetOtherAccounts(query *m.GetOtherAccountsQuery) error {
|
||||
query.Result = make([]*m.OtherAccountDTO, 0)
|
||||
sess := x.Table("collaborator")
|
||||
sess.Join("INNER", "account", "collaborator.for_account_id=account.id")
|
||||
sess.Where("account_id=?", accountId)
|
||||
sess.Where("account_id=?", query.AccountId)
|
||||
sess.Cols("collaborator.id", "collaborator.role", "account.email")
|
||||
err := sess.Find(&collaborators)
|
||||
return collaborators, err
|
||||
err := sess.Find(&query.Result)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -58,6 +58,14 @@ func TestAccountDataAccess(t *testing.T) {
|
||||
So(query.Result.Collaborators[0].Role, ShouldEqual, m.ROLE_READ_WRITE)
|
||||
So(query.Result.Collaborators[0].Email, ShouldEqual, "ac2@test.com")
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,7 +38,6 @@ func Init() {
|
||||
m.SaveAccount = SaveAccount
|
||||
m.GetAccount = GetAccount
|
||||
m.GetAccountByLogin = GetAccountByLogin
|
||||
m.GetOtherAccountsFor = GetOtherAccountsFor
|
||||
m.GetDashboard = GetDashboard
|
||||
m.SaveDashboard = SaveDashboard
|
||||
m.SearchQuery = SearchQuery
|
||||
|
||||
Reference in New Issue
Block a user