Skip to content

Commit 025781d

Browse files
committed
separate getAppBySpace as a function, add mock to test
1 parent 84be86c commit 025781d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/core/src/awsService/sagemaker/sagemakerSpace.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,8 @@ export class SagemakerSpace {
117117
AppType: this.spaceApp?.SpaceSettingsSummary?.AppType,
118118
SpaceName: this.spaceApp.SpaceName,
119119
})
120-
} else {
121-
const appsList = await this.client
122-
.listApps({ DomainIdEquals: this.spaceApp.DomainId, SpaceNameEquals: this.spaceApp.SpaceName })
123-
.flatten()
124-
.promise()
125-
app = appsList[0]
120+
} else if (this.spaceApp.DomainId && this.spaceApp.SpaceName) {
121+
app = await this.client.getAppBySpace(this.spaceApp.DomainId, this.spaceApp.SpaceName)
126122
}
127123

128124
// AWS DescribeSpace API returns full details with property names like 'SpaceSettings'

packages/core/src/shared/clients/sagemaker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
126126
return this.makeRequest(DeleteAppCommand, request)
127127
}
128128

129+
public async getAppBySpace(domainId: string, spaceName: string): Promise<AppDetails | undefined> {
130+
const appsList = await this.listApps({ DomainIdEquals: domainId, SpaceNameEquals: spaceName })
131+
.flatten()
132+
.promise()
133+
return appsList[0]
134+
}
135+
129136
public async startSpace(spaceName: string, domainId: string) {
130137
let spaceDetails: DescribeSpaceCommandOutput
131138

packages/core/src/test/awsService/sagemaker/sagemakerSpace.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('SagemakerSpace', function () {
6363

6464
mockClient.describeSpace.resolves(mockDescribeSpaceResponse)
6565
mockClient.describeApp.resolves(mockDescribeAppResponse)
66+
mockClient.getAppBySpace.resolves(mockDescribeAppResponse)
6667

6768
const space = new SagemakerSpace(mockClient as any, 'us-east-1', mockSpaceApp)
6869
const updateSpaceSpy = sinon.spy(space, 'updateSpace')

0 commit comments

Comments
 (0)