import { assertEquals } from "https://deno.land/std@0.128.0/testing/asserts.ts"; import { ParseDocument, PublicationDocument } from "../src/documents.ts"; Deno.test("Test forward fill only applies to A03 curve type", async function (t) { // Test A01 curve type (should not forward fill) const xmlA01 = ` TestA01 1 A44 1 A43 A01 2024-01-01T00:00Z 2024-01-01T06:00Z PT1H 1 50.00 3 55.00 `; const resultA01 = ParseDocument(xmlA01) as PublicationDocument; await t.step("A01 curve type should not forward fill", async () => { const points = resultA01.timeseries[0].periods?.[0].points; assertEquals(points?.length, 2); // Should only have 2 original points assertEquals(points?.[0].position, 1); assertEquals(points?.[1].position, 3); }); // Test A02 curve type (should not forward fill) const xmlA02 = xmlA01.replace("A01", "A02"); const resultA02 = ParseDocument(xmlA02) as PublicationDocument; await t.step("A02 curve type should not forward fill", async () => { const points = resultA02.timeseries[0].periods?.[0].points; assertEquals(points?.length, 2); // Should only have 2 original points assertEquals(points?.[0].position, 1); assertEquals(points?.[1].position, 3); }); // Test A03 curve type (should forward fill) const xmlA03 = xmlA01.replace("A01", "A03"); const resultA03 = ParseDocument(xmlA03) as PublicationDocument; await t.step("A03 curve type should forward fill", async () => { const points = resultA03.timeseries[0].periods?.[0].points; assertEquals(points?.length, 6); // Should have 6 points (forward filled) assertEquals(points?.[0].position, 1); assertEquals(points?.[1].position, 2); assertEquals(points?.[2].position, 3); assertEquals(points?.[3].position, 4); assertEquals(points?.[4].position, 5); assertEquals(points?.[5].position, 6); }); // Test A03 with missing first position - should not create points with undefined values await t.step("A03 with missing first position should skip undefined values", async () => { const xmlMissingFirst = ` TestA03MissingFirst 1 A44 1 A43 A03 2024-01-01T00:00Z 2024-01-01T06:00Z PT1H 3 55.00 5 60.00 `; const result = ParseDocument(xmlMissingFirst) as PublicationDocument; const points = result.timeseries[0].periods?.[0].points; // Should only have 4 points: position 3, 4, 5, 6 (no undefined values at positions 1 and 2) assertEquals(points?.length, 4); // First point should be position 3 with actual data assertEquals(points?.[0].position, 3); assertEquals(points?.[0].price, 55.00); // Position 4 should be forward filled from position 3 assertEquals(points?.[1].position, 4); assertEquals(points?.[1].price, 55.00); // Position 5 should have actual data assertEquals(points?.[2].position, 5); assertEquals(points?.[2].price, 60.00); // Position 6 should be forward filled from position 5 assertEquals(points?.[3].position, 6); assertEquals(points?.[3].price, 60.00); // Verify no points with undefined prices exist for (const point of points || []) { if (point.price !== undefined) { assertEquals(typeof point.price, "number"); } } }); // Test A03 with empty points array await t.step("A03 with no points should return empty array", async () => { const xmlNoPoints = ` TestA03NoPoints 1 A44 1 A43 A03 2024-01-01T00:00Z 2024-01-01T06:00Z PT1H `; const result = ParseDocument(xmlNoPoints) as PublicationDocument; const points = result.timeseries[0].periods?.[0].points; // Should have empty array when no points provided assertEquals(points?.length, 0); }); // Test A03 with only last position having data await t.step("A03 with only last position should not forward fill backwards", async () => { const xmlOnlyLast = ` TestA03OnlyLast 1 A44 1 A43 A03 2024-01-01T00:00Z 2024-01-01T06:00Z PT1H 6 100.00 `; const result = ParseDocument(xmlOnlyLast) as PublicationDocument; const points = result.timeseries[0].periods?.[0].points; // Should only have 1 point (position 6) since forward fill doesn't go backwards assertEquals(points?.length, 1); assertEquals(points?.[0].position, 6); assertEquals(points?.[0].price, 100.00); }); });