diff --git a/src/templates/aws/advanced.test.ts b/src/templates/aws/advanced.test.ts new file mode 100644 index 00000000..d6c616f7 --- /dev/null +++ b/src/templates/aws/advanced.test.ts @@ -0,0 +1,83 @@ +import { AwsOptions } from '.'; +import { remove } from '../../helpers/file'; +import { + applyAlb, + applyBastion, + applyCommon, + applyEcr, + applyEcs, + applyLog, + applyRds, + applyRegion, + applyS3, + applySecurityGroup, + applySsm, + applyVpc, +} from './addons'; +import { applyAdvancedTemplate } from './advanced'; + +jest.mock('./addons'); + +describe('AWS advanced template', () => { + describe('applyAdvancedTemplate', () => { + const projectDir = 'aws-advanced-test'; + const options: AwsOptions = { projectName: projectDir, provider: 'aws', infrastructureType: 'advanced', awsRegion: 'ap-southeast-1' }; + + beforeAll(() => { + applyAdvancedTemplate(options); + }); + + afterAll(() => { + jest.clearAllMocks(); + remove('/', projectDir); + }); + + it('applies common add-on', () => { + expect(applyCommon).toHaveBeenCalledWith(options); + }); + + it('applies region add-on', () => { + expect(applyRegion).toHaveBeenCalledWith(options); + }); + + it('applies VPC add-on', () => { + expect(applyVpc).toHaveBeenCalledWith(options); + }); + + it('applies security group add-on', () => { + expect(applySecurityGroup).toHaveBeenCalledWith(options); + }); + + it('applies ECR add-on', () => { + expect(applyEcr).toHaveBeenCalledWith(options); + }); + + it('applies log add-on', () => { + expect(applyLog).toHaveBeenCalledWith(options); + }); + + it('applies S3 add-on', () => { + expect(applyS3).toHaveBeenCalledWith(options); + }); + + it('applies ALB add-on', () => { + expect(applyAlb).toHaveBeenCalledWith(options); + }); + + it('applies RDS add-on', () => { + expect(applyRds).toHaveBeenCalledWith(options); + }); + + it('applies bastion add-on', () => { + expect(applyBastion).toHaveBeenCalledWith(options); + }); + + it('applies SSM add-on', () => { + expect(applySsm).toHaveBeenCalledWith(options); + }); + + it('applies ECS add-on', () => { + expect(applyEcs).toHaveBeenCalledWith(options); + }); + }); +}); diff --git a/src/templates/aws/advanced.ts b/src/templates/aws/advanced.ts index d6229a45..9fdf9b25 100644 --- a/src/templates/aws/advanced.ts +++ b/src/templates/aws/advanced.ts @@ -1,5 +1,18 @@ import { AwsOptions } from '.'; -import { applyAlb, applyBastion, applyCommon, applyEcr, applyEcs, applyLog, applyRds, applyRegion, applyS3, applySecurityGroup, applySsm, applyVpc } from './addons'; +import { + applyAlb, + applyBastion, + applyCommon, + applyEcr, + applyEcs, + applyLog, + applyRds, + applyRegion, + applyS3, + applySecurityGroup, + applySsm, + applyVpc, +} from './addons'; const applyAdvancedTemplate = (options: AwsOptions) => { applyCommon(options); diff --git a/src/templates/aws/index.test.ts b/src/templates/aws/index.test.ts new file mode 100644 index 00000000..9869e681 --- /dev/null +++ b/src/templates/aws/index.test.ts @@ -0,0 +1,50 @@ +import { prompt } from 'inquirer'; + +import { generateAwsTemplate } from '.'; +import { GeneralOptions } from '../../commands/generate'; +import { remove } from '../../helpers/file'; +import { applyAdvancedTemplate } from './advanced'; + +jest.mock('./advanced'); +jest.mock('inquirer'); + +describe('AWS template', () => { + describe('generateAwsTemplate', () => { + const projectDir = 'aws-advanced-test'; + const options: GeneralOptions = { projectName: projectDir, provider: 'aws' }; + + describe('given infrastructureType is basic', () => { + beforeAll(() => { + (prompt as unknown as jest.Mock) + .mockResolvedValueOnce({ infrastructureType: 'basic' }); + }); + + afterAll(() => { + jest.clearAllMocks(); + remove('/', projectDir); + }); + + it('throws the error message', async() => { + await expect(generateAwsTemplate(options)).rejects.toThrow('This type has not been implemented!'); + }); + }); + + describe('given infrastructureType is advanced', () => { + beforeAll(() => { + (prompt as unknown as jest.Mock) + .mockResolvedValueOnce({ infrastructureType: 'advanced' }); + }); + + afterAll(() => { + jest.clearAllMocks(); + remove('/', projectDir); + }); + + it('applies advanced add-ons', async() => { + await generateAwsTemplate(options); + + expect(applyAdvancedTemplate).toHaveBeenCalled(); + }); + }); + }); +});