Skip to content

Commit

Permalink
Show correct stream ID in UI
Browse files Browse the repository at this point in the history
- It was previously showing the literal pointer value
  • Loading branch information
samsondav committed Dec 16, 2024
1 parent 329e8f0 commit 5061599
Show file tree
Hide file tree
Showing 3 changed files with 95 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
}
85 changes: 85 additions & 0 deletions core/web/resolver/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,3 +1166,88 @@ func TestResolver_StandardCapabilitiesSpec(t *testing.T) {

RunGQLTests(t, testCases)
}

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

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, id).Return(job.Job{
Type: job.Stream,
StreamID: &streamID,
}, nil)
},
query: `
query GetJob {
job(id: "1") {
... on Job {
spec {
__typename
... on StreamSpec {
streamID
createdAt
}
}
}
}
}
`,
result: `
{
"job": {
"spec": {
"__typename": "CronSpec",
"streamID": "2",
"createdAt": "2021-01-01T00:00:00Z"
}
}
}
`,
},
{
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, id).Return(job.Job{
Type: job.Stream,
}, nil)
},
query: `
query GetJob {
job(id: "1") {
... on Job {
spec {
__typename
... on StreamSpec {
streamID
createdAt
}
}
}
}
}
`,
result: `
{
"job": {
"spec": {
"__typename": "CronSpec",
"streamID": null,
"createdAt": "2021-01-01T00:00:00Z"
}
}
}
`,
},
}

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 5061599

Please sign in to comment.