Skip to content

Commit fdcb5f5

Browse files
authored
Add function to get the system of the service (#540)
1 parent 11feb5f commit fdcb5f5

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Feature
2+
body: Add a function on the Service object to get the system of that service
3+
time: 2025-05-02T08:53:09.984285-05:00

service.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ func (service *Service) Hydrate(client *Client) error {
167167
return nil
168168
}
169169

170+
func (service *Service) GetSystem(client *Client, variables *PayloadVariables) (*System, error) {
171+
var q struct {
172+
Account struct {
173+
Service struct {
174+
System System `graphql:"system"`
175+
} `graphql:"service(id: $service)"`
176+
}
177+
}
178+
if service.Id == "" {
179+
return nil, fmt.Errorf("unable to get system, invalid Service id: '%s'", service.Id)
180+
}
181+
if variables == nil {
182+
variables = client.InitialPageVariablesPointer()
183+
}
184+
(*variables)["service"] = service.Id
185+
if err := client.Query(&q, *variables, WithName("ServiceSystemGet")); err != nil {
186+
return nil, err
187+
}
188+
return &q.Account.Service.System, nil
189+
}
190+
170191
func (service *Service) GetTags(client *Client, variables *PayloadVariables) (*TagConnection, error) {
171192
var q struct {
172193
Account struct {

service_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ func TestServiceTags(t *testing.T) {
4040
autopilot.Equals(t, "true", result[1].Value)
4141
}
4242

43+
func TestServiceSystem(t *testing.T) {
44+
// Arrange
45+
request := autopilot.NewTestRequest(
46+
`query ServiceSystemGet($after:String!$first:Int!$service:ID!){account{service(id: $service){system{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}},parent{id,aliases,description,htmlUrl,managedAliases,name,note,owner{... on Team{teamAlias:alias,id}}}}}}}`,
47+
`{ {{ template "first_page_variables" }}, "service": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS85NjQ4" }`,
48+
`{ "data": { "account": { "service": { "system": {{ template "system1_response" }} } } } }`,
49+
)
50+
client := BestTestClient(t, "service/system", request)
51+
// Act
52+
service := ol.Service{
53+
ServiceId: ol.ServiceId{
54+
Id: "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS85NjQ4",
55+
},
56+
}
57+
resp, err := service.GetSystem(client, nil)
58+
// Assert
59+
autopilot.Ok(t, err)
60+
autopilot.Equals(t, "Z2lkOi8vMTIzNDU2Nzg5OTg3NjU0MzIx", string(resp.Id))
61+
}
62+
4363
func TestServiceTools(t *testing.T) {
4464
// Arrange
4565
testRequestOne := autopilot.NewTestRequest(

0 commit comments

Comments
 (0)