Skip to content

Commit 7750182

Browse files
committed
fix(scf): support get demo address
1 parent c2dcdb8 commit 7750182

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

__tests__/scf.sp.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('Scf - special', () => {
77
SecretId: process.env.TENCENT_SECRET_ID,
88
SecretKey: process.env.TENCENT_SECRET_KEY,
99
};
10-
const scf = new Scf(credentials, 'ap-guangzhou');
10+
const client = new Scf(credentials, 'ap-guangzhou');
1111

1212
const triggers = {
1313
apigw: {
@@ -66,9 +66,13 @@ describe('Scf - special', () => {
6666

6767
let outputs;
6868

69+
test('get demo addresss', async () => {
70+
const res = await client.scf.getDemoAddress('demo-nhbwbsi4');
71+
expect(res).toContain(`https://`);
72+
});
6973
test('should deploy SCF success', async () => {
7074
await sleep(3000);
71-
outputs = await scf.deploy(inputs);
75+
outputs = await client.deploy(inputs);
7276
expect(outputs.FunctionName).toBe(inputs.name);
7377
expect(outputs.Qualifier).toBe('$LATEST');
7478
expect(outputs.Description).toBe('Created by Serverless');
@@ -80,7 +84,7 @@ describe('Scf - special', () => {
8084
});
8185
test('should update SCF success', async () => {
8286
await sleep(3000);
83-
outputs = await scf.deploy(inputs);
87+
outputs = await client.deploy(inputs);
8488
expect(outputs.FunctionName).toBe(inputs.name);
8589
expect(outputs.Qualifier).toBe('$LATEST');
8690
expect(outputs.Description).toBe('Created by Serverless');
@@ -93,13 +97,13 @@ describe('Scf - special', () => {
9397
test('[ignoreTriggers = true] update', async () => {
9498
await sleep(3000);
9599
inputs.ignoreTriggers = true;
96-
outputs = await scf.deploy(inputs);
100+
outputs = await client.deploy(inputs);
97101

98102
// expect triggers result
99103
expect(outputs.Triggers).toEqual([]);
100104
});
101105
test('should remove Scf success', async () => {
102-
const res = await scf.remove({
106+
const res = await client.remove({
103107
functionName: inputs.name,
104108
...outputs,
105109
});

src/modules/scf/apis.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ACTIONS = [
1717
'GetAlias',
1818
'Invoke',
1919
'ListTriggers',
20+
'GetDemoAddress',
2021
] as const;
2122

2223
export type ActionType = typeof ACTIONS[number];

src/modules/scf/entities/scf.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,18 @@ export default class ScfEntity extends BaseEntity {
397397

398398
return res;
399399
}
400+
401+
async getDemoAddress(demoId: string) {
402+
try {
403+
const res = await this.request({
404+
Action: 'GetDemoAddress',
405+
DemoId: demoId,
406+
});
407+
return res?.DownloadAddress;
408+
} catch (e) {
409+
console.log(`[SCF] 获取模板代码失败,${e.message}`);
410+
411+
return undefined;
412+
}
413+
}
400414
}

0 commit comments

Comments
 (0)