Skip to content

Commit

Permalink
[#153] Add test for blank infrastructure type
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangmirs committed Apr 25, 2023
1 parent 16cfec5 commit 2c97437
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,56 @@ jest.mock('@/helpers/terraform');
describe('Generator command', () => {
describe('given valid options', () => {
describe('given provider is AWS', () => {
describe('given infrastructure type is blank', () => {
const projectDir = 'aws-blank-test';
const stdoutSpy = jest.spyOn(process.stdout, 'write');

beforeAll(async () => {
(prompt as unknown as jest.Mock)
.mockResolvedValueOnce({
provider: 'aws',
versionControl: 'github',
})
.mockResolvedValueOnce({ infrastructureType: 'blank' });

await Generator.run([projectDir]);
});

afterAll(() => {
jest.resetAllMocks();
remove('/', projectDir);
});

it('creates expected directories', () => {
const expectedDirectories = ['.github/', 'base/', 'shared/'];

expect(projectDir).toHaveDirectories(expectedDirectories);
});

it('creates expected files', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'base/main.tf',
'base/variables.tf',
'base/providers.tf',
'base/outputs.tf',
'shared/main.tf',
'shared/variables.tf',
'shared/providers.tf',
'shared/outputs.tf',
];

expect(projectDir).toHaveFiles(expectedFiles);
});

it('displays the success message', () => {
expect(stdoutSpy).toHaveBeenCalledWith(
'The infrastructure template has been generated successfully!\n'
);
});
});

describe('given infrastructure type is advanced', () => {
const projectDir = 'aws-advanced-test';
const stdoutSpy = jest.spyOn(process.stdout, 'write');
Expand Down

0 comments on commit 2c97437

Please sign in to comment.