mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-23 10:02:51 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0dc3792fb9 | ||
|
|
223b5ee5c0 | ||
|
|
a65cfc1176 | ||
|
|
f54d04f94d | ||
|
|
315e15f53d | ||
|
|
d2fe89ec3a | ||
|
|
0d3248fff0 | ||
|
|
1748ba3825 | ||
|
|
8962da31a3 | ||
|
|
de8033c218 | ||
|
|
cb9dd83bef | ||
|
|
6257ca0dd3 | ||
|
|
6a87557109 | ||
|
|
83120a6734 | ||
|
|
d601880be1 | ||
|
|
8615203a3e | ||
|
|
3a5ee64db5 | ||
|
|
bfe3faa01c | ||
|
|
8b98b8afdc | ||
|
|
7a01a6b305 | ||
|
|
bc2274a9ef | ||
|
|
0becdeb6d9 | ||
|
|
dacb1c66e8 | ||
|
|
e187ee8c44 | ||
|
|
c9f37a1df0 | ||
|
|
6dd5fcdde5 | ||
|
|
26c14fa7e9 | ||
|
|
8cb4ee12a6 | ||
|
|
a09359d0b2 | ||
|
|
bf3a716767 | ||
|
|
1b3c43d2cb | ||
|
|
fee9a163e1 | ||
|
|
472a1b97d6 | ||
|
|
227abeb36d | ||
|
|
be1fef2e25 | ||
|
|
587c98a50e | ||
|
|
c685adcac6 |
54
CHANGELOG.md
54
CHANGELOG.md
@@ -1,3 +1,57 @@
|
|||||||
|
# [0.41.0](https://gitlab.com/openstapps/api/compare/v0.40.0...v0.41.0) (2022-05-17)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.40.0](https://gitlab.com/openstapps/api/compare/v0.39.0...v0.40.0) (2022-04-04)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.39.0](https://gitlab.com/openstapps/api/compare/v0.38.0...v0.39.0) (2022-03-17)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.38.0](https://gitlab.com/openstapps/api/compare/v0.37.0...v0.38.0) (2022-01-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add client method for invoking plugin routes ([83120a6](https://gitlab.com/openstapps/api/commit/83120a67345d2fee672f6a44ab91708ecce65e58))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.37.0](https://gitlab.com/openstapps/api/compare/v0.36.0...v0.37.0) (2021-12-17)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.36.0](https://gitlab.com/openstapps/api/compare/v0.35.0...v0.36.0) (2021-12-15)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.35.0](https://gitlab.com/openstapps/api/compare/v0.34.0...v0.35.0) (2021-10-20)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.34.0](https://gitlab.com/openstapps/api/compare/v0.33.0...v0.34.0) (2021-10-04)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.33.0](https://gitlab.com/openstapps/api/compare/v0.32.0...v0.33.0) (2021-09-16)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [0.32.0](https://gitlab.com/openstapps/api/compare/v0.31.1...v0.32.0) (2021-09-01)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [0.31.1](https://gitlab.com/openstapps/api/compare/v0.31.0...v0.31.1) (2021-08-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* plugin related tests ([51c157d](https://gitlab.com/openstapps/api/commit/51c157d577b9ae70e8c4683e653cd65aacb4f248))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [0.31.0](https://gitlab.com/openstapps/api/compare/v0.30.0...v0.31.0) (2021-08-17)
|
# [0.31.0](https://gitlab.com/openstapps/api/compare/v0.30.0...v0.31.0) (2021-08-17)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3288
package-lock.json
generated
3288
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
67
package.json
67
package.json
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@openstapps/api",
|
"name": "@openstapps/api",
|
||||||
"version": "0.31.1",
|
"version": "0.41.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run tslint && npm run compile",
|
"build": "npm run tslint && npm run compile",
|
||||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md && git commit -m 'docs: update changelog'",
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md && git commit -m 'docs: update changelog'",
|
||||||
"check-configuration": "openstapps-configuration",
|
"check-configuration": "openstapps-configuration",
|
||||||
"compile": "rimraf lib && tsc && prepend lib/cli.js '#!/usr/bin/env node\n'",
|
"compile": "rimraf lib && tsc && prepend lib/cli.js '#!/usr/bin/env node\n'",
|
||||||
"documentation": "typedoc --includeDeclarations --mode modules --out docs --readme README.md --listInvalidSymbolLinks src",
|
"documentation": "typedoc --includeVersion --out docs --readme README.md --listInvalidSymbolLinks --entryPointStrategy expand src",
|
||||||
"postversion": "npm run changelog",
|
"postversion": "npm run changelog",
|
||||||
"prepublishOnly": "npm ci && npm run build",
|
"prepublishOnly": "npm ci && npm run build",
|
||||||
"preversion": "npm run prepublishOnly",
|
"preversion": "npm run prepublishOnly",
|
||||||
@@ -16,53 +16,54 @@
|
|||||||
},
|
},
|
||||||
"description": "Node.js library to interact with the StApps backend service",
|
"description": "Node.js library to interact with the StApps backend service",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@krlwlfrt/async-pool": "0.5.0",
|
"@krlwlfrt/async-pool": "0.7.0",
|
||||||
"@openstapps/core": "0.49.3",
|
"@openstapps/core": "0.66.1",
|
||||||
"@openstapps/core-tools": "0.24.3",
|
"@openstapps/core-tools": "0.30.1",
|
||||||
"@openstapps/logger": "0.7.0",
|
"@openstapps/logger": "0.8.1",
|
||||||
"@types/cli-progress": "3.9.2",
|
"@types/cli-progress": "3.11.0",
|
||||||
"@types/express": "4.17.13",
|
"@types/express": "4.17.13",
|
||||||
"@types/morgan": "1.9.3",
|
"@types/morgan": "1.9.3",
|
||||||
"@types/node": "14.17.12",
|
"@types/node": "14.18.18",
|
||||||
"@types/traverse": "0.6.32",
|
"@types/traverse": "0.6.32",
|
||||||
"@types/uuid": "8.3.1",
|
"@types/uuid": "8.3.4",
|
||||||
"@types/wait-on": "5.3.1",
|
"@types/wait-on": "5.3.1",
|
||||||
"body-parser": "1.19.0",
|
"body-parser": "1.20.0",
|
||||||
"cli-progress": "3.9.0",
|
"cli-progress": "3.11.1",
|
||||||
"commander": "7.2.0",
|
"commander": "9.2.0",
|
||||||
"express": "4.17.1",
|
"express": "4.18.1",
|
||||||
"fast-clone": "1.5.13",
|
"got": "11.8.3",
|
||||||
"got": "11.8.2",
|
"json-schema": "0.4.0",
|
||||||
"json-schema": "0.3.0",
|
"moment": "2.29.3",
|
||||||
"moment": "2.29.1",
|
|
||||||
"morgan": "1.10.0",
|
"morgan": "1.10.0",
|
||||||
|
"rfdc": "1.3.0",
|
||||||
"traverse": "0.6.6",
|
"traverse": "0.6.6",
|
||||||
"uuid": "8.3.2",
|
"uuid": "8.3.2",
|
||||||
"wait-on": "5.3.0"
|
"wait-on": "6.0.1"
|
||||||
},
|
},
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@openstapps/configuration": "0.27.0",
|
"@openstapps/configuration": "0.29.1",
|
||||||
"@testdeck/mocha": "0.1.2",
|
"@testdeck/mocha": "0.2.0",
|
||||||
"@types/chai": "4.2.21",
|
"@types/chai": "4.3.1",
|
||||||
"@types/chai-as-promised": "7.1.4",
|
"@types/chai-as-promised": "7.1.5",
|
||||||
"@types/chai-spies": "1.0.3",
|
"@types/chai-spies": "1.0.3",
|
||||||
"@types/fs-extra": "9.0.12",
|
"@types/fs-extra": "9.0.13",
|
||||||
"@types/mocha": "8.2.3",
|
"@types/json-schema": "7.0.11",
|
||||||
"chai": "4.3.4",
|
"@types/mocha": "9.1.1",
|
||||||
|
"chai": "4.3.6",
|
||||||
"chai-as-promised": "7.1.1",
|
"chai-as-promised": "7.1.1",
|
||||||
"chai-spies": "1.0.0",
|
"chai-spies": "1.0.0",
|
||||||
"conventional-changelog-cli": "2.1.1",
|
"conventional-changelog-cli": "2.2.2",
|
||||||
"fs-extra": "9.1.0",
|
"fs-extra": "10.1.0",
|
||||||
"mocha": "8.4.0",
|
"mocha": "10.0.0",
|
||||||
"nock": "13.1.3",
|
"nock": "13.2.4",
|
||||||
"nyc": "15.1.0",
|
"nyc": "15.1.0",
|
||||||
"prepend-file-cli": "1.0.6",
|
"prepend-file-cli": "1.0.6",
|
||||||
"rimraf": "3.0.2",
|
"rimraf": "3.0.2",
|
||||||
"ts-node": "9.1.1",
|
"ts-node": "10.8.0",
|
||||||
"tslint": "6.1.3",
|
"tslint": "6.1.3",
|
||||||
"typedoc": "0.18.0",
|
"typedoc": "0.22.15",
|
||||||
"typescript": "3.8.3"
|
"typescript": "3.9.10"
|
||||||
},
|
},
|
||||||
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -75,7 +76,7 @@
|
|||||||
"Wieland Schöbl <wulkanat@gmail.com>"
|
"Wieland Schöbl <wulkanat@gmail.com>"
|
||||||
],
|
],
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@openstapps/core": "~0.49.0"
|
"@openstapps/core": "~0.66.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ commander
|
|||||||
.command('e2e <to>')
|
.command('e2e <to>')
|
||||||
.version(pkgJson.version)
|
.version(pkgJson.version)
|
||||||
.description('Run in end to end test mode. Indexing and afterwards retrieving all test files from @openstapp/core to the backend')
|
.description('Run in end to end test mode. Indexing and afterwards retrieving all test files from @openstapp/core to the backend')
|
||||||
.option('-s --samples [path]', 'Path to @openstapp/core test files', './node_modules/@openstapps/core/test/resources')
|
.option('-s --samples [path]', 'Path to @openstapp/core test files', './node_modules/@openstapps/core/test/resources/indexable')
|
||||||
.option('-w --waiton [resource]', 'wait-on resource parameter see "www.npmjs.com/wait-on"')
|
.option('-w --waiton [resource]', 'wait-on resource parameter see "www.npmjs.com/wait-on"')
|
||||||
.action(async (to, e2eCommand) => {
|
.action(async (to, e2eCommand) => {
|
||||||
let toURL = '';
|
let toURL = '';
|
||||||
|
|||||||
@@ -15,9 +15,8 @@
|
|||||||
import {
|
import {
|
||||||
SCAbstractRoute,
|
SCAbstractRoute,
|
||||||
SCErrorResponse,
|
SCErrorResponse,
|
||||||
SCFeedbackRequest,
|
SCFeatureConfiguration,
|
||||||
SCFeedbackResponse,
|
SCFeatureConfigurationPlugin,
|
||||||
SCFeedbackRoute,
|
|
||||||
SCIndexRequest,
|
SCIndexRequest,
|
||||||
SCIndexResponse,
|
SCIndexResponse,
|
||||||
SCIndexRoute,
|
SCIndexRoute,
|
||||||
@@ -32,17 +31,13 @@ import {
|
|||||||
SCSearchRoute,
|
SCSearchRoute,
|
||||||
SCThings,
|
SCThings,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError} from './errors';
|
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError, PluginNotAvailableError} from './errors';
|
||||||
import {HttpClientHeaders, HttpClientInterface} from './http-client-interface';
|
import {HttpClientHeaders, HttpClientInterface} from './http-client-interface';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StApps-API client
|
* StApps-API client
|
||||||
*/
|
*/
|
||||||
export class Client {
|
export class Client {
|
||||||
/**
|
|
||||||
* Instance of feedback request route
|
|
||||||
*/
|
|
||||||
private readonly feedbackRoute = new SCFeedbackRoute();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of index route
|
* Instance of index route
|
||||||
@@ -59,6 +54,11 @@ export class Client {
|
|||||||
*/
|
*/
|
||||||
private readonly searchRoute = new SCSearchRoute();
|
private readonly searchRoute = new SCSearchRoute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Features supported by backend
|
||||||
|
*/
|
||||||
|
private supportedFeatures?: SCFeatureConfiguration = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default headers
|
* Default headers
|
||||||
*
|
*
|
||||||
@@ -111,15 +111,6 @@ export class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send feedback
|
|
||||||
*
|
|
||||||
* @param feedback Feedback to send
|
|
||||||
*/
|
|
||||||
async feedback(feedback: SCFeedbackRequest): Promise<SCFeedbackResponse> {
|
|
||||||
return this.invokeRoute<SCFeedbackResponse>(this.feedbackRoute, undefined, feedback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a thing by its UID
|
* Get a thing by its UID
|
||||||
*
|
*
|
||||||
@@ -157,10 +148,42 @@ export class Client {
|
|||||||
if (response.backend.SCVersion.split('.')[0] !== coreVersion.split('.')[0]) {
|
if (response.backend.SCVersion.split('.')[0] !== coreVersion.split('.')[0]) {
|
||||||
throw new CoreVersionIncompatibleError(coreVersion, response.backend.SCVersion);
|
throw new CoreVersionIncompatibleError(coreVersion, response.backend.SCVersion);
|
||||||
}
|
}
|
||||||
|
/* istanbul ignore next */
|
||||||
|
this.supportedFeatures = response?.app?.features;
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke a plugin route
|
||||||
|
*
|
||||||
|
* @param name name of the plugin
|
||||||
|
* @param parameters Parameters for the URL fragment
|
||||||
|
* @param body Body for the request
|
||||||
|
*/
|
||||||
|
async invokePlugin<T>(name: string,
|
||||||
|
parameters?: { [k: string]: string; },
|
||||||
|
body?: SCRequests): Promise<T> {
|
||||||
|
|
||||||
|
if (typeof this.supportedFeatures === 'undefined') {
|
||||||
|
const request: SCIndexRequest = {};
|
||||||
|
const response = await this.invokeRoute<SCIndexResponse>(this.indexRoute, undefined, request);
|
||||||
|
if (typeof response?.app?.features !== 'undefined') {
|
||||||
|
/* istanbul ignore next */
|
||||||
|
this.supportedFeatures = response?.app?.features;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const pluginInfo: SCFeatureConfigurationPlugin | undefined = this.supportedFeatures?.plugins?.[name];
|
||||||
|
if (typeof pluginInfo === 'undefined') {
|
||||||
|
throw new PluginNotAvailableError(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const route = new SCIndexRoute();
|
||||||
|
route.urlPath = pluginInfo.urlPath;
|
||||||
|
|
||||||
|
return this.invokeRoute<T>(route, parameters, body);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke a route
|
* Invoke a route
|
||||||
*
|
*
|
||||||
@@ -177,7 +200,7 @@ export class Client {
|
|||||||
// TODO: remove headers
|
// TODO: remove headers
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: route.method,
|
method: route.method,
|
||||||
url: new URL(this.url + route.getUrlFragment(parameters)),
|
url: new URL(this.url + route.getUrlPath(parameters)),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode === route.statusCodeSuccess) {
|
if (response.statusCode === route.statusCodeSuccess) {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import {
|
|||||||
SCThingUpdateResponse,
|
SCThingUpdateResponse,
|
||||||
SCThingUpdateRoute,
|
SCThingUpdateRoute,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
import clone = require('fast-clone');
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import clone = require('rfdc');
|
||||||
import {v5} from 'uuid';
|
import {v5} from 'uuid';
|
||||||
import {Bulk} from './bulk';
|
import {Bulk} from './bulk';
|
||||||
import {Client} from './client';
|
import {Client} from './client';
|
||||||
@@ -82,7 +82,7 @@ export class ConnectorClient extends Client {
|
|||||||
static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> {
|
static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> {
|
||||||
|
|
||||||
// tslint:disable-next-line:no-any
|
// tslint:disable-next-line:no-any
|
||||||
const thingWithoutReferences = clone<any>(thing);
|
const thingWithoutReferences = clone()<any>(thing);
|
||||||
|
|
||||||
delete thingWithoutReferences.origin;
|
delete thingWithoutReferences.origin;
|
||||||
|
|
||||||
|
|||||||
@@ -103,14 +103,13 @@ function compareItems() {
|
|||||||
* Function to add all the SCThings that getItemsFromSamples() returns to the backend
|
* Function to add all the SCThings that getItemsFromSamples() returns to the backend
|
||||||
*/
|
*/
|
||||||
async function indexSamples(api: ConnectorClient, options: E2EOptions): Promise<void> {
|
async function indexSamples(api: ConnectorClient, options: E2EOptions): Promise<void> {
|
||||||
|
try {
|
||||||
const items = await getItemsFromSamples(options.samplesLocation);
|
const items = await getItemsFromSamples(options.samplesLocation);
|
||||||
|
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
throw new Error('Could not index samples. None were retrieved from the file system.');
|
throw new Error('Could not index samples. None were retrieved from the file system.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// sort items by type
|
// sort items by type
|
||||||
const itemMap: Map<SCThingType, SCThings[]> = new Map();
|
const itemMap: Map<SCThingType, SCThings[]> = new Map();
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
@@ -155,7 +154,7 @@ export async function getItemsFromSamples<T extends SCThings>(samplesDirectory:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return things;
|
return things;
|
||||||
|
|||||||
@@ -131,3 +131,18 @@ export class CoreVersionIncompatibleError extends ApiError {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error that is thrown when API and backend StAppsCore versions are incompatible
|
||||||
|
*/
|
||||||
|
export class PluginNotAvailableError extends ApiError {
|
||||||
|
/**
|
||||||
|
* Instantiate a new error
|
||||||
|
*/
|
||||||
|
constructor(requestedPluginWithName: string) {
|
||||||
|
super({
|
||||||
|
message: `A plugin named ${requestedPluginWithName} is not available.`,
|
||||||
|
name: 'PluginNotAvailable',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,11 +73,13 @@ export class HttpClient {
|
|||||||
try {
|
try {
|
||||||
response = await got(requestConfig.url.toString(), params);
|
response = await got(requestConfig.url.toString(), params);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (typeof err.response === 'undefined') {
|
// tslint:disable-next-line: no-any
|
||||||
|
if (typeof (err as any).response === 'undefined') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// if there is a response (e.g. response with statusCode 404 etc.) provide it
|
// if there is a response (e.g. response with statusCode 404 etc.) provide it
|
||||||
response = err.response;
|
// tslint:disable-next-line: no-any
|
||||||
|
response = (err as any).response as Response<TYPE_OF_BODY>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ export abstract class Plugin {
|
|||||||
* @param req An express Request from the backend
|
* @param req An express Request from the backend
|
||||||
* @param res An express Response to the backend for you to send back data
|
* @param res An express Response to the backend for you to send back data
|
||||||
*/
|
*/
|
||||||
protected abstract async onRouteInvoke(req: express.Request, res: express.Response): Promise<void>;
|
protected abstract onRouteInvoke(req: express.Request, res: express.Response): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the server
|
* Closes the server
|
||||||
@@ -222,9 +222,9 @@ export abstract class Plugin {
|
|||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (typeof err !== 'undefined') {
|
if (typeof err !== 'undefined') {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
return reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
resolve();
|
resolve(undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,6 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
SCFeedbackRequest,
|
|
||||||
SCFeedbackResponse,
|
|
||||||
SCFeedbackRoute,
|
|
||||||
SCIndexResponse,
|
SCIndexResponse,
|
||||||
SCIndexRoute,
|
SCIndexRoute,
|
||||||
SCMessage,
|
SCMessage,
|
||||||
@@ -44,7 +41,6 @@ chai.use(chaiAsPromised);
|
|||||||
const sandbox = chai.spy.sandbox();
|
const sandbox = chai.spy.sandbox();
|
||||||
|
|
||||||
const indexRoute = new SCIndexRoute();
|
const indexRoute = new SCIndexRoute();
|
||||||
const feedbackRoute = new SCFeedbackRoute();
|
|
||||||
const multiSearchRoute = new SCMultiSearchRoute();
|
const multiSearchRoute = new SCMultiSearchRoute();
|
||||||
const searchRoute = new SCSearchRoute();
|
const searchRoute = new SCSearchRoute();
|
||||||
|
|
||||||
@@ -65,6 +61,9 @@ export type RecursivePartial<T> = {
|
|||||||
async function invokeIndexRoute(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> {
|
async function invokeIndexRoute(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
|
app: {
|
||||||
|
features: {},
|
||||||
|
},
|
||||||
backend: {
|
backend: {
|
||||||
SCVersion: 'foo.bar.dummy',
|
SCVersion: 'foo.bar.dummy',
|
||||||
},
|
},
|
||||||
@@ -113,58 +112,7 @@ export class ClientSpec {
|
|||||||
'X-StApps-Version': 'foo.foo.foo',
|
'X-StApps-Version': 'foo.foo.foo',
|
||||||
},
|
},
|
||||||
method: indexRoute.method,
|
method: indexRoute.method,
|
||||||
url: new URL('http://localhost' + indexRoute.getUrlFragment()),
|
url: new URL('http://localhost' + indexRoute.getUrlPath()),
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
async feedback() {
|
|
||||||
sandbox.on(httpClient, 'request', async (): Promise<HttpClientResponse<SCFeedbackResponse>> => {
|
|
||||||
return {
|
|
||||||
body: {},
|
|
||||||
headers: {},
|
|
||||||
statusCode: feedbackRoute.statusCodeSuccess,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(httpClient.request).not.to.have.been.first.called();
|
|
||||||
|
|
||||||
const client = new Client(httpClient, 'http://localhost');
|
|
||||||
const feedback: SCFeedbackRequest = {
|
|
||||||
audiences: [
|
|
||||||
'employees',
|
|
||||||
],
|
|
||||||
categories: [
|
|
||||||
'news'
|
|
||||||
],
|
|
||||||
messageBody: 'Lorem ipsum.',
|
|
||||||
metaData: {
|
|
||||||
debug: true,
|
|
||||||
platform: 'android',
|
|
||||||
scope: {},
|
|
||||||
sendable: true,
|
|
||||||
state: 'foo',
|
|
||||||
userAgent: 'bar',
|
|
||||||
version: 'foobar',
|
|
||||||
},
|
|
||||||
name: 'foo',
|
|
||||||
origin: {
|
|
||||||
indexed: 'foo',
|
|
||||||
name: 'foo',
|
|
||||||
type: SCThingOriginType.Remote,
|
|
||||||
},
|
|
||||||
type: SCThingType.Message,
|
|
||||||
uid: 'foo',
|
|
||||||
};
|
|
||||||
await client.feedback(feedback);
|
|
||||||
|
|
||||||
expect(httpClient.request).to.have.been.first.called.with({
|
|
||||||
body: feedback,
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
method: feedbackRoute.method,
|
|
||||||
url: new URL('http://localhost' + feedbackRoute.getUrlFragment()),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +175,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: searchRoute.method,
|
method: searchRoute.method,
|
||||||
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +268,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: indexRoute.method,
|
method: indexRoute.method,
|
||||||
url: new URL('http://localhost' + indexRoute.getUrlFragment()),
|
url: new URL('http://localhost' + indexRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,6 +283,70 @@ export class ClientSpec {
|
|||||||
return client.handshake('bar.bar.dummy').should.be.rejectedWith(ApiError);
|
return client.handshake('bar.bar.dummy').should.be.rejectedWith(ApiError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async invokePlugin() {
|
||||||
|
sandbox.on(httpClient, 'request', async(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> => {
|
||||||
|
return {
|
||||||
|
body: {
|
||||||
|
app: {
|
||||||
|
features: {
|
||||||
|
plugins: {
|
||||||
|
"supportedPlugin": { urlPath: "/" }
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
statusCode: indexRoute.statusCodeSuccess,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(httpClient.request).not.to.have.been.first.called();
|
||||||
|
const client = new Client(httpClient, 'http://localhost');
|
||||||
|
|
||||||
|
await client.invokePlugin('unsupportedPlugin').should.be.rejectedWith(ApiError,/.*supportedPlugin.*/gmi);
|
||||||
|
|
||||||
|
// again with cached feature definitions
|
||||||
|
return client.invokePlugin('supportedPlugin')
|
||||||
|
.should.not.be.rejectedWith(ApiError,/.*supportedPlugin.*/gmi);
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async invokePluginUnavailable() {
|
||||||
|
sandbox.on(httpClient, 'request', async(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> => {
|
||||||
|
return {
|
||||||
|
body: {},
|
||||||
|
statusCode: indexRoute.statusCodeSuccess,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(httpClient.request).not.to.have.been.first.called();
|
||||||
|
|
||||||
|
const client = new Client(httpClient, 'http://localhost');
|
||||||
|
|
||||||
|
await client.invokePlugin('supportedPlugin').should.be.rejectedWith(ApiError,/.*supportedPlugin.*/gmi);
|
||||||
|
|
||||||
|
sandbox.restore();
|
||||||
|
sandbox.on(httpClient, 'request', async(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> => {
|
||||||
|
return {
|
||||||
|
body: {
|
||||||
|
app: {
|
||||||
|
features: {
|
||||||
|
plugins: {
|
||||||
|
'unsupportedPlugin': {
|
||||||
|
urlPath: '/unsupported-plugin'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
statusCode: indexRoute.statusCodeSuccess,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// again with cached feature definitions
|
||||||
|
return client.invokePlugin('supportedPlugin')
|
||||||
|
.should.be.rejectedWith(ApiError,/.*supportedPlugin.*/gmi);
|
||||||
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
async invokeRoute() {
|
async invokeRoute() {
|
||||||
sandbox.on(httpClient, 'request', invokeIndexRoute);
|
sandbox.on(httpClient, 'request', invokeIndexRoute);
|
||||||
@@ -350,7 +362,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: indexRoute.method,
|
method: indexRoute.method,
|
||||||
url: new URL('http://localhost' + indexRoute.getUrlFragment()),
|
url: new URL('http://localhost' + indexRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +423,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: multiSearchRoute.method,
|
method: multiSearchRoute.method,
|
||||||
url: new URL('http://localhost' + multiSearchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,7 +473,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: multiSearchRoute.method,
|
method: multiSearchRoute.method,
|
||||||
url: new URL('http://localhost' + multiSearchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
expect(httpClient.request).to.have.been.second.called.with({
|
expect(httpClient.request).to.have.been.second.called.with({
|
||||||
body: {foo: {size: 1000}, bar: {size: 500}, foobar: {size: 30}},
|
body: {foo: {size: 1000}, bar: {size: 500}, foobar: {size: 30}},
|
||||||
@@ -469,7 +481,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: multiSearchRoute.method,
|
method: multiSearchRoute.method,
|
||||||
url: new URL('http://localhost' + multiSearchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +544,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: searchRoute.method,
|
method: searchRoute.method,
|
||||||
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +582,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: searchRoute.method,
|
method: searchRoute.method,
|
||||||
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,7 +618,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: searchRoute.method,
|
method: searchRoute.method,
|
||||||
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
expect(httpClient.request).to.have.been.second.called.with({
|
expect(httpClient.request).to.have.been.second.called.with({
|
||||||
body: {size: 1000},
|
body: {size: 1000},
|
||||||
@@ -614,7 +626,7 @@ export class ClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: searchRoute.method,
|
method: searchRoute.method,
|
||||||
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
|
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import chai from 'chai';
|
|||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import chaiAsPromised from 'chai-as-promised';
|
import chaiAsPromised from 'chai-as-promised';
|
||||||
import chaiSpies from 'chai-spies';
|
import chaiSpies from 'chai-spies';
|
||||||
import clone = require('fast-clone');
|
import clone = require('rfdc');
|
||||||
import {readdir, readFile} from 'fs';
|
import {readdir, readFile} from 'fs';
|
||||||
import {suite, test} from '@testdeck/mocha';
|
import {suite, test} from '@testdeck/mocha';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
@@ -113,7 +113,7 @@ export class ConnectorClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: bulkRoute.method,
|
method: bulkRoute.method,
|
||||||
url: new URL('http://localhost' + bulkRoute.getUrlFragment()),
|
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ export class ConnectorClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: bulkRoute.method,
|
method: bulkRoute.method,
|
||||||
url: new URL('http://localhost' + bulkRoute.getUrlFragment()),
|
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ export class ConnectorClientSpec {
|
|||||||
|
|
||||||
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
||||||
: Promise<HttpClientResponse<responses>> => {
|
: Promise<HttpClientResponse<responses>> => {
|
||||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlFragment()).toString()) {
|
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
expiration: moment().add(3600, 'seconds').format(),
|
expiration: moment().add(3600, 'seconds').format(),
|
||||||
@@ -207,7 +207,7 @@ export class ConnectorClientSpec {
|
|||||||
headers: {},
|
headers: {},
|
||||||
statusCode: bulkRoute.statusCodeSuccess,
|
statusCode: bulkRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlFragment({
|
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlPath({
|
||||||
UID: 'foo',
|
UID: 'foo',
|
||||||
})).toString()) {
|
})).toString()) {
|
||||||
return {
|
return {
|
||||||
@@ -237,7 +237,7 @@ export class ConnectorClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: bulkRoute.method,
|
method: bulkRoute.method,
|
||||||
url: new URL('http://localhost' + bulkRoute.getUrlFragment()),
|
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ export class ConnectorClientSpec {
|
|||||||
|
|
||||||
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
||||||
: Promise<HttpClientResponse<responses>> => {
|
: Promise<HttpClientResponse<responses>> => {
|
||||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlFragment()).toString()) {
|
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
expiration: moment().add(3600, 'seconds').format(),
|
expiration: moment().add(3600, 'seconds').format(),
|
||||||
@@ -302,7 +302,7 @@ export class ConnectorClientSpec {
|
|||||||
headers: {},
|
headers: {},
|
||||||
statusCode: bulkRoute.statusCodeSuccess,
|
statusCode: bulkRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlFragment({
|
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlPath({
|
||||||
UID: 'foo',
|
UID: 'foo',
|
||||||
})).toString()) {
|
})).toString()) {
|
||||||
return {
|
return {
|
||||||
@@ -332,7 +332,7 @@ export class ConnectorClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: bulkRoute.method,
|
method: bulkRoute.method,
|
||||||
url: new URL('http://localhost' + bulkRoute.getUrlFragment()),
|
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ export class ConnectorClientSpec {
|
|||||||
|
|
||||||
for (const testInstance of testInstances) {
|
for (const testInstance of testInstances) {
|
||||||
|
|
||||||
const checkInstance = clone(testInstance);
|
const checkInstance = clone()(testInstance);
|
||||||
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
||||||
|
|
||||||
expect(doesContainThings(testInstanceWithoutReferences)).to.be
|
expect(doesContainThings(testInstanceWithoutReferences)).to.be
|
||||||
@@ -457,7 +457,7 @@ export class ConnectorClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: thingUpdateRoute.method,
|
method: thingUpdateRoute.method,
|
||||||
url: new URL('http://localhost' + thingUpdateRoute.getUrlFragment({
|
url: new URL('http://localhost' + thingUpdateRoute.getUrlPath({
|
||||||
TYPE: SCThingType.Message,
|
TYPE: SCThingType.Message,
|
||||||
UID: 'foo',
|
UID: 'foo',
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export class CopySpec {
|
|||||||
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
|
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
|
||||||
|
|
||||||
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||||
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlFragment().toString()) {
|
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlPath().toString()) {
|
||||||
const body = request.body as SCSearchRequest;
|
const body = request.body as SCSearchRequest;
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@@ -92,7 +92,7 @@ export class CopySpec {
|
|||||||
},
|
},
|
||||||
statusCode: searchRoute.statusCodeSuccess,
|
statusCode: searchRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlFragment().toString()) {
|
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
state: 'in progress',
|
state: 'in progress',
|
||||||
@@ -100,7 +100,7 @@ export class CopySpec {
|
|||||||
},
|
},
|
||||||
statusCode: bulkRoute.statusCodeSuccess,
|
statusCode: bulkRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlFragment({
|
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
|
||||||
UID: 'foo',
|
UID: 'foo',
|
||||||
}).toString()) {
|
}).toString()) {
|
||||||
return {
|
return {
|
||||||
@@ -130,7 +130,7 @@ export class CopySpec {
|
|||||||
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
|
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
|
||||||
|
|
||||||
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||||
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlFragment().toString()) {
|
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlPath().toString()) {
|
||||||
const body = request.body as SCSearchRequest;
|
const body = request.body as SCSearchRequest;
|
||||||
|
|
||||||
if (typeof body.size === 'number' && body.size > 0) {
|
if (typeof body.size === 'number' && body.size > 0) {
|
||||||
@@ -163,7 +163,7 @@ export class CopySpec {
|
|||||||
},
|
},
|
||||||
statusCode: searchRoute.statusCodeSuccess,
|
statusCode: searchRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlFragment().toString()) {
|
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
state: 'in progress',
|
state: 'in progress',
|
||||||
@@ -171,7 +171,7 @@ export class CopySpec {
|
|||||||
},
|
},
|
||||||
statusCode: bulkRoute.statusCodeSuccess,
|
statusCode: bulkRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlFragment({
|
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
|
||||||
UID: 'foo',
|
UID: 'foo',
|
||||||
}).toString()) {
|
}).toString()) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ import {
|
|||||||
SCBulkRoute,
|
SCBulkRoute,
|
||||||
SCSearchResponse,
|
SCSearchResponse,
|
||||||
SCSearchRoute,
|
SCSearchRoute,
|
||||||
SCThing,
|
|
||||||
SCThings,
|
SCThings,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
import chaiAsPromised from 'chai-as-promised';
|
import chaiAsPromised from 'chai-as-promised';
|
||||||
import chaiSpies from 'chai-spies';
|
import chaiSpies from 'chai-spies';
|
||||||
import clone = require('fast-clone');
|
import clone = require('rfdc');
|
||||||
import {existsSync, mkdirSync, rmdirSync, unlinkSync} from 'fs';
|
import {existsSync, mkdirSync, rmdirSync, unlinkSync} from 'fs';
|
||||||
import {createFileSync} from 'fs-extra';
|
import {createFileSync} from 'fs-extra';
|
||||||
import {suite, test} from '@testdeck/mocha';
|
import {suite, test} from '@testdeck/mocha';
|
||||||
@@ -66,18 +65,12 @@ export class E2EConnectorSpec {
|
|||||||
async getCoreTestSamples() {
|
async getCoreTestSamples() {
|
||||||
const items = await getItemsFromSamples('./node_modules/@openstapps/core/test/resources');
|
const items = await getItemsFromSamples('./node_modules/@openstapps/core/test/resources');
|
||||||
// tslint:disable-next-line: no-unused-expression
|
// tslint:disable-next-line: no-unused-expression
|
||||||
chai.expect(items).to.not.be.a.instanceof(Error);
|
|
||||||
// tslint:disable-next-line: no-unused-expression
|
|
||||||
chai.expect(items).to.not.be.empty;
|
chai.expect(items).to.not.be.empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
async getCoreTestSamplesShouldFail() {
|
async getCoreTestSamplesShouldFail() {
|
||||||
return getItemsFromSamples('./nonexistantdirectory')
|
await chai.expect(getItemsFromSamples('./nonexistantdirectory')).to.be.rejectedWith(Error);
|
||||||
.then(<T extends SCThing>(items: T[]) => {
|
|
||||||
// tslint:disable-next-line: no-unused-expression
|
|
||||||
chai.expect(items).to.be.a.instanceof(Error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
@@ -88,7 +81,7 @@ export class E2EConnectorSpec {
|
|||||||
let failOnLookup = false;
|
let failOnLookup = false;
|
||||||
|
|
||||||
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||||
if (request.url.toString() === `http://localhost${bulkRoute.getUrlFragment().toString()}`) {
|
if (request.url.toString() === `http://localhost${bulkRoute.getUrlPath().toString()}`) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
@@ -99,8 +92,8 @@ export class E2EConnectorSpec {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.url.toString() === `http://localhost${bulkAddRoute.getUrlFragment({UID: 'foo'}).toString()}`) {
|
if (request.url.toString() === `http://localhost${bulkAddRoute.getUrlPath({UID: 'foo'}).toString()}`) {
|
||||||
storedThings.set(request.body.uid, clone(request.body));
|
storedThings.set(request.body.uid, clone()(request.body));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
body: {},
|
body: {},
|
||||||
@@ -108,14 +101,14 @@ export class E2EConnectorSpec {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.url.toString() === `http://localhost${bulkDoneRoute.getUrlFragment({UID: 'foo'}).toString()}`) {
|
if (request.url.toString() === `http://localhost${bulkDoneRoute.getUrlPath({UID: 'foo'}).toString()}`) {
|
||||||
return {
|
return {
|
||||||
body: {},
|
body: {},
|
||||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.url.toString() === `http://localhost${searchRoute.getUrlFragment().toString()}`) {
|
if (request.url.toString() === `http://localhost${searchRoute.getUrlPath().toString()}`) {
|
||||||
const thing = storedThings.get(request.body.filter.arguments.value);
|
const thing = storedThings.get(request.body.filter.arguments.value);
|
||||||
if (failOnCompare) {
|
if (failOnCompare) {
|
||||||
thing!.origin!.modified = 'altered';
|
thing!.origin!.modified = 'altered';
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export class PluginClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: pluginRegisterRoute.method,
|
method: pluginRegisterRoute.method,
|
||||||
url: new URL(`http://localhost${pluginRegisterRoute.getUrlFragment()}`),
|
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ export class PluginClientSpec {
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
method: pluginRegisterRoute.method,
|
method: pluginRegisterRoute.method,
|
||||||
url: new URL(`http://localhost${pluginRegisterRoute.getUrlFragment()}`),
|
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user