From 50615998ddc75b7bf535542c7d9b2da2386dcd9a Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Mon, 16 Dec 2024 09:37:15 -0500 Subject: [PATCH] Show correct stream ID in UI - It was previously showing the literal pointer value --- core/web/resolver/spec.go | 13 +++-- core/web/resolver/spec_test.go | 85 +++++++++++++++++++++++++++++++ core/web/schema/type/spec.graphql | 2 +- 3 files changed, 95 insertions(+), 5 deletions(-) diff --git a/core/web/resolver/spec.go b/core/web/resolver/spec.go index ce23df49264..ca88f75a519 100644 --- a/core/web/resolver/spec.go +++ b/core/web/resolver/spec.go @@ -1,7 +1,7 @@ package resolver import ( - "fmt" + "strconv" "github.com/graph-gophers/graphql-go" @@ -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 { @@ -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 } diff --git a/core/web/resolver/spec_test.go b/core/web/resolver/spec_test.go index 69d6a56509c..27eafbb844d 100644 --- a/core/web/resolver/spec_test.go +++ b/core/web/resolver/spec_test.go @@ -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) +} diff --git a/core/web/schema/type/spec.graphql b/core/web/schema/type/spec.graphql index db81001543c..1efeb2c77ba 100644 --- a/core/web/schema/type/spec.graphql +++ b/core/web/schema/type/spec.graphql @@ -182,5 +182,5 @@ type StandardCapabilitiesSpec { } type StreamSpec { - streamID: String! + streamID: String }