Skip to content

Commit 032a231

Browse files
committed
feat: query user for organization in schema:update and schema:create commands
1 parent 0f577bd commit 032a231

File tree

18 files changed

+262
-80
lines changed

18 files changed

+262
-80
lines changed

.changeset/wet-bottles-wink.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@smartthings/cli": minor
3+
"@smartthings/cli-lib": minor
4+
---
5+
6+
query user for organization in schema:update and schema:create commands

package-lock.json

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"@oclif/plugin-not-found": "^2.3.1",
7878
"@oclif/plugin-plugins": "^2.1.0",
7979
"@smartthings/cli-lib": "^2.2.5",
80-
"@smartthings/core-sdk": "^8.2.0",
80+
"@smartthings/core-sdk": "^8.3.0",
8181
"@smartthings/plugin-cli-edge": "^3.3.3",
8282
"inquirer": "^8.2.4",
8383
"js-yaml": "^4.1.0",

packages/cli/src/__tests__/commands/schema/create.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { inputAndOutputItem } from '@smartthings/cli-lib'
22
import SchemaAppCreateCommand from '../../../commands/schema/create'
33
import { addSchemaPermission } from '../../../lib/aws-utils'
44
import { SchemaAppRequest, SchemaCreateResponse, SchemaEndpoint } from '@smartthings/core-sdk'
5-
import { SCHEMA_AWS_PRINCIPAL } from '../../../lib/commands/schema-util'
5+
import { SCHEMA_AWS_PRINCIPAL, SchemaAppWithOrganization } from '../../../lib/commands/schema-util'
66

77

88
jest.mock('../../../lib/aws-utils')
@@ -38,11 +38,16 @@ describe('SchemaAppCreateCommand', () => {
3838
const schemaAppRequest = {
3939
appName: 'schemaApp',
4040
} as SchemaAppRequest
41+
const schemaAppRequestWithOrganization = {
42+
...schemaAppRequest,
43+
organizationId: 'organization-id',
44+
} as SchemaAppWithOrganization
4145

4246
const actionFunction = inputAndOutputItemMock.mock.calls[0][2]
4347

44-
await expect(actionFunction(undefined, schemaAppRequest)).resolves.toStrictEqual(schemaCreateResponse)
45-
expect(createSpy).toBeCalledWith(schemaAppRequest)
48+
await expect(actionFunction(undefined, schemaAppRequestWithOrganization))
49+
.resolves.toStrictEqual(schemaCreateResponse)
50+
expect(createSpy).toBeCalledWith(schemaAppRequest, 'organization-id')
4651
})
4752

4853
it('accepts authorize flag and adds permissions for each lambda app region', async () => {
@@ -72,7 +77,7 @@ describe('SchemaAppCreateCommand', () => {
7277
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnCN, SCHEMA_AWS_PRINCIPAL, undefined)
7378
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnEU, SCHEMA_AWS_PRINCIPAL, undefined)
7479
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnAP, SCHEMA_AWS_PRINCIPAL, undefined)
75-
expect(createSpy).toBeCalledWith(schemaAppRequest)
80+
expect(createSpy).toBeCalledWith(schemaAppRequest, undefined)
7681
})
7782

7883
it('throws error if authorize flag is used on non-lambda app', async () => {
@@ -101,7 +106,7 @@ describe('SchemaAppCreateCommand', () => {
101106
await expect(actionFunction(undefined, schemaAppRequest)).resolves.not.toThrow()
102107

103108
expect(addSchemaPermissionMock).toBeCalledTimes(0)
104-
expect(createSpy).toBeCalledWith(schemaAppRequest)
109+
expect(createSpy).toBeCalledWith(schemaAppRequest, undefined)
105110
})
106111

107112
it('passes principal flag to addSchemaPermission', async () => {

packages/cli/src/__tests__/commands/schema/update.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { inputItem, IOFormat, selectFromList } from '@smartthings/cli-lib'
21
import { SchemaApp, SchemaAppRequest, SchemaEndpoint } from '@smartthings/core-sdk'
3-
import { addSchemaPermission } from '../../../lib/aws-utils'
2+
3+
import { inputItem, IOFormat, selectFromList } from '@smartthings/cli-lib'
4+
45
import SchemaUpdateCommand from '../../../commands/schema/update'
6+
import { addSchemaPermission } from '../../../lib/aws-utils'
7+
import { SchemaAppWithOrganization } from '../../../lib/commands/schema-util'
58

69

710
jest.mock('../../../lib/aws-utils')
@@ -12,8 +15,12 @@ describe('SchemaUpdateCommand', () => {
1215
const listSpy = jest.spyOn(SchemaEndpoint.prototype, 'list')
1316
const logSpy = jest.spyOn(SchemaUpdateCommand.prototype, 'log').mockImplementation()
1417

15-
const schemaAppRequest = { appName: 'schemaApp' } as SchemaAppRequest
16-
const inputItemMock = jest.mocked(inputItem).mockResolvedValue([schemaAppRequest, IOFormat.JSON])
18+
const schemaAppRequest = { appName: 'schemaApp' } as SchemaAppWithOrganization
19+
const schemaAppRequestWithOrganization = {
20+
...schemaAppRequest,
21+
organizationId: 'organization-id',
22+
} as SchemaAppWithOrganization
23+
const inputItemMock = jest.mocked(inputItem).mockResolvedValue([schemaAppRequestWithOrganization, IOFormat.JSON])
1724
const addSchemaPermissionMock = jest.mocked(addSchemaPermission)
1825
const selectFromListMock = jest.mocked(selectFromList).mockResolvedValue('schemaAppId')
1926

@@ -54,7 +61,7 @@ describe('SchemaUpdateCommand', () => {
5461
it('calls correct update endpoint', async () => {
5562
await expect(SchemaUpdateCommand.run([])).resolves.not.toThrow()
5663

57-
expect(updateSpy).toBeCalledWith('schemaAppId', schemaAppRequest)
64+
expect(updateSpy).toBeCalledWith('schemaAppId', schemaAppRequest, 'organization-id')
5865
})
5966

6067
it('logs to stdout when updated', async () => {
@@ -107,6 +114,6 @@ describe('SchemaUpdateCommand', () => {
107114
await expect(SchemaUpdateCommand.run(['--authorize'])).resolves.not.toThrow()
108115

109116
expect(addSchemaPermissionMock).toBeCalledTimes(0)
110-
expect(updateSpy).toBeCalledWith('schemaAppId', noArnSchemaRequest)
117+
expect(updateSpy).toBeCalledWith('schemaAppId', noArnSchemaRequest, undefined)
111118
})
112119
})

0 commit comments

Comments
 (0)