feat: 修复 网易搜索代码输入为中文时报错、增加 网易搜索股票代码测试用例

This commit is contained in:
zhangxiangliang 2020-08-24 00:39:35 +08:00
parent 0f7d20599f
commit cafab0ca63
2 changed files with 6 additions and 6 deletions

View File

@ -89,11 +89,11 @@ const Netease: StockApi = {
const items: Dictionary<string>[] = JSON.parse(row);
const codes: string[] = items.map(i => {
if (i.tag.includes(COMMON_SZ)) {
if (i.tag.includes(COMMON_SZ) || i.type.includes(COMMON_SZ)) {
return COMMON_SZ + i.symbol;
}
if (i.tag.includes(COMMON_SH)) {
if (i.tag.includes(COMMON_SH) || i.type.includes(COMMON_SH)) {
return COMMON_SH + i.symbol;
}

View File

@ -27,12 +27,12 @@ describe("【网易】股票代码接口", () => {
});
it("搜索股票代码", async () => {
await expect(Netease.searchStocks("510500"))
await expect(Netease.searchStocks("格力电器"))
.resolves
.toMatchObject([{ code: "SH510500", name: "500ETF" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SZ000651", name: "格力电器" })]));
await expect(Netease.searchStocks("399001"))
await expect(Netease.searchStocks("贵州茅台"))
.resolves
.toMatchObject([{ code: "SZ399001", name: "深证成指" }]);
.toEqual(expect.arrayContaining([expect.objectContaining({ code: "SH600519", name: "贵州茅台" })]));
});
});