mirror of
https://github.com/lyz05/danmaku.git
synced 2026-04-15 11:00:25 +08:00
180 lines
6.0 KiB
JavaScript
180 lines
6.0 KiB
JavaScript
let chai = require('chai');
|
||
let chaiHttp = require('chai-http');
|
||
let app = require('../app');
|
||
const { bilibili, mgtv, tencentvideo, youku, iqiyi } = require('../routes/api/base');
|
||
const list = [bilibili, mgtv, tencentvideo, youku, iqiyi];
|
||
|
||
let should = chai.should();
|
||
chai.use(chaiHttp);
|
||
|
||
//TODO: add more test cases
|
||
describe('App', () => {
|
||
|
||
describe('弹幕解析模块测试', function () {
|
||
this.timeout(1000*10);
|
||
it('主页测试', (done) => {
|
||
chai.request(app)
|
||
.get('/')
|
||
.end((err, res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('页面统计计数测试', (done) => {
|
||
chai.request(app)
|
||
.get('/pageinfo')
|
||
.end((err, res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('传入无法打开的url测试', (done) => {
|
||
chai.request(app)
|
||
.get('/?url=ababa')
|
||
.end((err, res) => {
|
||
res.should.have.status(403);
|
||
done();
|
||
});
|
||
});
|
||
it('传入不支持的网址', (done) => {
|
||
chai.request(app)
|
||
.get('/?url=https://tv.sohu.com/v/MjAyMDA2MjYvbjYwMDg3NDcwOS5zaHRtbA==.html')
|
||
.end((err, res) => {
|
||
res.should.have.status(403);
|
||
done();
|
||
});
|
||
});
|
||
for (const item of list) {
|
||
const name = item.name;
|
||
const example_urls = item.example_urls;
|
||
for (const i in example_urls) {
|
||
const url = example_urls[i];
|
||
it(name+'视频测试#'+i, (done) => {
|
||
chai.request(app)
|
||
.get('/')
|
||
.query({url})
|
||
.end((err, res) => {
|
||
res.should.have.status(200);
|
||
res.header['content-type'].should.equal('application/xml');
|
||
done();
|
||
});
|
||
});
|
||
}
|
||
}
|
||
|
||
});
|
||
it('should respond status 404', (done) => {
|
||
chai.request(app)
|
||
.get('/wrongUrl')
|
||
.end((err, res) => {
|
||
res.should.have.status(404);
|
||
done();
|
||
});
|
||
});
|
||
describe('ipinfo modules', () => {
|
||
it('GET the ipinfo response', (done) => {
|
||
chai.request(app)
|
||
.get('/ipinfo')
|
||
.end((err, res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('GET the ipinfo with name', (done) => {
|
||
chai.request(app)
|
||
.get('/ipinfo?name=home999.cc')
|
||
.end((err, res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
});
|
||
describe('机场订阅模块',function (){
|
||
this.timeout(1000*5);
|
||
it('接口不带参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub')
|
||
.end((err,res) => {
|
||
res.should.have.status(400);
|
||
done();
|
||
});
|
||
});
|
||
it('接口错误参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?abc=123')
|
||
.end((err,res) => {
|
||
res.should.have.status(400);
|
||
done();
|
||
});
|
||
});
|
||
it('接口带user参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=congcong')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('接口错误user参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=123')
|
||
.end((err,res) => {
|
||
res.should.have.status(404);
|
||
done();
|
||
});
|
||
});
|
||
it('接口带user与ctype参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=congcong&ctype=v2ray')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('接口带user与错误ctype参数测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=congcong&ctype=abaaba')
|
||
.end((err,res) => {
|
||
res.should.have.status(404);
|
||
done();
|
||
});
|
||
});
|
||
it('接口带user与ctype参数测试,带Mozilla UA', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=congcong&ctype=v2ray')
|
||
.set('User-Agent','Mozilla/5.0 ')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('接口带user,订阅过期测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub?user=test&ctype=v2ray')
|
||
.set('User-Agent','Mozilla/5.0 ')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('缓存测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub/cache')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
done();
|
||
});
|
||
});
|
||
it('软件下载测试', (done) =>{
|
||
chai.request(app)
|
||
.get('/sub/download')
|
||
.end((err,res) => {
|
||
res.should.have.status(200);
|
||
res.text.should.have.string('clash');
|
||
res.text.should.have.string('v2ray');
|
||
res.text.should.have.string('shadowsocks');
|
||
done();
|
||
});
|
||
});
|
||
});
|
||
}); |