All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
152 lines
3.6 KiB
Go
152 lines
3.6 KiB
Go
package store_test
|
|
|
|
import (
|
|
"gitea.deepak.science/deepak/gogmagog/models"
|
|
"gitea.deepak.science/deepak/gogmagog/store"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestInMemoryActionMethods(t *testing.T) {
|
|
assert := assert.New(t)
|
|
str, _ := store.GetInMemoryStore()
|
|
|
|
sampleplanid := 8
|
|
userID := 10
|
|
|
|
act := &models.Action{}
|
|
a2 := &models.Action{PlanID: sampleplanid}
|
|
|
|
id, _ := str.InsertAction(act, userID)
|
|
assert.EqualValues(1, id)
|
|
|
|
receivedAction, err := str.SelectActionByID(id, userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(act, receivedAction)
|
|
_, err = str.SelectActionByID(id, userID+1)
|
|
assert.NotNil(err)
|
|
|
|
allactions, err := str.SelectActions(userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(1, len(allactions))
|
|
|
|
str.InsertAction(a2, userID)
|
|
allactions, err = str.SelectActions(userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(2, len(allactions))
|
|
|
|
planactions, err := str.SelectActionsByPlanID(&models.Plan{PlanID: int64(sampleplanid)}, userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(1, len(planactions))
|
|
assert.Equal(a2, planactions[0])
|
|
|
|
_, err = str.SelectActionByID(151, userID)
|
|
assert.NotNil(err)
|
|
|
|
sampleDescription := "snth"
|
|
replacementAction := &models.Action{ActionID: 1, ActionDescription: sampleDescription}
|
|
err = str.UpdateAction(replacementAction, userID)
|
|
assert.Nil(err)
|
|
assert.Equal(sampleDescription, act.ActionDescription)
|
|
|
|
replacementAction = &models.Action{ActionID: 1235122, ActionDescription: sampleDescription}
|
|
err = str.UpdateAction(replacementAction, userID)
|
|
assert.NotNil(err)
|
|
|
|
}
|
|
|
|
func TestInMemoryPlanMethods(t *testing.T) {
|
|
assert := assert.New(t)
|
|
str, _ := store.GetInMemoryStore()
|
|
userID := 1
|
|
p := &models.Plan{}
|
|
plans, err := str.SelectPlans(userID)
|
|
|
|
assert.Nil(err)
|
|
assert.EqualValues(0, len(plans))
|
|
|
|
id, err := str.InsertPlan(p, userID)
|
|
plans, err = str.SelectPlans(userID)
|
|
|
|
assert.Nil(err)
|
|
assert.EqualValues(1, len(plans))
|
|
|
|
retrievedPlan, err := str.SelectPlanByID(id, userID)
|
|
assert.Nil(err)
|
|
assert.Equal(retrievedPlan, p)
|
|
|
|
_, err = str.SelectPlanByID(135135, userID)
|
|
assert.NotNil(err)
|
|
|
|
sampleDescription := "snth"
|
|
replacePlan := &models.Plan{PlanID: 1, PlanDescription: sampleDescription}
|
|
err = str.UpdatePlan(replacePlan, userID)
|
|
assert.Nil(err)
|
|
assert.Equal(sampleDescription, p.PlanDescription)
|
|
|
|
replacePlan = &models.Plan{PlanID: 1235122, PlanDescription: sampleDescription}
|
|
err = str.UpdatePlan(replacePlan, userID)
|
|
assert.NotNil(err)
|
|
}
|
|
|
|
func TestLive(t *testing.T) {
|
|
assert := assert.New(t)
|
|
str, _ := store.GetInMemoryStore()
|
|
|
|
err := str.ConnectionLive()
|
|
assert.Nil(err)
|
|
}
|
|
|
|
func TestInMemoryUserMethods(t *testing.T) {
|
|
assert := assert.New(t)
|
|
str, _ := store.GetInMemoryStore()
|
|
|
|
uname := "hiimauser"
|
|
|
|
u := &models.User{Username: uname}
|
|
|
|
id, err := str.InsertUser(u)
|
|
assert.Nil(err)
|
|
|
|
retrievedUser, err := str.SelectUserByUsername(uname)
|
|
assert.Nil(err)
|
|
assert.EqualValues(id, retrievedUser.UserID)
|
|
|
|
_, err = str.SelectUserByUsername("bad username")
|
|
assert.NotNil(err)
|
|
}
|
|
|
|
func TestInMemoryCurrentPlanMethods(t *testing.T) {
|
|
assert := assert.New(t)
|
|
str, _ := store.GetInMemoryStore()
|
|
|
|
userID := 10
|
|
|
|
cp1 := &models.CurrentPlan{PlanID: 1}
|
|
cp2 := &models.CurrentPlan{PlanID: 2}
|
|
|
|
err := str.UpdateCurrentPlan(cp1, userID)
|
|
assert.NotNil(err)
|
|
|
|
err = str.InsertCurrentPlan(cp1, userID)
|
|
assert.Nil(err)
|
|
|
|
receivedCp, err := str.SelectCurrentPlan(userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(1, receivedCp.PlanID)
|
|
|
|
_, err = str.SelectCurrentPlan(userID + 1)
|
|
assert.NotNil(err)
|
|
|
|
str.InsertCurrentPlan(cp2, userID)
|
|
assert.NotNil(err)
|
|
|
|
err = str.UpdateCurrentPlan(cp2, userID)
|
|
assert.Nil(err)
|
|
|
|
receivedCp, err = str.SelectCurrentPlan(userID)
|
|
assert.Nil(err)
|
|
assert.EqualValues(2, receivedCp.PlanID)
|
|
|
|
}
|