/** * HeroUnion测试用例 * 执行此测试之前,请先启动主程序,在根目录执行命令:npm start */ import test from 'node:test'; import assert from 'node:assert'; import axios from 'axios'; import common from '../common.mjs'; import HeroUnion from '../heroUnion.mjs'; const axiosConfig = { timeout: 5000, proxy: false }; test('HeroUnion api list test', async (t) => { let api = 'http://127.0.0.1:8080/api/'; const response = await axios.get(api, axiosConfig); console.log(response.data); assert.equal(response.status, 200); }); test('Hero onboard test', async (t) => { let params = { name: 'test_hero', description: 'Hero test 测试爬虫', status: 'idle', timestamp: common.getTimestampInSeconds(), platforms: 'douyin,xigua', contracts: 'tajiantv', country: 'cn', lang: 'zh', contact: 'https://tajian.tv' }; let api = 'http://127.0.0.1:8080/api/onboard/'; const response = await axios.post(api, params, axiosConfig); console.log(response.data); assert.equal(response.status, 200); assert.equal(response.data.code, 1); params.name = 'test_hero_2'; const response2 = await axios.post(api, params, axiosConfig); console.log(response2.data); assert.equal(response2.status, 200); assert.equal(response2.data.code, 1); }); test('HeroUnion get heros test', async (t) => { let api = 'http://127.0.0.1:8080/api/heros/'; const response = await axios.get(api, axiosConfig); console.log(response.data); assert.equal(response.status, 200); }); test('HeroUnion create task test', async (t) => { let params = { uuid: 'herounion_demo', url: 'https://v.douyin.com/xxx', platform: 'douyin', contract: 'tajiantv', data_mode: 'json', country: 'cn', lang: 'zh', notify_url: 'https://tajian.tv/test/' }; let token = 'hello#world!'; params.sign = common.sign(params, token); let api = 'http://127.0.0.1:8080/api/newtask/'; const response = await axios.post(api, params, axiosConfig); console.log(response.data); assert.equal(response.status, 200); assert.equal(response.data.code, 1); }); test('HeroUnion stats test', async (t) => { let api = 'http://127.0.0.1:8080/api/stats/'; const response = await axios.get(api, axiosConfig); console.log(response.data); assert.equal(response.status, 200); });