Save method
This commit is contained in:
@ -33,9 +33,9 @@ func NewMockDB() (*sql.DB, *gorm.DB, sqlmock.Sqlmock) {
|
||||
}
|
||||
|
||||
type MyModel struct {
|
||||
Id uuid.UUID
|
||||
Id *uuid.UUID `gorm:"type(uuid);unique"`
|
||||
Value string
|
||||
Count int
|
||||
Cnt int
|
||||
}
|
||||
|
||||
func (m MyModel) TableName() string {
|
||||
@ -46,7 +46,7 @@ type MyModelFilter struct {
|
||||
Id *uuid.UUID `filterfield:"field=id,operator=EQ"`
|
||||
Ids *[]uuid.UUID `filterfield:"field=id,operator=IN"`
|
||||
Value *string `filterfield:"field=value,operator=EQ"`
|
||||
Count *int `filterfield:"field=count,operator=GT"`
|
||||
Cnt *int `filterfield:"field=cnt,operator=GT"`
|
||||
}
|
||||
|
||||
func TestListMethod(t *testing.T) {
|
||||
@ -65,13 +65,13 @@ func TestListMethod(t *testing.T) {
|
||||
Direction: OrderASC,
|
||||
},
|
||||
{
|
||||
Field: "count",
|
||||
Field: "cnt",
|
||||
Direction: OrderDESC,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sql := "SELECT * FROM my_models ORDER BY id,count DESC"
|
||||
sql := "SELECT * FROM my_models ORDER BY id,cnt DESC"
|
||||
mock.ExpectQuery(fmt.Sprintf("^%s$", regexp.QuoteMeta(sql)))
|
||||
|
||||
_, err := repo.List(filter, &options)
|
||||
@ -198,10 +198,10 @@ func TestListMethod(t *testing.T) {
|
||||
filter := MyModelFilter{
|
||||
Id: &id,
|
||||
Value: &value,
|
||||
Count: &count,
|
||||
Cnt: &count,
|
||||
}
|
||||
|
||||
sql := "SELECT * FROM my_models WHERE my_models.id = $1 AND my_models.value = $2 AND my_models.count > $3"
|
||||
sql := "SELECT * FROM my_models WHERE my_models.id = $1 AND my_models.value = $2 AND my_models.cnt > $3"
|
||||
mock.ExpectQuery(fmt.Sprintf("^%s$", regexp.QuoteMeta(sql))).
|
||||
WithArgs(id, value, count)
|
||||
|
||||
@ -226,7 +226,7 @@ func TestListMethod(t *testing.T) {
|
||||
filter := MyModelFilter{
|
||||
Id: &id,
|
||||
Value: &value,
|
||||
Count: &count,
|
||||
Cnt: &count,
|
||||
}
|
||||
options := ListOptions{
|
||||
Pagination: &Pagination{
|
||||
@ -235,7 +235,7 @@ func TestListMethod(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
sql := "SELECT * FROM my_models WHERE my_models.id = $1 AND my_models.value = $2 AND my_models.count > $3 LIMIT $4 OFFSET $5"
|
||||
sql := "SELECT * FROM my_models WHERE my_models.id = $1 AND my_models.value = $2 AND my_models.cnt > $3 LIMIT $4 OFFSET $5"
|
||||
mock.ExpectQuery(fmt.Sprintf("^%s$", regexp.QuoteMeta(sql))).
|
||||
WithArgs(id, value, count, options.Pagination.Limit, options.Pagination.Offset)
|
||||
|
||||
@ -258,11 +258,11 @@ func TestListMethod(t *testing.T) {
|
||||
options := ListOptions{
|
||||
Only: &[]string{
|
||||
"id",
|
||||
"count",
|
||||
"cnt",
|
||||
},
|
||||
}
|
||||
|
||||
sql := "SELECT id,count FROM my_models"
|
||||
sql := "SELECT id,cnt FROM my_models"
|
||||
mock.ExpectQuery(fmt.Sprintf("^%s$", regexp.QuoteMeta(sql)))
|
||||
|
||||
_, err := repo.List(filter, &options)
|
||||
|
||||
Reference in New Issue
Block a user