feat: 增加 新浪股票测试用例

This commit is contained in:
zhangxiangliang 2020-07-29 02:31:57 +08:00
parent 5f5c188008
commit fc83dcb411
3 changed files with 88 additions and 1 deletions

View File

@ -9,7 +9,8 @@
| 名称 | 接口名 | 官网 |
| --- | --- | --- |
| 基础示例 | base | 无 |
| 网易财经 | netease | [传送门](https://money.163.com/)
| 网易财经 | netease | [传送门](https://money.163.com/) |
| 新浪股票 | sina | [传送门](https://finance.sina.com.cn/) |
## 安装

View File

@ -0,0 +1,16 @@
// Stock
import Sina from "../../../src/stocks/sina/api";
describe("【网易】股票代码接口", () => {
it("需要获取的股票代码", async () => {
await expect(new Sina().getStock("SH510500"))
.resolves
.toMatchObject({ code: "SH510500", name: "500ETF" });
});
it("需要获取的股票组代码", async () => {
await expect((new Sina()).getStocks(["SH510500"]))
.resolves
.toMatchObject([{ code: "SH510500", name: "500ETF" }]);
});
});

View File

@ -0,0 +1,70 @@
// Stock
import SinaExchangeTransform from "../../../src/stocks/sina/exchangeTransform";
describe("【新浪】股票代码转换测试", () => {
it("深交所股票代码转换", async () => {
expect(() => (new SinaExchangeTransform()).SZExchangeTransform("000000"))
.toThrow(new Error("请检查股票代码是否正确"));
expect((new SinaExchangeTransform()).SZExchangeTransform("SZ000000"))
.toBe("sz000000");
});
it("上交所股票代码转换", async () => {
expect(() => (new SinaExchangeTransform()).SHExchangeTransform("000000"))
.toThrow(new Error("请检查股票代码是否正确"));
expect((new SinaExchangeTransform()).SHExchangeTransform("SH000000"))
.toBe("sh000000");
});
it("港交所股票代码转换", async () => {
expect(() => (new SinaExchangeTransform()).HKExchangeTransform("000000"))
.toThrow(new Error("请检查股票代码是否正确"));
expect((new SinaExchangeTransform()).HKExchangeTransform("HK000000"))
.toBe("hk000000");
});
it("美交所股票代码转换", async () => {
expect(() => (new SinaExchangeTransform()).USExchangeTransform("000000"))
.toThrow(new Error("请检查股票代码是否正确"));
expect((new SinaExchangeTransform()).USExchangeTransform("US000000"))
.toBe("gb_000000");
});
it("交易所股票代码转换", async () => {
expect((new SinaExchangeTransform()).transform("SZ000000"))
.toBe("sz000000");
expect((new SinaExchangeTransform()).transform("SH000000"))
.toBe("sh000000");
expect((new SinaExchangeTransform()).transform("HK000000"))
.toBe("hk000000");
expect((new SinaExchangeTransform()).transform("US000000"))
.toBe("gb_000000");
expect(() => (new SinaExchangeTransform()).transform("000000"))
.toThrow(new Error("请检查股票代码是否正确"));
});
it("交易所股票组代码转换", async () => {
expect((new SinaExchangeTransform()).transforms(["SZ000000"]))
.toStrictEqual(["sz000000"]);
expect((new SinaExchangeTransform()).transforms(["SH000000"]))
.toStrictEqual(["sh000000"]);
expect((new SinaExchangeTransform()).transforms(["HK000000"]))
.toStrictEqual(["hk000000"]);
expect((new SinaExchangeTransform()).transforms(["US000000"]))
.toStrictEqual(["gb_000000"]);
expect(() => (new SinaExchangeTransform()).transforms(["000000"]))
.toThrow(new Error("请检查股票代码是否正确"));
});
});