|
| 1 | +import { ApigwDeployInputs, ApigwDeployOutputs } from '../../src/modules/apigw/interface'; |
| 2 | +import { Apigw } from '../../src'; |
| 3 | +import { deepClone } from '../../src/utils'; |
| 4 | + |
| 5 | +describe('apigw app', () => { |
| 6 | + const credentials = { |
| 7 | + SecretId: process.env.TENCENT_SECRET_ID, |
| 8 | + SecretKey: process.env.TENCENT_SECRET_KEY, |
| 9 | + }; |
| 10 | + const inputs: ApigwDeployInputs = { |
| 11 | + protocols: ['http', 'https'], |
| 12 | + serviceName: 'serverless_test', |
| 13 | + environment: 'release', |
| 14 | + netTypes: ['OUTER'], |
| 15 | + endpoints: [ |
| 16 | + { |
| 17 | + path: '/appauth', |
| 18 | + protocol: 'HTTP', |
| 19 | + method: 'POST', |
| 20 | + apiName: 'appauth', |
| 21 | + authType: 'APP', |
| 22 | + app: { |
| 23 | + name: 'serverless_app_test', |
| 24 | + description: 'Created by serverless test', |
| 25 | + }, |
| 26 | + function: { |
| 27 | + functionName: 'serverless-unit-test', |
| 28 | + }, |
| 29 | + }, |
| 30 | + ], |
| 31 | + }; |
| 32 | + const apigw = new Apigw(credentials, process.env.REGION); |
| 33 | + let outputs: ApigwDeployOutputs; |
| 34 | + |
| 35 | + // 由于自定义域名必须 ICP 备案,所以这里测试域名不会通过,具体测试请使用 |
| 36 | + test('create apigw with app auth success', async () => { |
| 37 | + const apigwInputs = deepClone(inputs); |
| 38 | + outputs = await apigw.deploy(apigwInputs); |
| 39 | + |
| 40 | + expect(outputs.apiList).toEqual([ |
| 41 | + { |
| 42 | + path: '/appauth', |
| 43 | + internalDomain: expect.any(String), |
| 44 | + method: 'POST', |
| 45 | + apiName: 'appauth', |
| 46 | + apiId: expect.stringContaining('api-'), |
| 47 | + created: true, |
| 48 | + authType: 'APP', |
| 49 | + businessType: 'NORMAL', |
| 50 | + isBase64Encoded: false, |
| 51 | + url: expect.stringContaining('http'), |
| 52 | + app: { |
| 53 | + description: 'Created by serverless test', |
| 54 | + id: expect.stringContaining('app-'), |
| 55 | + name: 'serverless_app_test', |
| 56 | + }, |
| 57 | + }, |
| 58 | + ]); |
| 59 | + }); |
| 60 | + |
| 61 | + test('update apigw without app auth success', async () => { |
| 62 | + const apigwInputs = deepClone(inputs); |
| 63 | + delete apigwInputs.endpoints[0].app; |
| 64 | + apigwInputs.serviceId = outputs.serviceId; |
| 65 | + apigwInputs.endpoints[0].apiId = outputs.apiList[0].apiId; |
| 66 | + outputs = await apigw.deploy(apigwInputs); |
| 67 | + |
| 68 | + const apiAppRes: { |
| 69 | + ApiAppApiSet: { |
| 70 | + ApiAppId: string; |
| 71 | + ApiAppName: string; |
| 72 | + ApiId: string; |
| 73 | + ServiceId: string; |
| 74 | + ApiRegion: string; |
| 75 | + EnvironmentName: string; |
| 76 | + AuthorizedTime: string; |
| 77 | + }[]; |
| 78 | + } = await apigw.request({ |
| 79 | + Action: 'DescribeApiBindApiAppsStatus', |
| 80 | + ServiceId: outputs.serviceId, |
| 81 | + ApiIds: [outputs.apiList[0].apiId], |
| 82 | + }); |
| 83 | + expect(apiAppRes.ApiAppApiSet).toEqual([]); |
| 84 | + }); |
| 85 | + |
| 86 | + test('remove app auth success', async () => { |
| 87 | + outputs.apiList[0].created = true; |
| 88 | + await apigw.remove(outputs); |
| 89 | + |
| 90 | + const detail = await apigw.request({ |
| 91 | + Action: 'DescribeApi', |
| 92 | + serviceId: outputs.serviceId, |
| 93 | + apiId: outputs.apiList[0].apiId, |
| 94 | + }); |
| 95 | + |
| 96 | + expect(detail).toBeNull(); |
| 97 | + }); |
| 98 | +}); |
0 commit comments