Skip to content

Commit

Permalink
QueryProjectEnrollments test
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Mar 31, 2024
1 parent d047dd7 commit cc428ad
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion x/ecocredit/base/keeper/query_project_enrollments_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
package keeper

// TODO
import (
"testing"

"github.com/stretchr/testify/require"

api "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1"
types "github.com/regen-network/regen-ledger/x/ecocredit/v3/base/types/v1"
)

func TestQuery_ProjectEnrollments(t *testing.T) {
t.Parallel()
s := setupBase(t)

// insert projects
projId1 := "P001"

Check warning on line 17 in x/ecocredit/base/keeper/query_project_enrollments_test.go

View workflow job for this annotation

GitHub Actions / golangci (x/ecocredit)

var-naming: var projId1 should be projID1 (revive)
projKey1, err := s.stateStore.ProjectTable().InsertReturningID(s.ctx, &api.Project{
Id: projId1,
})
require.NoError(t, err)

projId2 := "P002"

Check warning on line 23 in x/ecocredit/base/keeper/query_project_enrollments_test.go

View workflow job for this annotation

GitHub Actions / golangci (x/ecocredit)

var-naming: var projId2 should be projID2 (revive)
projKey2, err := s.stateStore.ProjectTable().InsertReturningID(s.ctx, &api.Project{
Id: projId2,
})
require.NoError(t, err)

// insert classes
clsId1 := "C01"
clsKey1, err := s.stateStore.ClassTable().InsertReturningID(s.ctx, &api.Class{
Id: clsId1,
})

clsId2 := "BIO01"
clsKey2, err := s.stateStore.ClassTable().InsertReturningID(s.ctx, &api.Class{
Id: clsId2,
})

// insert enrollments
enrollment1 := &api.ProjectEnrollment{
ProjectKey: projKey1,
ClassKey: clsKey1,
}

enrollment2 := &api.ProjectEnrollment{
ProjectKey: projKey1,
ClassKey: clsKey2,
}

enrollment3 := &api.ProjectEnrollment{
ProjectKey: projKey2,
ClassKey: clsKey2,
}

for _, enrollment := range []*api.ProjectEnrollment{enrollment1, enrollment2, enrollment3} {
require.NoError(t, s.stateStore.ProjectEnrollmentTable().Insert(s.ctx, enrollment))
}

// query project enrollments by project id
res, err := s.k.ProjectEnrollments(s.ctx, &types.QueryProjectEnrollmentsRequest{
ProjectId: projId1,
})
require.NoError(t, err)
require.Len(t, res.Enrollments, 2)
require.Equal(t, projId1, res.Enrollments[0].ProjectId)
require.Equal(t, clsId1, res.Enrollments[0].ClassId)
require.Equal(t, projId1, res.Enrollments[1].ProjectId)
require.Equal(t, clsId2, res.Enrollments[1].ClassId)

// query project enrollments by class id
res, err = s.k.ProjectEnrollments(s.ctx, &types.QueryProjectEnrollmentsRequest{
ClassId: clsId2,
})
require.NoError(t, err)
require.Len(t, res.Enrollments, 2)
require.Equal(t, projId1, res.Enrollments[0].ProjectId)
require.Equal(t, clsId2, res.Enrollments[0].ClassId)
require.Equal(t, projId2, res.Enrollments[1].ProjectId)
require.Equal(t, clsId2, res.Enrollments[1].ClassId)
}

0 comments on commit cc428ad

Please sign in to comment.