From 121185368e53cd993a222712b525bbbb328e8e8e Mon Sep 17 00:00:00 2001 From: Amy Fromandi Date: Wed, 23 Oct 2024 11:31:21 -0500 Subject: [PATCH] modified some a few endpoints to pass test suite --- api-tests/app.ts | 40 ++++++++++++++++++++++++++++++++++-- api-tests/v2Tests/columns.ts | 1 + v2/test/validators.ts | 11 ++++++++-- v2/units.ts | 6 +++--- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/api-tests/app.ts b/api-tests/app.ts index bb4854c0..389f8076 100644 --- a/api-tests/app.ts +++ b/api-tests/app.ts @@ -7,9 +7,45 @@ var request = require("supertest"); import * as fs from 'fs'; import * as path from 'path'; -const testFiles = [ - 'units.ts' +const testFiles = [ + 'carto_small.ts', + 'columns.ts' + 'defs.ts', + 'defs_columns.ts', + /*'defs_econs.ts', + 'defs_environments.ts', + 'defs_groups.ts', + 'defs_intervals.ts', + 'defs_lithologies.ts', + 'defs_lithology_attributes.ts', + 'defs_measurements.ts', + 'defs_minerals.ts', + 'defs_plates.ts', + 'defs_projects.ts', + 'defs_refs.ts', + 'defs_sources.ts', + 'defs_strat_name_concepts.ts', + 'defs_strat_names.ts', + 'defs_structures.ts', + 'defs_timescales.ts', + 'fossils.ts', + 'geologic_units_burwell.ts', + 'geologic_units_gmna.ts', + 'geologic_units_gmus.ts', + 'index.ts', + 'mancos_test_cases.ts', + 'mobile_fossil_collections.ts', + 'mobile_macro_summary.ts', + 'mobile_map_query.ts', + 'mobile_point.ts', + 'mobile_point_details.ts', + 'paleogeography.ts', + 'root.ts', + 'sections.ts', + 'stats.ts', + 'tiles.ts', + 'units.ts'*/ ]; /* 'carto_small.ts', diff --git a/api-tests/v2Tests/columns.ts b/api-tests/v2Tests/columns.ts index 8543ae92..a3f7c5a2 100644 --- a/api-tests/v2Tests/columns.ts +++ b/api-tests/v2Tests/columns.ts @@ -135,6 +135,7 @@ request(settings.host) it("should accept a project_id", function (done) { + this.timeout(7000); request(settings.host) .get("/columns?project_id=4") .expect(validators.aSuccessfulRequest) diff --git a/v2/test/validators.ts b/v2/test/validators.ts index d0a01d34..9b5b07eb 100644 --- a/v2/test/validators.ts +++ b/v2/test/validators.ts @@ -98,11 +98,12 @@ module.exports = { }, json: function (res) { - if (!res.body.success && !res.body.error) { - throw new Error("Request did not return valid JSON"); + if (!res.body || (!res.body.success && !res.body.error)) { + throw new Error("Request did not return valid JSON or unexpected structure"); } }, + csv: function (res) { if (res.body.length < 10) { throw new Error("No CSV output recieved"); @@ -123,8 +124,14 @@ module.exports = { }, atLeastOneResult: function (res) { + if (!res.body.success || !Array.isArray(res.body.success.data)) { + console.error("Response body:", res.body); + throw new Error("Expected success.data to be an array but got something else or undefined"); + } if (res.body.success.data.length < 1) { throw new Error("Should have returned at least one result"); } }, + + }; diff --git a/v2/units.ts b/v2/units.ts index 920e5c66..b2747290 100644 --- a/v2/units.ts +++ b/v2/units.ts @@ -582,10 +582,10 @@ module.exports = function (req, res, next, cb) { LEFT JOIN macrostrat.lookup_strat_names ON lookup_strat_names.strat_name_id=unit_strat_names.strat_name_id LEFT JOIN macrostrat.unit_notes ON unit_notes.unit_id=units.id WHERE ${where} - ${orderby.length > 0 ? `ORDER BY ${orderby.join(", ")} ASC` : ""} - ${limit}) + ${orderby.length > 0 ? `ORDER BY ${orderby.join(", ")} ASC` : ""}) SELECT * FROM orig_query - ORDER BY t_age ASC` + ORDER BY t_age ASC + ${limit}` larkin.queryPg("burwell", sql, params, function (error, result) { if (error) {