Skip to content

Commit

Permalink
fix: fix tests #5
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Sep 23, 2024
1 parent b0a8e38 commit 838db39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
15 changes: 4 additions & 11 deletions tests/commands/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { deploy } from '../../src/commands/deploy';
import { defaultContext } from '../fixtures/deployFixture';

const mockedDeployStack = jest.fn();
jest.mock('../../src/stack', () => ({
Expand All @@ -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);
});
});
11 changes: 11 additions & 0 deletions tests/fixtures/deployFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

0 comments on commit 838db39

Please sign in to comment.