From 9aecd374eb86ddc9049f530ae7ac8d7af3746237 Mon Sep 17 00:00:00 2001 From: James Tranovich Date: Wed, 25 Sep 2024 11:30:20 -0700 Subject: [PATCH] interop tests: overnight test --- api-interop-layer/data/forecast/daily.test.js | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/api-interop-layer/data/forecast/daily.test.js b/api-interop-layer/data/forecast/daily.test.js index 8a95f5876..ac0aad5c3 100644 --- a/api-interop-layer/data/forecast/daily.test.js +++ b/api-interop-layer/data/forecast/daily.test.js @@ -1,27 +1,45 @@ import sinon from "sinon"; import dayjs from "dayjs"; import { expect } from "chai"; -import forecast from "./index.js"; +import daily from "./daily.js"; import fs from "fs"; import path from "path"; import Ajv from "ajv"; describe("daily forecast", () => { it("returns data in the expected schema", async () => { - const where = new URL('../schemas/daily.json', import.meta.url); - const schema = JSON.parse(fs.readFileSync(where)); + const filename = new URL('../schemas/daily.json', import.meta.url); // relative to this file + const schema = JSON.parse(fs.readFileSync(filename)); const ajv = new Ajv(); // TODO // $this->onLocationRoute(34.749, -92.275); // $data = $this->block->build(); - const valid = ajv.validate(schema, { foo: 5 }); + const valid = ajv.validate(schema, {}); expect(valid).to.be.true; }); it("returns one overnight period when between midnight and 6am", () => { - // TODO + const timezone = "America/Chicago"; + const data = { + properties: { + periods: [{ + startTime: "2024-09-01T01:00:00-05:00", + endTime: "2024-09-01T04:00:00-05:00", + isDaytime: false, + }], + }, + }; + const dailyData = daily(data, { timezone }); + console.log(JSON.stringify(dailyData)); + const [ firstDay ] = dailyData.days; + expect(firstDay.periods.length).to.equal(1); + const [ firstPeriod ] = firstDay.periods; + expect(firstPeriod.isDaytime).not.to.be.true; + expect(firstPeriod.isOvernight).to.be.true; + expect(firstPeriod.timeLabel).to.equal("NOW-6AM"); + expect(firstPeriod.dayName).to.equal("Today"); }); it("returns one overnight period when between midnight and 6am, even with midnight data", () => {