Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of incorrect Stream ID in job definition UI #15703

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/web/resolver/spec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package resolver

import (
"fmt"
"strconv"

"github.com/graph-gophers/graphql-go"

Expand Down Expand Up @@ -139,8 +139,13 @@ func (r *SpecResolver) ToStreamSpec() (*StreamSpecResolver, bool) {
if r.j.Type != job.Stream {
return nil, false
}
res := &StreamSpecResolver{}
if r.j.StreamID != nil {
sid := strconv.FormatUint(uint64(*r.j.StreamID), 10)
res.streamID = &sid
}
ro-tex marked this conversation as resolved.
Show resolved Hide resolved

return &StreamSpecResolver{streamID: fmt.Sprintf("%d", r.j.StreamID)}, true
return res, true
}

type CronSpecResolver struct {
Expand Down Expand Up @@ -1057,9 +1062,9 @@ func (r *StandardCapabilitiesSpecResolver) Config() *string {
}

type StreamSpecResolver struct {
streamID string
streamID *string
}

func (r *StreamSpecResolver) StreamID() string {
func (r *StreamSpecResolver) StreamID() *string {
return r.streamID
}
83 changes: 83 additions & 0 deletions core/web/resolver/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolver

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -1166,3 +1167,85 @@ func TestResolver_StandardCapabilitiesSpec(t *testing.T) {

RunGQLTests(t, testCases)
}

func TestResolver_StreamSpec(t *testing.T) {
var (
id1 = int32(1)
id2 = int32(2)
streamID = uint32(3)
)

testCases := []GQLTestCase{
{
name: "stream spec with stream ID",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("JobORM").Return(f.Mocks.jobORM)
f.Mocks.jobORM.On("FindJobWithoutSpecErrors", mock.Anything, id1).Return(job.Job{
Type: job.Stream,
StreamID: &streamID,
}, nil)
},
query: fmt.Sprintf(`
query GetJob {
job(id: "%d") {
... on Job {
spec {
__typename
... on StreamSpec {
streamID
}
}
}
}
}
`, id1),
result: fmt.Sprintf(`
{
"job": {
"spec": {
"__typename": "StreamSpec",
"streamID": "%d"
}
}
}
`, streamID),
},
{
name: "stream spec without stream ID",
authenticated: true,
before: func(ctx context.Context, f *gqlTestFramework) {
f.App.On("JobORM").Return(f.Mocks.jobORM)
f.Mocks.jobORM.On("FindJobWithoutSpecErrors", mock.Anything, id2).Return(job.Job{
Type: job.Stream,
}, nil)
},
query: fmt.Sprintf(`
query GetJob {
job(id: "%d") {
... on Job {
spec {
__typename
... on StreamSpec {
streamID
}
}
}
}
}
`, id2),
result: `
{
"job": {
"spec": {
"__typename": "StreamSpec",
"streamID": null
}
}
}
`,
},
}

RunGQLTests(t, testCases)
}
2 changes: 1 addition & 1 deletion core/web/schema/type/spec.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,5 @@ type StandardCapabilitiesSpec {
}

type StreamSpec {
streamID: String!
streamID: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Loading