mirror of
https://github.com/lyz05/danmaku.git
synced 2026-02-03 02:04:38 +08:00
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
import chai from "chai";
|
|
import chaiHttp from "chai-http";
|
|
import app from "../app.js";
|
|
import { createSourceList } from "../routes/sources.mjs";
|
|
|
|
const list = createSourceList();
|
|
chai.should();
|
|
chai.use(chaiHttp);
|
|
|
|
//TODO: add more test cases
|
|
describe("App", () => {
|
|
describe("弹幕解析模块测试", function () {
|
|
this.timeout(1000*30);
|
|
it("主页测试", (done) => {
|
|
chai.request(app)
|
|
.get("/")
|
|
.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})
|
|
.redirects(0)
|
|
.end((err, res) => {
|
|
if (res) {
|
|
if (name === "B站") {
|
|
res.should.redirect;
|
|
} else {
|
|
res.should.have.status(200);
|
|
res.header["content-type"].should.equal("application/xml; charset=utf-8");
|
|
}
|
|
}
|
|
done();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
});
|
|
it("should respond status 404", (done) => {
|
|
chai.request(app)
|
|
.get("/wrongUrl")
|
|
.end((err, res) => {
|
|
res.should.have.status(404);
|
|
done();
|
|
});
|
|
});
|
|
});
|