Skip to content

Commit

Permalink
interop tests: overnight test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestranovich-noaa committed Sep 25, 2024
1 parent 1213df4 commit 9aecd37
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions api-interop-layer/data/forecast/daily.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down

0 comments on commit 9aecd37

Please sign in to comment.