Service implement api or sdk of 3rd party.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

'use strict';
const test = require('node:test');
const assert = require('node:assert');
const axios = require('axios');
const {default: common} = require('../common.js');
const {default: aliyunSmsClient} = require('../aliyunSmsClient');
const {default: defaultConfig, getCustomConfigs: getCustomConfigs} = require('../conf/config');
const axiosConfig = {
timeout: 5000,
proxy: false
};
test('Custom config load test', async (t) => {
console.log('Config data', defaultConfig);
assert.equal(defaultConfig.ALIBABA_CLOUD_ACCESS_KEY_ID, '你的AccessKey ID');
let myConfig = await getCustomConfigs('./conf/custom_config.json');
console.log('Custom config data', myConfig);
assert.ok(myConfig);
});
test('AliyunSmsClient test', async (t) => {
let myConfig = await getCustomConfigs('./conf/custom_config.json');
let client = aliyunSmsClient.createClient(myConfig);
assert.ok(client);
/*
let signName = 'Ta荐',
templateCode = 'SMS_465915662',
templateParam = '{"code":"2345"}',
phoneNumber = '13168946847';
let sended = await aliyunSmsClient.send(myConfig, signName, templateCode, templateParam, phoneNumber);
assert.equal(sended, true);
*/
});
test('Aliyun api test', async (t) => {
let myConfig = await getCustomConfigs('./conf/custom_config.json');
let api = 'http://127.0.0.1:8081/aliyun/sendverifycode';
let params = {
phoneNumber: '13168946847',
codeNumber: '8866',
action: 'register'
};
let sign = common.sign(params, myConfig.secret);
assert.ok(myConfig);
assert.ok(sign);
params.sign = sign;
const response = await axios.post(api, params, axiosConfig);
console.log(response.data);
assert.equal(response.status, 200);
assert.equal(response.data.code, 1);
});