Skip to content

Commit

Permalink
Allow query on validation report id
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Feb 5, 2024
1 parent 7049433 commit a792863
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions finders/dbfinder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ func (f *Finder) ValidationReportsByFeedVersionID(ctx context.Context, params []
Limit(checkLimit(limit)).
OrderBy("tl_validation_reports.created_at desc, tl_validation_reports.id desc")
if where != nil {
if len(where.ReportIds) > 0 {
q = q.Where(sq.Eq{"tl_validation_reports.id": where.ReportIds})
}
if where.Success != nil {
q = q.Where(sq.Eq{"success": where.Success})
}
Expand Down
10 changes: 9 additions & 1 deletion internal/generated/gqlout/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schema/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ input OperatorFilter {
}

input ValidationReportFilter {
report_ids: [Int!]
success: Boolean
validator: String
validator_version: String
Expand Down
23 changes: 21 additions & 2 deletions server/gql/validation_report_resolver_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package gql

import (
"strconv"
"testing"

"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
)

func TestValidationReportResolver(t *testing.T) {
c, cfg := newTestClient(t)
fvsha1 := "96b67c0934b689d9085c52967365d8c233ea321d"
q := `query($feed_version_sha1: String!, $where: ValidationReportFilter) { feed_versions(where:{sha1:$feed_version_sha1}) {validation_reports(where:$where) {success failure_reason includes_static includes_rt validator validator_version errors { filename error_type error_code field count errors { filename error_type error_code entity_id field line value message geometry }} }} }`
q := `query($feed_version_sha1: String!, $where: ValidationReportFilter) { feed_versions(where:{sha1:$feed_version_sha1}) {validation_reports(where:$where) {id success failure_reason includes_static includes_rt validator validator_version errors { filename error_type error_code field count errors { filename error_type error_code entity_id field line value message geometry }} }} }`
var reportId int
if err := cfg.Finder.DBX().QueryRowx("select rp.id from tl_validation_reports rp join feed_versions fv on fv.id = rp.feed_version_id where fv.sha1 = $1 limit 1", fvsha1).Scan(&reportId); err != nil {
panic(err)
}
testcases := []testcase{
// Saved validation reports
{
Expand Down Expand Up @@ -77,8 +83,21 @@ func TestValidationReportResolver(t *testing.T) {
selector: "feed_versions.0.validation_reports.#.includes_rt",
selectExpect: []string{"false"},
},
{
name: "report_ids",
query: q,
vars: hw{"feed_version_sha1": fvsha1, "where": hw{"report_ids": []int{reportId}}},
selector: "feed_versions.0.validation_reports.#.id",
selectExpect: []string{strconv.Itoa(reportId)},
},
{
name: "report_ids",
query: q,
vars: hw{"feed_version_sha1": fvsha1, "where": hw{"report_ids": []int{100000}}},
selector: "feed_versions.0.validation_reports.#.id",
selectExpect: []string{},
},
}
c, _ := newTestClient(t)
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
queryTestcase(t, c, tc)
Expand Down

0 comments on commit a792863

Please sign in to comment.