[TASK] add review model
This commit is contained in:
parent
969bd7f618
commit
4e966a59df
|
@ -0,0 +1,28 @@
|
|||
package models
|
||||
|
||||
import "github.com/genofire/hs_master-kss-monolith/lib/database"
|
||||
|
||||
type Review struct {
|
||||
ID int64
|
||||
ProductID int64
|
||||
LocaleLanguage string
|
||||
FirstName string
|
||||
LastName string
|
||||
RatingStars int64
|
||||
Text string
|
||||
}
|
||||
|
||||
func (r *Review) DisplayName() string {
|
||||
if len(r.FirstName) > 0 {
|
||||
if len(r.LastName) > 0 {
|
||||
last := []byte(r.LastName)
|
||||
return r.FirstName + " " + string(last[0]) + "."
|
||||
}
|
||||
return r.FirstName
|
||||
}
|
||||
return "Anonymous"
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AddModel(&Review{})
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDisplayName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
r := Review{}
|
||||
assert.Equal("", r.FirstName, "wrong firstname")
|
||||
assert.Equal("", r.LastName, "wrong lastname")
|
||||
assert.Equal("Anonymous", r.DisplayName(), "No name")
|
||||
|
||||
r.FirstName = "Max"
|
||||
assert.Equal("Max", r.FirstName, "wrong firstname")
|
||||
assert.Equal("", r.LastName, "wrong lastname")
|
||||
assert.Equal("Max", r.DisplayName(), "Only Firstname")
|
||||
|
||||
r.LastName = "Mustermann"
|
||||
assert.Equal("Max", r.FirstName, "wrong firstname")
|
||||
assert.Equal("Mustermann", r.LastName, "wrong lastname")
|
||||
assert.Equal("Max M.", r.DisplayName(), "Shorted Name")
|
||||
|
||||
r.FirstName = ""
|
||||
assert.Equal("", r.FirstName, "wrong firstname")
|
||||
assert.Equal("Mustermann", r.LastName, "wrong lastname")
|
||||
assert.Equal("Anonymous", r.DisplayName(), "displayname: no firstname")
|
||||
}
|
Reference in New Issue