Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20250502-085309.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add a function on the Service object to get the system of that service
time: 2025-05-02T08:53:09.984285-05:00
21 changes: 21 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ func (service *Service) Hydrate(client *Client) error {
return nil
}

func (service *Service) GetSystem(client *Client, variables *PayloadVariables) (*System, error) {
var q struct {
Account struct {
Service struct {
System System `graphql:"system"`
} `graphql:"service(id: $service)"`
}
}
if service.Id == "" {
return nil, fmt.Errorf("unable to get system, invalid Service id: '%s'", service.Id)
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
(*variables)["service"] = service.Id
if err := client.Query(&q, *variables, WithName("ServiceSystemGet")); err != nil {
return nil, err
}
return &q.Account.Service.System, nil
}

func (service *Service) GetTags(client *Client, variables *PayloadVariables) (*TagConnection, error) {
var q struct {
Account struct {
Expand Down
20 changes: 20 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ func TestServiceTags(t *testing.T) {
autopilot.Equals(t, "true", result[1].Value)
}

func TestServiceSystem(t *testing.T) {
// Arrange
request := autopilot.NewTestRequest(
`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}}}}}}}`,
`{ {{ template "first_page_variables" }}, "service": "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS85NjQ4" }`,
`{ "data": { "account": { "service": { "system": {{ template "system1_response" }} } } } }`,
)
client := BestTestClient(t, "service/system", request)
// Act
service := ol.Service{
ServiceId: ol.ServiceId{
Id: "Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS85NjQ4",
},
}
resp, err := service.GetSystem(client, nil)
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "Z2lkOi8vMTIzNDU2Nzg5OTg3NjU0MzIx", string(resp.Id))
}

func TestServiceTools(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
Expand Down