upd(messaging): type updates, tests
This commit is contained in:
parent
106bbd19ae
commit
fdc1e36239
@ -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"`
|
||||
|
||||
@ -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 (
|
||||
|
||||
9
messaging/types/command_param.go
Normal file
9
messaging/types/command_param.go
Normal 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"`
|
||||
}
|
||||
)
|
||||
@ -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
|
||||
}
|
||||
@ -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")
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user