Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav committed Dec 16, 2024
1 parent 329e8f0 commit e3c0f8b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
13 changes: 8 additions & 5 deletions core/web/resolver/spec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package resolver

import (
"fmt"

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

"github.com/smartcontractkit/chainlink/v2/core/services/job"
Expand Down Expand Up @@ -139,8 +137,13 @@ func (r *SpecResolver) ToStreamSpec() (*StreamSpecResolver, bool) {
if r.j.Type != job.Stream {
return nil, false
}
res := &StreamSpecResolver{}
if r.j.StreamID != nil {
sid := int64(*r.j.StreamID)
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 +1060,9 @@ func (r *StandardCapabilitiesSpecResolver) Config() *string {
}

type StreamSpecResolver struct {
streamID string
streamID *int64
}

func (r *StreamSpecResolver) StreamID() string {
func (r *StreamSpecResolver) StreamID() *int64 {
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) {
const (
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,

Check failure on line 1184 in core/web/resolver/spec_test.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_tests)

invalid operation: cannot take address of streamID (constant 2 of type uint32)

Check failure on line 1184 in core/web/resolver/spec_test.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: cannot take address of streamID (constant 2 of type uint32) (typecheck)

Check failure on line 1184 in core/web/resolver/spec_test.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_race_tests)

invalid operation: cannot take address of streamID (constant 2 of type uint32)
}, 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: Int
}

0 comments on commit e3c0f8b

Please sign in to comment.