mirror of
https://github.com/zhangxiangliang/stock-api.git
synced 2025-01-23 06:00:24 +08:00
feat: 增加 新浪股票测试用例
This commit is contained in:
parent
5f5c188008
commit
fc83dcb411
@ -9,7 +9,8 @@
|
||||
| 名称 | 接口名 | 官网 |
|
||||
| --- | --- | --- |
|
||||
| 基础示例 | base | 无 |
|
||||
| 网易财经 | netease | [传送门](https://money.163.com/)
|
||||
| 网易财经 | netease | [传送门](https://money.163.com/) |
|
||||
| 新浪股票 | sina | [传送门](https://finance.sina.com.cn/) |
|
||||
|
||||
## 安装
|
||||
|
||||
|
16
test/stocks/sina/api.test.ts
Normal file
16
test/stocks/sina/api.test.ts
Normal 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" }]);
|
||||
});
|
||||
});
|
70
test/stocks/sina/exchangeTransform.test.ts
Normal file
70
test/stocks/sina/exchangeTransform.test.ts
Normal 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("请检查股票代码是否正确"));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user