2021-09-03 16:14:09 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPerson(t *testing.T) {
|
|
|
|
t.Run("BillGates", func(t *testing.T) {
|
|
|
|
subj := Subject{
|
2021-09-17 14:26:12 +02:00
|
|
|
SubjUID: "jqytw12v8jjeu3e6",
|
|
|
|
SubjName: "William Henry Gates III",
|
|
|
|
SubjAlias: "Windows Guru",
|
|
|
|
SubjFavorite: true,
|
2021-09-03 16:14:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m := NewPerson(subj)
|
|
|
|
|
2021-09-17 14:26:12 +02:00
|
|
|
assert.Equal(t, "jqytw12v8jjeu3e6", m.SubjUID)
|
|
|
|
assert.Equal(t, "William Henry Gates III", m.SubjName)
|
|
|
|
assert.Equal(t, "Windows Guru", m.SubjAlias)
|
|
|
|
assert.Equal(t, true, m.SubjFavorite)
|
2021-09-03 16:14:09 +02:00
|
|
|
|
|
|
|
if j, err := m.MarshalJSON(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
|
|
|
s := string(j)
|
|
|
|
|
|
|
|
expected := "{\"UID\":\"jqytw12v8jjeu3e6\",\"Name\":\"William Henry Gates III\"," +
|
|
|
|
"\"Keywords\":[\"william\",\"henry\",\"gates\",\"iii\",\"windows\",\"guru\"]," +
|
2021-09-17 18:51:24 +02:00
|
|
|
"\"Favorite\":true}"
|
2021-09-03 16:14:09 +02:00
|
|
|
|
|
|
|
assert.Equal(t, expected, s)
|
|
|
|
t.Logf("person json: %s", s)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|