Compare commits

...

37 Commits

Author SHA1 Message Date
Rainer Killinger
0dc3792fb9 0.41.1 2022-05-27 17:13:55 +02:00
Rainer Killinger
223b5ee5c0 refactor: update dependencies 2022-05-27 17:13:23 +02:00
Jovan Krunić
a65cfc1176 docs: update changelog 2022-05-17 21:02:57 +02:00
Jovan Krunić
f54d04f94d 0.41.0 2022-05-17 21:02:56 +02:00
openstappsbot
315e15f53d refactor: update all 2022-05-17 13:07:17 +00:00
Rainer Killinger
d2fe89ec3a docs: update changelog 2022-04-04 21:37:18 +02:00
Rainer Killinger
0d3248fff0 0.40.0 2022-04-04 21:37:17 +02:00
Rainer Killinger
1748ba3825 refactor: update dependencies 2022-04-04 21:33:14 +02:00
Rainer Killinger
8962da31a3 docs: update changelog 2022-03-17 12:26:48 +01:00
Rainer Killinger
de8033c218 0.39.0 2022-03-17 12:26:42 +01:00
Rainer Killinger
cb9dd83bef refactor: update dependencies 2022-03-17 12:08:37 +01:00
Rainer Killinger
6257ca0dd3 docs: update changelog 2022-01-25 12:44:22 +01:00
Rainer Killinger
6a87557109 0.38.0 2022-01-25 12:44:16 +01:00
Rainer Killinger
83120a6734 feat: add client method for invoking plugin routes 2022-01-24 15:52:12 +01:00
Rainer Killinger
d601880be1 refactor: update dependencies 2022-01-24 15:51:40 +01:00
Rainer Killinger
8615203a3e docs: update changelog 2021-12-17 10:48:56 +01:00
Rainer Killinger
3a5ee64db5 0.37.0 2021-12-17 10:48:54 +01:00
Rainer Killinger
bfe3faa01c refactor: update dependencies 2021-12-17 10:48:18 +01:00
Rainer Killinger
8b98b8afdc docs: update changelog 2021-12-15 16:20:09 +01:00
Rainer Killinger
7a01a6b305 0.36.0 2021-12-15 16:20:08 +01:00
Rainer Killinger
bc2274a9ef refactor: update dependencies 2021-12-15 16:14:55 +01:00
Jovan Krunić
0becdeb6d9 docs: update changelog 2021-10-20 14:10:03 +02:00
Jovan Krunić
dacb1c66e8 0.35.0 2021-10-20 14:10:00 +02:00
openstappsbot
e187ee8c44 refactor: update all 2021-10-20 11:27:10 +00:00
Rainer Killinger
c9f37a1df0 docs: update changelog 2021-10-04 18:07:57 +02:00
Rainer Killinger
6dd5fcdde5 0.34.0 2021-10-04 18:07:52 +02:00
openstappsbot
26c14fa7e9 refactor: update all 2021-10-04 17:53:15 +02:00
openstappsbot
8cb4ee12a6 refactor: update all 2021-10-04 07:07:31 +00:00
openstappsbot
a09359d0b2 refactor: update all 2021-09-27 07:06:56 +00:00
Rainer Killinger
bf3a716767 docs: update changelog 2021-09-16 12:09:17 +02:00
Rainer Killinger
1b3c43d2cb 0.33.0 2021-09-16 12:09:16 +02:00
Rainer Killinger
fee9a163e1 docs: adjust typedoc arguments 2021-09-16 12:08:33 +02:00
openstappsbot
472a1b97d6 refactor: update all 2021-09-15 13:06:45 +00:00
Rainer Killinger
227abeb36d docs: update changelog 2021-09-01 15:45:14 +02:00
Rainer Killinger
be1fef2e25 0.32.0 2021-09-01 15:45:10 +02:00
openstappsbot
587c98a50e refactor: update all 2021-09-01 13:06:57 +00:00
Rainer Killinger
c685adcac6 docs: update changelog 2021-08-27 14:42:52 +02:00
16 changed files with 2029 additions and 1704 deletions

View File

@@ -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)

View File

