Skip to content

Commit

Permalink
interop layer: assert sql query is called properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestranovich-noaa committed Sep 24, 2024
1 parent 267a629 commit 037fa8b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 145 deletions.
118 changes: 0 additions & 118 deletions api-interop-layer/_tests_to_copy/Test/AlertUtilityGeometry.php.test

This file was deleted.

58 changes: 31 additions & 27 deletions api-interop-layer/data/alerts/geometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,34 @@ describe("alert geometries", () => {
const rawAlert = {
geometry: "existing geometry",
};

const geometry = await generateAlertGeometry(db, rawAlert);
expect(geometry).to.equal("existing geometry");
});

it("autogenerates a geometry from affected zones", async () => {
const affectedZones = ["zone 1", "zone 2", "zone 3"];
const rawAlert = {
geometry: false,
properties: {
affectedZones: ["zone 1", "zone 2", "zone 3"],
affectedZones,
},
};
const query = `SELECT ST_ASGEOJSON(
ST_SIMPLIFY(
ST_SRID(
ST_COLLECT(shape),
0
),
0.003
)
)
as shape
FROM weathergov_geo_zones
WHERE id IN ('zone 1','zone 2','zone 3')`;
// TODO assert query was called?
db.query.resolves([{ shape: { combined: "zones" } }]);
ST_SIMPLIFY(
ST_SRID(
ST_COLLECT(shape),
0
),
0.003
)
)
AS shape
FROM weathergov_geo_zones
WHERE id IN (?,?,?)`;
db.query.withArgs(sinon.match(query), sinon.match.same(affectedZones))
.resolves([{ shape: { combined: "zones" } }]);

const geometry = await generateAlertGeometry(db, rawAlert);
expect(geometry).to.eql({ combined: "zones" });
});
Expand All @@ -68,19 +71,19 @@ describe("alert geometries", () => {
},
};
const query = `SELECT ST_ASGEOJSON(
ST_SIMPLIFY(
ST_SRID(
ST_COLLECT(shape),
0
),
0.003
)
)
as shape
FROM weathergov_geo_counties
WHERE countyFips IN (county 1,county 2,county 3)"`;
// TODO assert query was called?
db.query.resolves([{ shape: { combined: "county" } }]);
ST_SIMPLIFY(
ST_SRID(
ST_COLLECT(shape),
0
),
0.003
)
)
AS shape
FROM weathergov_geo_counties
WHERE countyFips IN ('county 1','county 2','county 3')`;
db.query.withArgs(sinon.match(query)).resolves([{ shape: { combined: "county" } }]);

const geometry = await generateAlertGeometry(db, rawAlert);
expect(geometry).to.eql({ combined: "county" });
});
Expand All @@ -90,6 +93,7 @@ describe("alert geometries", () => {
geometry: false,
properties: {},
};

const geometry = await generateAlertGeometry(db, rawAlert);
expect(geometry).to.be.null;
});
Expand Down

0 comments on commit 037fa8b

Please sign in to comment.