"add search test"

This commit is contained in:
0xmuralik 2022-11-04 16:42:27 +05:30
parent 647669cf17
commit c0143e65cd

View File

@ -34,12 +34,16 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
grpcClient, ctx := suite.queryClient, suite.ctx grpcClient, ctx := suite.queryClient, suite.ctx
sr := suite.Require() sr := suite.Require()
var recordId string var recordId string
examples := []string{
"/../helpers/examples/service_provider_example.yml",
"/../helpers/examples/website_registration_example.yml",
}
testCases := []struct { testCases := []struct {
msg string msg string
req *nameservicetypes.QueryListRecordsRequest req *nameservicetypes.QueryListRecordsRequest
createRecord bool createRecords bool
expErr bool expErr bool
noOfRecords int noOfRecords int
}{ }{
{ {
"Empty Records", "Empty Records",
@ -53,25 +57,43 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
&nameservicetypes.QueryListRecordsRequest{}, &nameservicetypes.QueryListRecordsRequest{},
true, true,
false, false,
2,
},
{
"Filter with type",
&nameservicetypes.QueryListRecordsRequest{
Attributes: []*nameservicetypes.QueryListRecordsRequest_KeyValueInput{
{
Key: "type",
Value: &nameservicetypes.QueryListRecordsRequest_ValueInput{
String_: "WebsiteRegistrationRecord",
},
},
},
},
true,
false,
1, 1,
}, },
} }
for _, test := range testCases { for _, test := range testCases {
suite.Run(fmt.Sprintf("Case %s ", test.msg), func() { suite.Run(fmt.Sprintf("Case %s ", test.msg), func() {
if test.createRecord { if test.createRecords {
dir, err := os.Getwd() for _, example := range examples {
sr.NoError(err) dir, err := os.Getwd()
payloadType, err := cli.GetPayloadFromFile(dir + "/../helpers/examples/service_provider_example.yml") sr.NoError(err)
sr.NoError(err) payloadType, err := cli.GetPayloadFromFile(fmt.Sprint(dir, example))
payload, err := payloadType.ToPayload() sr.NoError(err)
sr.NoError(err) payload, err := payloadType.ToPayload()
record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{ sr.NoError(err)
BondId: suite.bond.GetId(), record, err := suite.app.NameServiceKeeper.ProcessSetRecord(ctx, nameservicetypes.MsgSetRecord{
Signer: suite.accounts[0].String(), BondId: suite.bond.GetId(),
Payload: payload, Signer: suite.accounts[0].String(),
}) Payload: payload,
sr.NoError(err) })
sr.NotNil(record.ID) sr.NoError(err)
sr.NotNil(record.ID)
}
} }
resp, err := grpcClient.ListRecords(context.Background(), test.req) resp, err := grpcClient.ListRecords(context.Background(), test.req)
if test.expErr { if test.expErr {
@ -79,7 +101,7 @@ func (suite *KeeperTestSuite) TestGrpcGetRecordLists() {
} else { } else {
sr.NoError(err) sr.NoError(err)
sr.Equal(test.noOfRecords, len(resp.GetRecords())) sr.Equal(test.noOfRecords, len(resp.GetRecords()))
if test.createRecord { if test.createRecords {
recordId = resp.GetRecords()[0].GetId() recordId = resp.GetRecords()[0].GetId()
sr.NotZero(resp.GetRecords()) sr.NotZero(resp.GetRecords())
sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId()) sr.Equal(resp.GetRecords()[0].GetBondId(), suite.bond.GetId())