Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ SUBNET_ID=subnet-xxx
# VPC in ap-guangzhou-3 for cfs
CFS_VPC_ID=vpc-xxx
CFS_SUBNET_ID=subnet-xxx

# apigw OAUTH PUBLIC_KEY
API_PUBLIC_KEY=
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ env.js
package-lock.json
yarn.lock

__tests__/apigw.sp.test.ts
__tests__/scf.image.test.ts
__tests__/scf.sp.test.ts
__tests__/apigw/special.test.ts
__tests__/scf/image.test.ts
__tests__/scf/special.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account } from '../src';
import { Account } from '../../src';

describe('Account', () => {
const credentials = {
Expand Down
72 changes: 72 additions & 0 deletions __tests__/apigw/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { ApigwDeployInputs, ApigwDeployOutputs } from '../../src/modules/apigw/interface';
import { Apigw } from '../../src';
import { deepClone } from '../../src/utils';

describe('apigw app', () => {
const credentials = {
SecretId: process.env.TENCENT_SECRET_ID,
SecretKey: process.env.TENCENT_SECRET_KEY,
};
const inputs: ApigwDeployInputs = {
protocols: ['http', 'https'],
serviceName: 'serverless_test',
environment: 'release',
netTypes: ['OUTER'],
endpoints: [
{
path: '/appauth',
protocol: 'HTTP',
method: 'POST',
apiName: 'appauth',
authType: 'APP',
app: {
name: 'serverless_app_test',
description: 'Created by serverless test',
},
function: {
functionName: 'serverless-unit-test',
},
},
],
};
const apigw = new Apigw(credentials, process.env.REGION);
let bindOutputs: ApigwDeployOutputs;

// 由于自定义域名必须 ICP 备案,所以这里测试域名不会通过,具体测试请使用
test('create apigw with app auth success', async () => {
const apigwInputs = deepClone(inputs);
bindOutputs = await apigw.deploy(apigwInputs);

expect(bindOutputs.apiList).toEqual([
{
path: '/appauth',
internalDomain: expect.any(String),
method: 'POST',
apiName: 'appauth',
apiId: expect.stringContaining('api-'),
created: true,
authType: 'APP',
businessType: 'NORMAL',
isBase64Encoded: false,
url: expect.stringContaining('http'),
app: {
description: 'Created by serverless test',
id: expect.stringContaining('app-'),
name: 'serverless_app_test',
},
},
]);
});

test('remove app auth success', async () => {
await apigw.remove(bindOutputs);

const detail = await apigw.request({
Action: 'DescribeApi',
serviceId: bindOutputs.serviceId,
apiId: bindOutputs.apiList[0].apiId,
});

expect(detail).toBeNull();
});
});
Loading