@@ -64,4 +64,4 @@ Or using `e2e` command:
```shell
docker run --net=host registry.gitlab.com/openstapps/api/cli e2e http://localhost:3000
```
```

3298
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,12 @@
{
"name": "@openstapps/api",
"version": "0.31.1",
"version": "0.41.1",
"scripts": {
"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'",
"check-configuration": "openstapps-configuration",
"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",
"prepublishOnly": "npm ci && npm run build",
"preversion": "npm run prepublishOnly",
@@ -16,53 +16,54 @@
},
"description": "Node.js library to interact with the StApps backend service",
"dependencies": {
"@krlwlfrt/async-pool": "0.5.0",
"@openstapps/core": "0.49.3",
"@openstapps/core-tools": "0.24.3",
"@openstapps/logger": "0.7.0",
"@types/cli-progress": "3.9.2",
"@krlwlfrt/async-pool": "0.7.0",
"@openstapps/core": "0.66.1",
"@openstapps/core-tools": "0.30.1",
"@openstapps/logger": "0.8.1",
"@types/cli-progress": "3.11.0",
"@types/express": "4.17.13",
"@types/morgan": "1.9.3",
"@types/node": "14.17.12",
"@types/node": "14.18.18",
"@types/traverse": "0.6.32",
"@types/uuid": "8.3.1",
"@types/uuid": "8.3.4",
"@types/wait-on": "5.3.1",
"body-parser": "1.19.0",
"cli-progress": "3.9.0",
"commander": "7.2.0",
"express": "4.17.1",
"fast-clone": "1.5.13",
"got": "11.8.2",
"json-schema": "0.3.0",
"moment": "2.29.1",
"body-parser": "1.20.0",
"cli-progress": "3.11.1",
"commander": "9.2.0",
"express": "4.18.1",
"got": "11.8.3",
"json-schema": "0.4.0",
"moment": "2.29.3",
"morgan": "1.10.0",
"rfdc": "1.3.0",
"traverse": "0.6.6",
"uuid": "8.3.2",
"wait-on": "5.3.0"
"wait-on": "6.0.1"
},
"license": "GPL-3.0-only",
"devDependencies": {
"@openstapps/configuration": "0.27.0",
"@testdeck/mocha": "0.1.2",
"@types/chai": "4.2.21",
"@types/chai-as-promised": "7.1.4",
"@openstapps/configuration": "0.29.1",
"@testdeck/mocha": "0.2.0",
"@types/chai": "4.3.1",
"@types/chai-as-promised": "7.1.5",
"@types/chai-spies": "1.0.3",
"@types/fs-extra": "9.0.12",
"@types/mocha": "8.2.3",
"chai": "4.3.4",
"@types/fs-extra": "9.0.13",
"@types/json-schema": "7.0.11",
"@types/mocha": "9.1.1",
"chai": "4.3.6",
"chai-as-promised": "7.1.1",
"chai-spies": "1.0.0",
"conventional-changelog-cli": "2.1.1",
"fs-extra": "9.1.0",
"mocha": "8.4.0",
"nock": "13.1.3",
"conventional-changelog-cli": "2.2.2",
"fs-extra": "10.1.0",
"mocha": "10.0.0",
"nock": "13.2.4",
"nyc": "15.1.0",
"prepend-file-cli": "1.0.6",
"rimraf": "3.0.2",
"ts-node": "9.1.1",
"ts-node": "10.8.0",
"tslint": "6.1.3",
"typedoc": "0.18.0",
"typescript": "3.8.3"
"typedoc": "0.22.15",
"typescript": "3.9.10"
},
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
"contributors": [
@@ -75,7 +76,7 @@
"Wieland Schöbl <wulkanat@gmail.com>"
],
"peerDependencies": {
"@openstapps/core": "~0.49.0"
"@openstapps/core": "~0.66.0"
},
"repository": {
"type": "git",

View File

@@ -42,7 +42,7 @@ commander
.command('e2e <to>')
.version(pkgJson.version)
.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"')
.action(async (to, e2eCommand) => {
let toURL = '';

View File

@@ -15,9 +15,8 @@
import {
SCAbstractRoute,
SCErrorResponse,
SCFeedbackRequest,
SCFeedbackResponse,
SCFeedbackRoute,
SCFeatureConfiguration,
SCFeatureConfigurationPlugin,
SCIndexRequest,
SCIndexResponse,
SCIndexRoute,
@@ -32,17 +31,13 @@ import {
SCSearchRoute,
SCThings,
} from '@openstapps/core';
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError} from './errors';
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError, PluginNotAvailableError} from './errors';
import {HttpClientHeaders, HttpClientInterface} from './http-client-interface';
/**
* StApps-API client
*/
export class Client {
/**
* Instance of feedback request route
*/
private readonly feedbackRoute = new SCFeedbackRoute();
/**
* Instance of index route
@@ -59,6 +54,11 @@ export class Client {
*/
private readonly searchRoute = new SCSearchRoute();
/**
* Features supported by backend
*/
private supportedFeatures?: SCFeatureConfiguration = undefined;
/**
* 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
*
@@ -157,10 +148,42 @@ export class Client {
if (response.backend.SCVersion.split('.')[0] !== coreVersion.split('.')[0]) {
throw new CoreVersionIncompatibleError(coreVersion, response.backend.SCVersion);
}
/* istanbul ignore next */
this.supportedFeatures = response?.app?.features;
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
*
@@ -177,7 +200,7 @@ export class Client {
// TODO: remove headers
headers: this.headers,
method: route.method,
url: new URL(this.url + route.getUrlFragment(parameters)),
url: new URL(this.url + route.getUrlPath(parameters)),
});
if (response.statusCode === route.statusCodeSuccess) {

View File

@@ -25,8 +25,8 @@ import {
SCThingUpdateResponse,
SCThingUpdateRoute,
} from '@openstapps/core';
import clone = require('fast-clone');
import moment from 'moment';
import clone = require('rfdc');
import {v5} from 'uuid';
import {Bulk} from './bulk';
import {Client} from './client';
@@ -82,7 +82,7 @@ export class ConnectorClient extends Client {
static removeReferences<THING extends SCThings>(thing: THING): SCAssociatedThingWithoutReferences<THING> {
// tslint:disable-next-line:no-any
const thingWithoutReferences = clone<any>(thing);
const thingWithoutReferences = clone()<any>(thing);
delete thingWithoutReferences.origin;

View File

@@ -103,15 +103,14 @@ function compareItems() {
* Function to add all the SCThings that getItemsFromSamples() returns to the backend
*/
async function indexSamples(api: ConnectorClient, options: E2EOptions): Promise<void> {
const items = await getItemsFromSamples(options.samplesLocation);
if (items.length === 0) {
throw new Error('Could not index samples. None were retrieved from the file system.');
}
try {
// sort items by type
const items = await getItemsFromSamples(options.samplesLocation);
if (items.length === 0) {
throw new Error('Could not index samples. None were retrieved from the file system.');
}
// sort items by type
const itemMap: Map<SCThingType, SCThings[]> = new Map();
for (const item of items) {
if (!itemMap.has(item.type)) {
@@ -155,7 +154,7 @@ export async function getItemsFromSamples<T extends SCThings>(samplesDirectory:
}
}
} catch (error) {
return error;
throw error;
}
return things;

View File

@@ -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',
});
}
}

View File

@@ -73,11 +73,13 @@ export class HttpClient {
try {
response = await got(requestConfig.url.toString(), params);
} catch (err) {
if (typeof err.response === 'undefined') {
// tslint:disable-next-line: no-any
if (typeof (err as any).response === 'undefined') {
throw err;
}
// 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;

View File

@@ -208,7 +208,7 @@ export abstract class Plugin {
* @param req An express Request from the backend
* @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
@@ -222,9 +222,9 @@ export abstract class Plugin {
/* istanbul ignore next */
if (typeof err !== 'undefined') {
/* istanbul ignore next */
return reject(err);
reject(err);
}
resolve();
resolve(undefined);
});
});
}

View File

@@ -13,9 +13,6 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {
SCFeedbackRequest,
SCFeedbackResponse,
SCFeedbackRoute,
SCIndexResponse,
SCIndexRoute,
SCMessage,
@@ -44,7 +41,6 @@ chai.use(chaiAsPromised);
const sandbox = chai.spy.sandbox();
const indexRoute = new SCIndexRoute();
const feedbackRoute = new SCFeedbackRoute();
const multiSearchRoute = new SCMultiSearchRoute();
const searchRoute = new SCSearchRoute();
@@ -65,6 +61,9 @@ export type RecursivePartial<T> = {
async function invokeIndexRoute(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> {
return {
body: {
app: {
features: {},
},
backend: {
SCVersion: 'foo.bar.dummy',
},
@@ -113,58 +112,7 @@ export class ClientSpec {
'X-StApps-Version': 'foo.foo.foo',
},
method: indexRoute.method,
url: new URL('http://localhost' + indexRoute.getUrlFragment()),
});
}
@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()),
url: new URL('http://localhost' + indexRoute.getUrlPath()),
});
}
@@ -227,7 +175,7 @@ export class ClientSpec {
"Content-Type": "application/json",
},
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",
},
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);
}
@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
async invokeRoute() {
sandbox.on(httpClient, 'request', invokeIndexRoute);
@@ -350,7 +362,7 @@ export class ClientSpec {
"Content-Type": "application/json",
},
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",
},
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",
},
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({
body: {foo: {size: 1000}, bar: {size: 500}, foobar: {size: 30}},
@@ -469,7 +481,7 @@ export class ClientSpec {
"Content-Type": "application/json",
},
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",
},
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",
},
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",
},
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({
body: {size: 1000},
@@ -614,7 +626,7 @@ export class ClientSpec {
"Content-Type": "application/json",
},
method: searchRoute.method,
url: new URL('http://localhost' + searchRoute.getUrlFragment()),
url: new URL('http://localhost' + searchRoute.getUrlPath()),
});
}
}

View File

@@ -32,7 +32,7 @@ import chai from 'chai';
import {expect} from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import clone = require('fast-clone');
import clone = require('rfdc');
import {readdir, readFile} from 'fs';
import {suite, test} from '@testdeck/mocha';
import moment from 'moment';
@@ -113,7 +113,7 @@ export class ConnectorClientSpec {
"Content-Type": "application/json",
},
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",
},
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)
: 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 {
body: {
expiration: moment().add(3600, 'seconds').format(),
@@ -207,7 +207,7 @@ export class ConnectorClientSpec {
headers: {},
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',
})).toString()) {
return {
@@ -237,7 +237,7 @@ export class ConnectorClientSpec {
"Content-Type": "application/json",
},
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)
: 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 {
body: {
expiration: moment().add(3600, 'seconds').format(),
@@ -302,7 +302,7 @@ export class ConnectorClientSpec {
headers: {},
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',
})).toString()) {
return {
@@ -332,7 +332,7 @@ export class ConnectorClientSpec {
"Content-Type": "application/json",
},
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) {
const checkInstance = clone(testInstance);
const checkInstance = clone()(testInstance);
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
expect(doesContainThings(testInstanceWithoutReferences)).to.be
@@ -457,7 +457,7 @@ export class ConnectorClientSpec {
"Content-Type": "application/json",
},
method: thingUpdateRoute.method,
url: new URL('http://localhost' + thingUpdateRoute.getUrlFragment({
url: new URL('http://localhost' + thingUpdateRoute.getUrlPath({
TYPE: SCThingType.Message,
UID: 'foo',
})),

View File

@@ -58,7 +58,7 @@ export class CopySpec {
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
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;
let count = 0;
@@ -92,7 +92,7 @@ export class CopySpec {
},
statusCode: searchRoute.statusCodeSuccess,
};
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlFragment().toString()) {
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
return {
body: {
state: 'in progress',
@@ -100,7 +100,7 @@ export class CopySpec {
},
statusCode: bulkRoute.statusCodeSuccess,
};
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlFragment({
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
UID: 'foo',
}).toString()) {
return {
@@ -130,7 +130,7 @@ export class CopySpec {
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
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;
if (typeof body.size === 'number' && body.size > 0) {
@@ -163,7 +163,7 @@ export class CopySpec {
},
statusCode: searchRoute.statusCodeSuccess,
};
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlFragment().toString()) {
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
return {
body: {
state: 'in progress',
@@ -171,7 +171,7 @@ export class CopySpec {
},
statusCode: bulkRoute.statusCodeSuccess,
};
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlFragment({
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
UID: 'foo',
}).toString()) {
return {

View File

@@ -24,13 +24,12 @@ import {
SCBulkRoute,
SCSearchResponse,
SCSearchRoute,
SCThing,
SCThings,
} from '@openstapps/core';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import clone = require('fast-clone');
import clone = require('rfdc');
import {existsSync, mkdirSync, rmdirSync, unlinkSync} from 'fs';
import {createFileSync} from 'fs-extra';
import {suite, test} from '@testdeck/mocha';
@@ -66,18 +65,12 @@ export class E2EConnectorSpec {
async getCoreTestSamples() {
const items = await getItemsFromSamples('./node_modules/@openstapps/core/test/resources');
// 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;
}
@test
async getCoreTestSamplesShouldFail() {
return getItemsFromSamples('./nonexistantdirectory')
.then(<T extends SCThing>(items: T[]) => {
// tslint:disable-next-line: no-unused-expression
chai.expect(items).to.be.a.instanceof(Error);
});
await chai.expect(getItemsFromSamples('./nonexistantdirectory')).to.be.rejectedWith(Error);
}
@test
@@ -88,7 +81,7 @@ export class E2EConnectorSpec {
let failOnLookup = false;
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 {
body: {
@@ -99,8 +92,8 @@ export class E2EConnectorSpec {
};
}
if (request.url.toString() === `http://localhost${bulkAddRoute.getUrlFragment({UID: 'foo'}).toString()}`) {
storedThings.set(request.body.uid, clone(request.body));
if (request.url.toString() === `http://localhost${bulkAddRoute.getUrlPath({UID: 'foo'}).toString()}`) {
storedThings.set(request.body.uid, clone()(request.body));
return {
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 {
body: {},
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);
if (failOnCompare) {
thing!.origin!.modified = 'altered';

View File

@@ -81,7 +81,7 @@ export class PluginClientSpec {
"Content-Type": "application/json",
},
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",
},
method: pluginRegisterRoute.method,
url: new URL(`http://localhost${pluginRegisterRoute.getUrlFragment()}`),
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
});
}
}