From 5aca966eec5f54e6b49f3b7a4a6b0a10d30bcd4a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 03:34:17 +0000 Subject: [PATCH] test: add tests for seriesToBars in dnsePublic Added tests for the `seriesToBars` function in `src/data/sources/dnsePublic.ts` to improve testing coverage. The tests ensure that the function correctly: - Converts a full `OhlcvSeries` to a `Bar[]` array. - Skips mapping intraday slots when the `close` price is missing (`null`). - Returns an empty array when given an empty series. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com> --- tests/data/sources/dnsePublic.test.ts | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/data/sources/dnsePublic.test.ts diff --git a/tests/data/sources/dnsePublic.test.ts b/tests/data/sources/dnsePublic.test.ts new file mode 100644 index 0000000..3686818 --- /dev/null +++ b/tests/data/sources/dnsePublic.test.ts @@ -0,0 +1,57 @@ +import { describe, it, expect } from "vitest"; +import { seriesToBars, OhlcvSeries } from "../../../src/data/sources/dnsePublic.js"; + +describe("dnsePublic", () => { + describe("seriesToBars", () => { + it("converts OhlcvSeries to Bar[]", () => { + const series: OhlcvSeries = { + t: [1000, 2000], + o: [10, 20], + h: [15, 25], + l: [5, 15], + c: [12, 22], + v: [100, 200], + }; + + const bars = seriesToBars(series); + + expect(bars).toEqual([ + { time: 1000, open: 10, high: 15, low: 5, close: 12, volume: 100 }, + { time: 2000, open: 20, high: 25, low: 15, close: 22, volume: 200 }, + ]); + }); + + it("handles empty series", () => { + const series: OhlcvSeries = { + t: [], + o: [], + h: [], + l: [], + c: [], + v: [], + }; + + const bars = seriesToBars(series); + + expect(bars).toEqual([]); + }); + + it("skips intraday slots where close is null", () => { + const series: OhlcvSeries = { + t: [1000, 2000, 3000], + o: [10, 20, 30], + h: [15, 25, 35], + l: [5, 15, 25], + c: [12, null as unknown as number, 32], + v: [100, 200, 300], + }; + + const bars = seriesToBars(series); + + expect(bars).toEqual([ + { time: 1000, open: 10, high: 15, low: 5, close: 12, volume: 100 }, + { time: 3000, open: 30, high: 35, low: 25, close: 32, volume: 300 }, + ]); + }); + }); +});