package models_test import ( "gitea.deepak.science/deepak/gogmagog/models" "gitea.deepak.science/deepak/gogmagog/store" "github.com/stretchr/testify/assert" "testing" ) func TestModelActions(t *testing.T) { assert := assert.New(t) a1 := &models.Action{ActionID: 3} a2 := &models.Action{ActionID: 4} userID := 3 p := &models.Plan{PlanID: 6} str, _ := store.GetInMemoryStore() str.InsertAction(a1) str.InsertPlan(p, userID) m := models.New(str) actions, err := m.Actions() assert.Nil(err) assert.Equal(1, len(actions)) firstAction, err := m.Action(1) assert.Nil(err) assert.EqualValues(1, firstAction.ActionID) actionID, err := m.AddAction(a2) assert.Nil(err) assert.EqualValues(2, actionID) err = m.SaveAction(a1) assert.Nil(err) } func TestModelPlanMethods(t *testing.T) { assert := assert.New(t) userID := 3 a1 := &models.Action{ActionID: 3, PlanID: 1} a2 := &models.Action{ActionID: 4} p := &models.Plan{} str, _ := store.GetInMemoryStore() str.InsertPlan(p, userID) str.InsertAction(a1) str.InsertAction(a2) m := models.New(str) plans, err := m.Plans(userID) assert.Nil(err) assert.Equal(1, len(plans)) firstPlan, err := m.Plan(1, userID) assert.Nil(err) assert.EqualValues(1, firstPlan.PlanID) actions, err := m.GetActions(firstPlan) assert.Nil(err) assert.Equal(1, len(actions)) planId, err := m.AddPlan(&models.Plan{}, userID) assert.Nil(err) assert.EqualValues(2, planId) } func TestModelHealthy(t *testing.T) { assert := assert.New(t) str, _ := store.GetInMemoryStore() m := models.New(str) err := m.Healthy() assert.Nil(err) } func TestNilModelUnhealthy(t *testing.T) { assert := assert.New(t) m := models.New(nil) err := m.Healthy() assert.NotNil(err) }