-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(amplify-category-function): skip unnecessary prompt for 'amplify…
… update function' * feat(amplify-category-function): skip unnecessary prompt for 'amplify update function' * test: remove additional prompt from e2e
- Loading branch information
Showing
5 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...unction/src/__tests__/provider-utils/awscloudformation/utils/determineServiceSelection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { determineServiceSelection } from '../../../../provider-utils/awscloudformation/utils/determineServiceSelection'; | ||
import { ServiceName } from '../../../../provider-utils/awscloudformation/utils/constants'; | ||
|
||
const serviceSelectionPromptMock = jest.fn(); | ||
const mockChooseServiceMessage = 'mockChooseServiceMessage'; | ||
const mockContext = { | ||
amplify: { | ||
getResourceStatus: async () => { | ||
return { allResources: [] }; | ||
}, | ||
serviceSelectionPrompt: serviceSelectionPromptMock, | ||
}, | ||
}; | ||
|
||
describe('determineServiceSelection', () => { | ||
it('returns LambdaFunction when no resources exists', async () => { | ||
const response = await determineServiceSelection(mockContext, mockChooseServiceMessage); | ||
expect(response.service === ServiceName.LambdaFunction); | ||
expect(serviceSelectionPromptMock).toBeCalledTimes(0); | ||
}); | ||
|
||
it('returns LambdaFunction when only LambdaFunction resources exists', async () => { | ||
mockContext.amplify.getResourceStatus = async () => { | ||
return { | ||
allResources: [ | ||
{ | ||
service: ServiceName.LambdaFunction, | ||
}, | ||
], | ||
}; | ||
}; | ||
const response = await determineServiceSelection(mockContext, mockChooseServiceMessage); | ||
expect(response.service === ServiceName.LambdaFunction); | ||
expect(serviceSelectionPromptMock).toBeCalledTimes(0); | ||
}); | ||
|
||
it('returns LambdaLayer when only LambdaLayer resources exists', async () => { | ||
mockContext.amplify.getResourceStatus = async () => { | ||
return { | ||
allResources: [ | ||
{ | ||
service: ServiceName.LambdaLayer, | ||
}, | ||
], | ||
}; | ||
}; | ||
const response = await determineServiceSelection(mockContext, mockChooseServiceMessage); | ||
expect(response.service === ServiceName.LambdaLayer); | ||
expect(serviceSelectionPromptMock).toBeCalledTimes(0); | ||
}); | ||
|
||
it('returns LambdaLayer when existing LambdaFunction resources have mobileHubMigrated', async () => { | ||
mockContext.amplify.getResourceStatus = async () => { | ||
return { | ||
allResources: [ | ||
{ | ||
service: ServiceName.LambdaLayer, | ||
}, | ||
{ | ||
service: ServiceName.LambdaFunction, | ||
mobileHubMigrated: true, | ||
}, | ||
], | ||
}; | ||
}; | ||
const response = await determineServiceSelection(mockContext, mockChooseServiceMessage); | ||
expect(response.service === ServiceName.LambdaLayer); | ||
expect(serviceSelectionPromptMock).toBeCalledTimes(0); | ||
}); | ||
|
||
it('prompts for user input when both LambdaFunction and LambdaLayer resources exist', async () => { | ||
mockContext.amplify.getResourceStatus = async () => { | ||
return { | ||
allResources: [ | ||
{ | ||
service: ServiceName.LambdaFunction, | ||
}, | ||
{ | ||
service: ServiceName.LambdaLayer, | ||
}, | ||
], | ||
}; | ||
}; | ||
await determineServiceSelection(mockContext, mockChooseServiceMessage); | ||
expect(serviceSelectionPromptMock).toBeCalledTimes(1); | ||
}); | ||
}); |
5 changes: 2 additions & 3 deletions
5
packages/amplify-category-function/src/commands/function/update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...category-function/src/provider-utils/awscloudformation/utils/determineServiceSelection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ServiceName } from './constants'; | ||
import { categoryName } from '../../../constants'; | ||
import { supportedServices } from '../../supported-services'; | ||
|
||
export const determineServiceSelection = async (context, chooseServiceMessage) => { | ||
const { allResources } = await context.amplify.getResourceStatus(); | ||
const lambdaLayerExists = allResources.filter(resource => resource.service === ServiceName.LambdaLayer).length > 0; | ||
const lambdaFunctionExists = | ||
allResources.filter(resource => resource.service === ServiceName.LambdaFunction && resource.mobileHubMigrated !== true).length > 0; | ||
|
||
if ((!lambdaFunctionExists && !lambdaLayerExists) || (lambdaFunctionExists && !lambdaLayerExists)) { | ||
return { | ||
service: ServiceName.LambdaFunction, | ||
}; | ||
} | ||
|
||
if (!lambdaFunctionExists && lambdaLayerExists) { | ||
return { | ||
service: ServiceName.LambdaLayer, | ||
}; | ||
} | ||
|
||
return await context.amplify.serviceSelectionPrompt(context, categoryName, supportedServices, chooseServiceMessage); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters