Skip to content

Commit

Permalink
feat: query user for organization in schema:update and schema:create …
Browse files Browse the repository at this point in the history
…commands
  • Loading branch information
rossiam committed Sep 10, 2024
1 parent 0f577bd commit 032a231
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 80 deletions.
6 changes: 6 additions & 0 deletions .changeset/wet-bottles-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smartthings/cli": minor
"@smartthings/cli-lib": minor
---

query user for organization in schema:update and schema:create commands
29 changes: 14 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@oclif/plugin-not-found": "^2.3.1",
"@oclif/plugin-plugins": "^2.1.0",
"@smartthings/cli-lib": "^2.2.5",
"@smartthings/core-sdk": "^8.2.0",
"@smartthings/core-sdk": "^8.3.0",
"@smartthings/plugin-cli-edge": "^3.3.3",
"inquirer": "^8.2.4",
"js-yaml": "^4.1.0",
Expand Down
15 changes: 10 additions & 5 deletions packages/cli/src/__tests__/commands/schema/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { inputAndOutputItem } from '@smartthings/cli-lib'
import SchemaAppCreateCommand from '../../../commands/schema/create'
import { addSchemaPermission } from '../../../lib/aws-utils'
import { SchemaAppRequest, SchemaCreateResponse, SchemaEndpoint } from '@smartthings/core-sdk'
import { SCHEMA_AWS_PRINCIPAL } from '../../../lib/commands/schema-util'
import { SCHEMA_AWS_PRINCIPAL, SchemaAppWithOrganization } from '../../../lib/commands/schema-util'


jest.mock('../../../lib/aws-utils')
Expand Down Expand Up @@ -38,11 +38,16 @@ describe('SchemaAppCreateCommand', () => {
const schemaAppRequest = {
appName: 'schemaApp',
} as SchemaAppRequest
const schemaAppRequestWithOrganization = {
...schemaAppRequest,
organizationId: 'organization-id',
} as SchemaAppWithOrganization

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

await expect(actionFunction(undefined, schemaAppRequest)).resolves.toStrictEqual(schemaCreateResponse)
expect(createSpy).toBeCalledWith(schemaAppRequest)
await expect(actionFunction(undefined, schemaAppRequestWithOrganization))
.resolves.toStrictEqual(schemaCreateResponse)
expect(createSpy).toBeCalledWith(schemaAppRequest, 'organization-id')
})

it('accepts authorize flag and adds permissions for each lambda app region', async () => {
Expand Down Expand Up @@ -72,7 +77,7 @@ describe('SchemaAppCreateCommand', () => {
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnCN, SCHEMA_AWS_PRINCIPAL, undefined)
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnEU, SCHEMA_AWS_PRINCIPAL, undefined)
expect(addSchemaPermissionMock).toBeCalledWith(schemaAppRequest.lambdaArnAP, SCHEMA_AWS_PRINCIPAL, undefined)
expect(createSpy).toBeCalledWith(schemaAppRequest)
expect(createSpy).toBeCalledWith(schemaAppRequest, undefined)
})

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

expect(addSchemaPermissionMock).toBeCalledTimes(0)
expect(createSpy).toBeCalledWith(schemaAppRequest)
expect(createSpy).toBeCalledWith(schemaAppRequest, undefined)
})

it('passes principal flag to addSchemaPermission', async () => {
Expand Down
19 changes: 13 additions & 6 deletions packages/cli/src/__tests__/commands/schema/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { inputItem, IOFormat, selectFromList } from '@smartthings/cli-lib'
import { SchemaApp, SchemaAppRequest, SchemaEndpoint } from '@smartthings/core-sdk'
import { addSchemaPermission } from '../../../lib/aws-utils'

import { inputItem, IOFormat, selectFromList } from '@smartthings/cli-lib'

import SchemaUpdateCommand from '../../../commands/schema/update'
import { addSchemaPermission } from '../../../lib/aws-utils'
import { SchemaAppWithOrganization } from '../../../lib/commands/schema-util'


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

const schemaAppRequest = { appName: 'schemaApp' } as SchemaAppRequest
const inputItemMock = jest.mocked(inputItem).mockResolvedValue([schemaAppRequest, IOFormat.JSON])
const schemaAppRequest = { appName: 'schemaApp' } as SchemaAppWithOrganization
const schemaAppRequestWithOrganization = {
...schemaAppRequest,
organizationId: 'organization-id',
} as SchemaAppWithOrganization
const inputItemMock = jest.mocked(inputItem).mockResolvedValue([schemaAppRequestWithOrganization, IOFormat.JSON])
const addSchemaPermissionMock = jest.mocked(addSchemaPermission)
const selectFromListMock = jest.mocked(selectFromList).mockResolvedValue('schemaAppId')

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

expect(updateSpy).toBeCalledWith('schemaAppId', schemaAppRequest)
expect(updateSpy).toBeCalledWith('schemaAppId', schemaAppRequest, 'organization-id')
})

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

expect(addSchemaPermissionMock).toBeCalledTimes(0)
expect(updateSpy).toBeCalledWith('schemaAppId', noArnSchemaRequest)
expect(updateSpy).toBeCalledWith('schemaAppId', noArnSchemaRequest, undefined)
})
})
Loading

0 comments on commit 032a231

Please sign in to comment.