Skip to content

Commit

Permalink
api interop tests: daily forecast tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestranovich-noaa committed Sep 26, 2024
1 parent 6f9db40 commit 05e6963
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 66 deletions.
66 changes: 0 additions & 66 deletions api-interop-layer/_tests_to_copy/Test/NewRelicMetrics.php.test

This file was deleted.

76 changes: 76 additions & 0 deletions api-interop-layer/data/forecast/daily.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import sinon from "sinon";
import dayjs from "dayjs";
import { expect } from "chai";
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 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, {});
expect(valid).to.be.true;
});

it("returns one overnight period when between midnight and 6am", () => {
const timezone = "Pacific/Honolulu";
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 });
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 data before midnight", () => {
const timezone = "Pacific/Honolulu";
const data = {
properties: {
periods: [{
startTime: "2024-08-31T11:00:00-05:00",
endTime: "2024-09-01T01:00:00-05:00",
isDaytime: false,
}],
},
};
const dailyData = daily(data, { timezone });
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 tonight period when between 6pm and midnight", () => {
// TODO
});

it("returns no overnight period when between 6am and midnight", () => {
// TODO
});

it("returns three periods when between midnight and 6am", () => {
// TODO
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions api-interop-layer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api-interop-layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "CC0-1.0",
"dependencies": {
"ajv": "^8.17.1",
"convert": "^5.3.0",
"dayjs": "^1.11.12",
"fastify": "^4.28.1",
Expand Down

0 comments on commit 05e6963

Please sign in to comment.