Skip to content

Commit

Permalink
Show correct stream ID in UI (#15703)
Browse files Browse the repository at this point in the history
- It was previously showing the literal pointer value
  • Loading branch information
samsondav authored Dec 16, 2024
1 parent ed6f486 commit 68b0d6b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
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
}

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
}

0 comments on commit 68b0d6b

Please sign in to comment.