From 838db39b0d8e589b0d8988ba057cc6e3fa4e60a2 Mon Sep 17 00:00:00 2001 From: seven Date: Mon, 23 Sep 2024 18:56:21 +0800 Subject: [PATCH] fix: fix tests #5 Signed-off-by: seven --- jest.config.js | 5 +++++ tests/commands/deploy.test.ts | 15 ++++----------- tests/fixtures/deployFixture.ts | 11 +++++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/jest.config.js b/jest.config.js index 34f58477..dbca2c90 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 5144862b..e3ff1a7e 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 6d1e9f33..474e1753 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', +};