3
0

upd(messaging): type updates, tests

This commit is contained in:
Tit Petric 2019-04-03 15:09:23 +02:00
parent 106bbd19ae
commit fdc1e36239
5 changed files with 22 additions and 32 deletions

View File

@ -3,18 +3,18 @@ package types
import (
"time"
"encoding/json"
"github.com/jmoiron/sqlx/types"
"github.com/crusttech/crust/internal/rules"
)
type (
Channel struct {
ID uint64 `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Topic string `json:"topic" db:"topic"`
Type ChannelType `json:"type" db:"type"`
Meta json.RawMessage `json:"-" db:"meta"`
ID uint64 `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Topic string `json:"topic" db:"topic"`
Type ChannelType `json:"type" db:"type"`
Meta types.JSONText `json:"-" db:"meta"`
CreatorID uint64 `json:"creatorId" db:"rel_creator"`
OrganisationID uint64 `json:"organisationId" db:"rel_organisation"`

View File

@ -6,12 +6,6 @@ type (
Params CommandParamSet `db:"params" json:"params"`
Description string `db:"description" json:"description"`
}
CommandParam struct {
Name string `db:"name" json:"name"`
Type string `db:"type" json:"type"`
Required bool `db:"required" json:"required"`
}
)
var (

View File

@ -0,0 +1,9 @@
package types
type (
CommandParam struct {
Name string `db:"name" json:"name"`
Type string `db:"type" json:"type"`
Required bool `db:"required" json:"required"`
}
)

View File

@ -1,17 +0,0 @@
package types
import (
"fmt"
"runtime"
"testing"
)
func assert(t *testing.T, ok bool, format string, args ...interface{}) bool {
if !ok {
_, file, line, _ := runtime.Caller(1)
caller := fmt.Sprintf("\nAsserted at:%s:%d", file, line)
t.Fatalf(format+caller, args...)
}
return ok
}

View File

@ -1,14 +1,18 @@
// +build unit
package types
import (
"testing"
"github.com/crusttech/crust/internal/test"
)
func TestMentionSet_Diff(t *testing.T) {
ex := MentionSet{&Mention{ID: 1000}, &Mention{ID: 1001}}
add, upd, del := ex.Diff(MentionSet{&Mention{ID: 1001}, &Mention{UserID: 1}})
assert(t, len(add) == 1 && len(add.FindByUserID(1)) == 1, "Did not find expected mention (UserID:1) for creation")
assert(t, len(upd) == 1 && upd.FindByID(1001) != nil, "Did not find expected mention (id:1001) for update")
assert(t, len(del) == 1 && del.FindByID(1000) != nil, "Did not find expected mention (id:1000) for removal")
test.Assert(t, len(add) == 1 && len(add.FindByUserID(1)) == 1, "Did not find expected mention (UserID:1) for creation")
test.Assert(t, len(upd) == 1 && upd.FindByID(1001) != nil, "Did not find expected mention (id:1001) for update")
test.Assert(t, len(del) == 1 && del.FindByID(1000) != nil, "Did not find expected mention (id:1000) for removal")
}