diff --git a/jest.config.js b/jest.config.js index 34f5847..dbca2c9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,3 +4,8 @@ module.exports = { testEnvironment: 'node', testPathIgnorePatterns: ['/node_modules/', '/dist/'], }; + +process.env.ROS_REGION_ID = 'cn-hangzhou'; +process.env.ALIYUN_ACCESS_KEY_ID = 'access key id'; +process.env.ALIYUN_ACCESS_KEY_SECRET = 'access key secret'; +process.env.ALIYUN_SECURITY_TOKEN = 'account id'; diff --git a/tests/commands/deploy.test.ts b/tests/commands/deploy.test.ts index 5144862..e3ff1a7 100644 --- a/tests/commands/deploy.test.ts +++ b/tests/commands/deploy.test.ts @@ -1,4 +1,5 @@ import { deploy } from '../../src/commands/deploy'; +import { defaultContext } from '../fixtures/deployFixture'; const mockedDeployStack = jest.fn(); jest.mock('../../src/stack', () => ({ @@ -9,18 +10,10 @@ jest.mock('../../src/stack', () => ({ describe('unit test for deploy command', () => { it('should construct valid context and deploy the stack when deploy with valid iac', async () => { const stackName = 'my-demo-stack'; + await deploy(stackName, { location: 'tests/fixtures/serverless-insight.yml', parameters: {} }); + expect(mockedDeployStack).toHaveBeenCalledTimes(1); - expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), { - accessKeyId: undefined, - accessKeySecret: undefined, - iacLocation: - '/Users/blank/Documents/dev/geekfun/serverlessinsight/tests/fixtures/serverless-insight.yml', - parameters: [], - region: 'cn-hangzhou', - securityToken: undefined, - stackName: 'my-demo-stack', - stage: 'default', - }); + expect(mockedDeployStack).toHaveBeenCalledWith(stackName, expect.any(Object), defaultContext); }); }); diff --git a/tests/fixtures/deployFixture.ts b/tests/fixtures/deployFixture.ts index 6d1e9f3..474e175 100644 --- a/tests/fixtures/deployFixture.ts +++ b/tests/fixtures/deployFixture.ts @@ -213,3 +213,14 @@ export const oneFcRos = { }, }, }; + +export const defaultContext = { + accessKeyId: 'access key id', + accessKeySecret: 'access key secret', + iacLocation: expect.stringContaining('tests/fixtures/serverless-insight.yml'), + parameters: [], + region: 'cn-hangzhou', + securityToken: 'account id', + stackName: 'my-demo-stack', + stage: 'default', +};