mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
feat: update tests
feat: update tests feat: update tests
This commit is contained in:
@@ -10,4 +10,4 @@ RUN npm ci && npm run build
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "./lib/cli"]
|
||||
CMD ["node", "app"]
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js",
|
||||
"test": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 c8 mocha",
|
||||
"test:integration": "docker-compose -f integration-test.yml pull && docker-compose -f integration-test.yml up --build --abort-on-container-exit --exit-code-from apicli",
|
||||
"test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 nyc mocha --require ts-node/register --exit 'test/**/*.spec.ts'"
|
||||
"test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 c8 mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elastic/elasticsearch": "8.4.0",
|
||||
@@ -36,15 +36,15 @@
|
||||
"@openstapps/core-tools": "workspace:*",
|
||||
"@openstapps/logger": "workspace:*",
|
||||
"body-parser": "1.20.2",
|
||||
"cosmiconfig": "8.1.3",
|
||||
"cors": "2.8.5",
|
||||
"cosmiconfig": "8.1.3",
|
||||
"express": "4.18.2",
|
||||
"express-prom-bundle": "6.6.0",
|
||||
"express-promise-router": "4.1.1",
|
||||
"got": "12.6.0",
|
||||
"moment": "2.29.4",
|
||||
"morgan": "1.10.0",
|
||||
"nock": "13.3.0",
|
||||
"nock": "13.3.1",
|
||||
"node-cache": "5.1.2",
|
||||
"node-cron": "3.0.2",
|
||||
"nodemailer": "6.9.1",
|
||||
@@ -61,7 +61,7 @@
|
||||
"@openstapps/tsconfig": "workspace:*",
|
||||
"@testdeck/mocha": "0.3.3",
|
||||
"@types/body-parser": "1.19.2",
|
||||
"@types/chai": "4.3.4",
|
||||
"@types/chai": "4.3.5",
|
||||
"@types/chai-as-promised": "7.1.5",
|
||||
"@types/config": "3.3.0",
|
||||
"@types/cors": "2.8.13",
|
||||
@@ -77,21 +77,21 @@
|
||||
"@types/sinon-express-mock": "1.3.9",
|
||||
"@types/supertest": "2.0.12",
|
||||
"@types/uuid": "8.3.4",
|
||||
"c8": "7.13.0",
|
||||
"chai": "4.3.7",
|
||||
"chai-as-promised": "7.1.1",
|
||||
"cross-env": "7.0.3",
|
||||
"conventional-changelog-cli": "2.2.2",
|
||||
"cross-env": "7.0.3",
|
||||
"esmock": "2.2.3",
|
||||
"get-port": "5.1.1",
|
||||
"mocha": "10.2.0",
|
||||
"mocked-env": "1.3.5",
|
||||
"c8": "7.13.0",
|
||||
"redoc-cli": "0.13.20",
|
||||
"sinon": "15.0.4",
|
||||
"sinon-express-mock": "2.2.1",
|
||||
"supertest": "6.3.3",
|
||||
"tsup": "6.7.0",
|
||||
"typedoc": "0.23.28",
|
||||
"typescript": "4.8.4"
|
||||
"typescript": "4.6.4"
|
||||
},
|
||||
"tsup": {
|
||||
"entry": [
|
||||
|
||||
@@ -39,6 +39,7 @@ import {virtualPluginRoute} from './routes/virtual-plugin-route.js';
|
||||
import {BulkStorage} from './storage/bulk-storage.js';
|
||||
import {DatabaseConstructor} from './storage/database.js';
|
||||
import {backendConfig} from './config.js';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
/**
|
||||
* Configure the backend
|
||||
@@ -143,9 +144,9 @@ export async function configureApp(app: Express, databases: {[name: string]: Dat
|
||||
});
|
||||
|
||||
// validate config file
|
||||
const directory = path.dirname(fileURLToPath(import.meta.url));
|
||||
await validator.addSchemas(
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
path.join(path.dirname(require.resolve('@openstapps/core/package.json')), 'lib', 'schema'),
|
||||
path.join(directory, '..', 'node_modules', '@openstapps', 'core', 'lib', 'schema'),
|
||||
);
|
||||
|
||||
// validate the config file
|
||||
|
||||
@@ -49,7 +49,7 @@ export async function virtualPluginRoute(request: Request, plugin: SCPluginMetaD
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw new SCValidationErrorResponse(responseValidation.errors, isTestEnvironment);
|
||||
}
|
||||
return response;
|
||||
return responseBody as object;
|
||||
} catch (error) {
|
||||
// wrap exact error inside of the internal server error response
|
||||
throw new SCInternalServerErrorResponse(error, isTestEnvironment);
|
||||
|
||||
@@ -150,3 +150,6 @@ export async function setUp(
|
||||
|
||||
Logger.log(`Scheduled ${monitoringConfig.watchers.length} watches`);
|
||||
}
|
||||
|
||||
// do this for esm mocking
|
||||
export default {setUp};
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCBackendConfigurationSearchBoostingType} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Creates boost functions for all type boost configurations
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {QueryDslFunctionScoreContainer} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCBackendConfigurationSearchBoostingContext, SCSearchContext} from '@openstapps/core';
|
||||
import {buildFunctionsForBoostingTypes} from './boost-functions';
|
||||
import {buildFunctionsForBoostingTypes} from './boost-functions.js';
|
||||
|
||||
/**
|
||||
* Builds scoring functions from boosting config
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
*/
|
||||
import {QueryDslQueryContainer} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCSearchFilter} from '@openstapps/core';
|
||||
import {buildBooleanFilter} from './filters/boolean';
|
||||
import {buildAvailabilityFilter} from './filters/availability';
|
||||
import {buildDateRangeFilter} from './filters/date-range';
|
||||
import {buildDistanceFilter} from './filters/distance';
|
||||
import {buildGeoFilter} from './filters/geo';
|
||||
import {buildNumericRangeFilter} from './filters/numeric-range';
|
||||
import {buildValueFilter} from './filters/value';
|
||||
import {buildBooleanFilter} from './filters/boolean.js';
|
||||
import {buildAvailabilityFilter} from './filters/availability.js';
|
||||
import {buildDateRangeFilter} from './filters/date-range.js';
|
||||
import {buildDistanceFilter} from './filters/distance.js';
|
||||
import {buildGeoFilter} from './filters/geo.js';
|
||||
import {buildNumericRangeFilter} from './filters/numeric-range.js';
|
||||
import {buildValueFilter} from './filters/value.js';
|
||||
|
||||
/**
|
||||
* Converts Array of Filters to elasticsearch query-syntax
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCSearchAvailabilityFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts an availability filter to elasticsearch syntax
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
*/
|
||||
import {QueryDslBoolQuery} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCSearchBooleanFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {buildFilter} from '../filter';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
import {buildFilter} from '../filter.js';
|
||||
|
||||
/**
|
||||
* Converts a boolean filter to elasticsearch syntax
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {QueryDslDateRangeQuery} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCSearchDateRangeFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts a date range filter to elasticsearch syntax
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {QueryDslGeoDistanceQuery} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCSearchDistanceFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts a distance filter to elasticsearch syntax
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCGeoFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts a geo filter to elasticsearch syntax
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
import {QueryDslNumberRangeQuery} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {SCSearchNumericRangeFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts a numeric range filter to elasticsearch syntax
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCSearchValueFilter} from '@openstapps/core';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util';
|
||||
import {QueryDslSpecificQueryContainer} from '../../types/util.js';
|
||||
|
||||
/**
|
||||
* Converts a value filter to elasticsearch syntax
|
||||
|
||||
@@ -26,7 +26,7 @@ import {buildScoringFunctions} from './boost/scoring-functions.js';
|
||||
* @param elasticsearchConfig Elasticsearch configuration
|
||||
* @returns ElasticsearchQuery (body of a search-request)
|
||||
*/
|
||||
export function buildQuery(
|
||||
export const buildQuery = function buildQuery(
|
||||
parameters: SCSearchQuery,
|
||||
defaultConfig: SCConfigFile,
|
||||
elasticsearchConfig: ElasticsearchConfig,
|
||||
@@ -111,4 +111,4 @@ export function buildQuery(
|
||||
}
|
||||
|
||||
return functionScoreQuery;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import {buildPriceSort} from './sort/price.js';
|
||||
* @param sorts Sorting rules to apply to the data that is being queried
|
||||
* @returns an array of sort queries
|
||||
*/
|
||||
export function buildSort(sorts: SCSearchSort[]): Sort {
|
||||
export const buildSort = function buildSort(sorts: SCSearchSort[]): Sort {
|
||||
return sorts.map(sort => {
|
||||
switch (sort.type) {
|
||||
case 'generic': {
|
||||
@@ -42,4 +42,4 @@ export function buildSort(sorts: SCSearchSort[]): Sort {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
import {SCConfigFile, SCSearchQuery, SCSearchResponse, SCThings, SCThingType, SCUuid} from '@openstapps/core';
|
||||
import {Express} from 'express';
|
||||
import moment from 'moment';
|
||||
import {getIndexUID} from '../src/storage/elasticsearch/util.js';
|
||||
import {configureApp} from '../src/app.js';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
@@ -26,6 +25,7 @@ import getPort from 'get-port';
|
||||
import {Database} from '../src/storage/database.js';
|
||||
import {v4} from 'uuid';
|
||||
import {backendConfig} from '../src/config.js';
|
||||
import {getIndexUID} from '../src/storage/elasticsearch/util/index.js';
|
||||
|
||||
/**
|
||||
* Adds routers and configures an (express) app
|
||||
|
||||
@@ -31,8 +31,8 @@ import {buildQuery} from '../../../src/storage/elasticsearch/query/query.js';
|
||||
import {buildSort} from '../../../src/storage/elasticsearch/query/sort.js';
|
||||
import {ElasticsearchConfig} from '../../../src/storage/elasticsearch/types/elasticsearch-config.js';
|
||||
import {QueryDslSpecificQueryContainer} from '../../../src/storage/elasticsearch/types/util.js';
|
||||
import {configFile} from '../../../src/common.js';
|
||||
import {SortCombinations} from '@elastic/elasticsearch/lib/api/types';
|
||||
import {backendConfig} from '../../../src/config.js';
|
||||
|
||||
describe('Query', function () {
|
||||
describe('buildBooleanFilter', function () {
|
||||
@@ -363,9 +363,7 @@ describe('Query', function () {
|
||||
const filter = buildFilter(rawFilter) as QueryDslSpecificQueryContainer<'range'>;
|
||||
expect(filter).to.deep.equal(expectedFilter);
|
||||
for (const bound of ['g', 'l']) {
|
||||
// @ts-expect-error implicit any
|
||||
const inclusiveExists = typeof filter.range.price[`${bound}t`] !== 'undefined';
|
||||
// @ts-expect-error implicit any
|
||||
const exclusiveExists = typeof filter.range.price[`${bound}te`] !== 'undefined';
|
||||
|
||||
// only one should exist at the same time
|
||||
|
||||
Reference in New Issue
Block a user