Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamess-Lucass committed Apr 2, 2024
1 parent d06930b commit 70d8e58
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand All @@ -15,7 +16,8 @@ import (
var DB *gorm.DB

type Base struct {
Id uuid.UUID `json:"id"`
Id uuid.UUID `json:"id"`
CreatedAt time.Time `json:"createdAt"`
}

type User struct {
Expand Down Expand Up @@ -474,3 +476,19 @@ func Test_QueryWithFilterAndOrInColumnName(t *testing.T) {

assert.Equal(t, expectedSql, sql)
}

func Test_QueryWithFilterCompositeStructProperty(t *testing.T) {
now := time.Now().UTC().String()
query := Query{Filter: fmt.Sprintf("createdAt eq '%s'", now)}

sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
res, _, _ := Apply(tx.Model(&User{}), query, nil, nil, &[]User{})
return res.Find(&[]User{})
})

expectedSql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
return tx.Model(&User{}).Where(fmt.Sprintf("LOWER(created_at) = LOWER('%s')", now)).Find(&[]User{})
})

assert.Equal(t, expectedSql, sql)
}

0 comments on commit 70d8e58

Please sign in to comment.