2023-01-10 20:23:47 -07:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSortResourceListByTitle(t *testing.T) {
|
|
|
|
//setup
|
|
|
|
a := "a"
|
|
|
|
g := "g"
|
|
|
|
p := "p"
|
|
|
|
z := "z"
|
2023-07-08 08:43:30 -06:00
|
|
|
resources := []*models.ResourceBase{
|
2023-01-10 20:23:47 -07:00
|
|
|
{
|
|
|
|
SortTitle: &a,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortTitle: &g,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortTitle: &z,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortTitle: &p,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//test
|
|
|
|
resources = SortResourcePtrListByTitle(resources)
|
|
|
|
|
|
|
|
//assert
|
|
|
|
require.Equal(t, "a", *resources[0].SortTitle)
|
|
|
|
require.Equal(t, "g", *resources[1].SortTitle)
|
|
|
|
require.Equal(t, "p", *resources[2].SortTitle)
|
|
|
|
require.Equal(t, "z", *resources[3].SortTitle)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSortResourceListByDate(t *testing.T) {
|
|
|
|
//setup
|
|
|
|
a := time.Now().Add(time.Hour * -24)
|
|
|
|
g := time.Now().Add(time.Hour * -48)
|
|
|
|
p := time.Now().Add(time.Hour * -72)
|
|
|
|
z := time.Now().Add(time.Hour * -100)
|
2023-07-08 08:43:30 -06:00
|
|
|
resources := []*models.ResourceBase{
|
2023-01-10 20:23:47 -07:00
|
|
|
{
|
|
|
|
SortDate: &a,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortDate: &g,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortDate: &z,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SortDate: &p,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//test
|
|
|
|
resources = SortResourcePtrListByDate(resources)
|
|
|
|
|
|
|
|
//assert
|
|
|
|
require.Equal(t, a, *resources[0].SortDate)
|
|
|
|
require.Equal(t, g, *resources[1].SortDate)
|
|
|
|
require.Equal(t, p, *resources[2].SortDate)
|
|
|
|
require.Equal(t, z, *resources[3].SortDate)
|
|
|
|
}
|