mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-11 12:12:55 +00:00
refactor: build system
This commit is contained in:
@@ -12,7 +12,14 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCBulkAddRoute, SCBulkDoneRoute, SCDish, SCMessage, SCThingOriginType, SCThingType} from '@openstapps/core';
|
||||
import {
|
||||
SCBulkAddRoute,
|
||||
SCBulkDoneRoute,
|
||||
SCDish,
|
||||
SCMessage,
|
||||
SCThingOriginType,
|
||||
SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import chai from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
@@ -55,9 +62,7 @@ export class BulkSpec {
|
||||
});
|
||||
|
||||
const dish: SCDish = {
|
||||
categories: [
|
||||
'main dish',
|
||||
],
|
||||
categories: ['main dish'],
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
indexed: moment().format(),
|
||||
@@ -70,9 +75,13 @@ export class BulkSpec {
|
||||
|
||||
await bulk.add(dish);
|
||||
|
||||
expect(client.invokeRoute).to.have.been.first.called.with(bulkAddRoute, {
|
||||
UID: 'bar',
|
||||
}, dish);
|
||||
expect(client.invokeRoute).to.have.been.first.called.with(
|
||||
bulkAddRoute,
|
||||
{
|
||||
UID: 'bar',
|
||||
},
|
||||
dish,
|
||||
);
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -86,12 +95,8 @@ export class BulkSpec {
|
||||
});
|
||||
|
||||
const message: SCMessage = {
|
||||
audiences: [
|
||||
'students',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['students'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
|
||||
@@ -52,10 +52,11 @@ const httpClient = new HttpClient();
|
||||
* @see https://stackoverflow.com/a/51365037
|
||||
*/
|
||||
export type RecursivePartial<T> = {
|
||||
[P in keyof T]?:
|
||||
T[P] extends Array<(infer U)> ? Array<RecursivePartial<U>> :
|
||||
T[P] extends object ? RecursivePartial<T[P]> :
|
||||
T[P];
|
||||
[P in keyof T]?: T[P] extends Array<infer U>
|
||||
? Array<RecursivePartial<U>>
|
||||
: T[P] extends object
|
||||
? RecursivePartial<T[P]>
|
||||
: T[P];
|
||||
};
|
||||
|
||||
async function invokeIndexRoute(): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> {
|
||||
@@ -119,12 +120,8 @@ export class ClientSpec {
|
||||
@test
|
||||
async getThing() {
|
||||
const message: SCMessage = {
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -172,7 +169,7 @@ export class ClientSpec {
|
||||
size: 1,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: searchRoute.method,
|
||||
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||
@@ -210,12 +207,8 @@ export class ClientSpec {
|
||||
@test
|
||||
async getThingFailsByUid() {
|
||||
const message: SCMessage = {
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -265,7 +258,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: indexRoute.method,
|
||||
url: new URL('http://localhost' + indexRoute.getUrlPath()),
|
||||
@@ -285,66 +278,78 @@ export class ClientSpec {
|
||||
|
||||
@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'
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (): Promise<RecursivePartial<HttpClientResponse<SCIndexResponse>>> => {
|
||||
return {
|
||||
body: {
|
||||
app: {
|
||||
features: {
|
||||
plugins: {
|
||||
supportedPlugin: {urlPath: '/'},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
statusCode: indexRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
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.*/gim);
|
||||
|
||||
// again with cached feature definitions
|
||||
return client.invokePlugin('supportedPlugin')
|
||||
.should.be.rejectedWith(ApiError,/.*supportedPlugin.*/gmi);
|
||||
return client
|
||||
.invokePlugin('supportedPlugin')
|
||||
.should.not.be.rejectedWith(ApiError, /.*supportedPlugin.*/gim);
|
||||
}
|
||||
|
||||
@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.*/gim);
|
||||
|
||||
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.*/gim);
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -359,7 +364,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: undefined,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: indexRoute.method,
|
||||
url: new URL('http://localhost' + indexRoute.getUrlPath()),
|
||||
@@ -420,7 +425,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {a: {size: 1}, b: {size: 1}},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: multiSearchRoute.method,
|
||||
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||
@@ -470,7 +475,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {foo: {size: 0}, bar: {size: 0}},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: multiSearchRoute.method,
|
||||
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||
@@ -478,7 +483,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.second.called.with({
|
||||
body: {foo: {size: 1000}, bar: {size: 500}, foobar: {size: 30}},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: multiSearchRoute.method,
|
||||
url: new URL('http://localhost' + multiSearchRoute.getUrlPath()),
|
||||
@@ -541,7 +546,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {size: 1},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: searchRoute.method,
|
||||
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||
@@ -579,7 +584,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {from: 30, size: 30},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: searchRoute.method,
|
||||
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||
@@ -615,7 +620,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: {size: 0},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: searchRoute.method,
|
||||
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||
@@ -623,7 +628,7 @@ export class ClientSpec {
|
||||
expect(httpClient.request).to.have.been.second.called.with({
|
||||
body: {size: 1000},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: searchRoute.method,
|
||||
url: new URL('http://localhost' + searchRoute.getUrlPath()),
|
||||
|
||||
@@ -72,7 +72,7 @@ function doesContainThings<T extends SCThingWithoutReferences>(thing: T): boolea
|
||||
return false;
|
||||
}
|
||||
|
||||
return sum || (item === null) ? false : isThing(item);
|
||||
return sum || item === null ? false : isThing(item);
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export class ConnectorClientSpec {
|
||||
type: SCThingType.Message,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: bulkRoute.method,
|
||||
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||
@@ -145,7 +145,7 @@ export class ConnectorClientSpec {
|
||||
type: SCThingType.Message,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: bulkRoute.method,
|
||||
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||
@@ -156,12 +156,8 @@ export class ConnectorClientSpec {
|
||||
async index() {
|
||||
const messages: SCMessage[] = [
|
||||
{
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -173,12 +169,8 @@ export class ConnectorClientSpec {
|
||||
uid: 'foo',
|
||||
},
|
||||
{
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -193,36 +185,45 @@ export class ConnectorClientSpec {
|
||||
|
||||
type responses = SCBulkResponse | SCBulkAddResponse | SCBulkDoneResponse;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
||||
: Promise<HttpClientResponse<responses>> => {
|
||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||
return {
|
||||
body: {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
source: 'copy',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Message,
|
||||
uid: 'foo',
|
||||
},
|
||||
headers: {},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
})).toString()) {
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (request: HttpClientRequest): Promise<HttpClientResponse<responses>> => {
|
||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||
return {
|
||||
body: {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
source: 'copy',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Message,
|
||||
uid: 'foo',
|
||||
},
|
||||
headers: {},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (
|
||||
request.url.toString() ===
|
||||
new URL(
|
||||
'http://localhost' +
|
||||
bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
}),
|
||||
).toString()
|
||||
) {
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
const connectorClient = new ConnectorClient(httpClient, 'http://localhost');
|
||||
await connectorClient.index(messages, 'copy');
|
||||
@@ -234,7 +235,7 @@ export class ConnectorClientSpec {
|
||||
type: SCThingType.Message,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: bulkRoute.method,
|
||||
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||
@@ -251,12 +252,8 @@ export class ConnectorClientSpec {
|
||||
async indexWithoutSource() {
|
||||
const messages: SCMessage[] = [
|
||||
{
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -268,12 +265,8 @@ export class ConnectorClientSpec {
|
||||
uid: 'foo',
|
||||
},
|
||||
{
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -288,36 +281,45 @@ export class ConnectorClientSpec {
|
||||
|
||||
type responses = SCBulkResponse | SCBulkAddResponse | SCBulkDoneResponse;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (request: HttpClientRequest)
|
||||
: Promise<HttpClientResponse<responses>> => {
|
||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||
return {
|
||||
body: {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
source: 'stapps-api',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Message,
|
||||
uid: 'foo',
|
||||
},
|
||||
headers: {},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === new URL('http://localhost' + bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
})).toString()) {
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (request: HttpClientRequest): Promise<HttpClientResponse<responses>> => {
|
||||
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
|
||||
return {
|
||||
body: {
|
||||
expiration: moment().add(3600, 'seconds').format(),
|
||||
source: 'stapps-api',
|
||||
state: 'in progress',
|
||||
type: SCThingType.Message,
|
||||
uid: 'foo',
|
||||
},
|
||||
headers: {},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (
|
||||
request.url.toString() ===
|
||||
new URL(
|
||||
'http://localhost' +
|
||||
bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
}),
|
||||
).toString()
|
||||
) {
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
headers: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
const connectorClient = new ConnectorClient(httpClient, 'http://localhost');
|
||||
await connectorClient.index(messages);
|
||||
@@ -329,7 +331,7 @@ export class ConnectorClientSpec {
|
||||
type: SCThingType.Message,
|
||||
},
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: bulkRoute.method,
|
||||
url: new URL('http://localhost' + bulkRoute.getUrlPath()),
|
||||
@@ -362,12 +364,12 @@ export class ConnectorClientSpec {
|
||||
'core',
|
||||
'test',
|
||||
'resources',
|
||||
'indexable'
|
||||
'indexable',
|
||||
);
|
||||
|
||||
const testFiles = await readdirPromisified(pathToTestFiles);
|
||||
|
||||
const testInstances = await asyncPool(5, testFiles, async (testFile) => {
|
||||
const testInstances = await asyncPool(5, testFiles, async testFile => {
|
||||
const buffer = await readFilePromisified(join(pathToTestFiles, testFile));
|
||||
const content = JSON.parse(buffer.toString());
|
||||
|
||||
@@ -375,58 +377,53 @@ export class ConnectorClientSpec {
|
||||
});
|
||||
|
||||
for (const testInstance of testInstances) {
|
||||
|
||||
const checkInstance = clone()(testInstance);
|
||||
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
||||
|
||||
expect(doesContainThings(testInstanceWithoutReferences)).to.be
|
||||
.equal(false, JSON.stringify(
|
||||
[testInstance, testInstanceWithoutReferences],
|
||||
null,
|
||||
2,
|
||||
));
|
||||
expect((testInstanceWithoutReferences as any).origin).to.be
|
||||
.equal(undefined, JSON.stringify(
|
||||
[testInstance, testInstanceWithoutReferences],
|
||||
null,
|
||||
2,
|
||||
));
|
||||
expect(testInstance).to.be.deep
|
||||
.equal(checkInstance,
|
||||
'Removing the references of a thing could have side effects because no deep copy is used');
|
||||
expect(doesContainThings(testInstanceWithoutReferences)).to.be.equal(
|
||||
false,
|
||||
JSON.stringify([testInstance, testInstanceWithoutReferences], null, 2),
|
||||
);
|
||||
expect((testInstanceWithoutReferences as any).origin).to.be.equal(
|
||||
undefined,
|
||||
JSON.stringify([testInstance, testInstanceWithoutReferences], null, 2),
|
||||
);
|
||||
expect(testInstance).to.be.deep.equal(
|
||||
checkInstance,
|
||||
'Removing the references of a thing could have side effects because no deep copy is used',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
async removeUndefinedProperties() {
|
||||
const objectWithUndefinedProperties = {value: 'foo',
|
||||
novalue: undefined,
|
||||
nested: {
|
||||
value: 'foo',
|
||||
novalue: undefined},
|
||||
};
|
||||
const objectWithoutUndefinedProperties = {value: 'foo',
|
||||
nested: {
|
||||
value: 'foo'},
|
||||
};
|
||||
const objectWithUndefinedProperties = {
|
||||
value: 'foo',
|
||||
novalue: undefined,
|
||||
nested: {
|
||||
value: 'foo',
|
||||
novalue: undefined,
|
||||
},
|
||||
};
|
||||
const objectWithoutUndefinedProperties = {
|
||||
value: 'foo',
|
||||
nested: {
|
||||
value: 'foo',
|
||||
},
|
||||
};
|
||||
ConnectorClient.removeUndefinedProperties(objectWithUndefinedProperties);
|
||||
|
||||
expect(objectWithUndefinedProperties).to.deep.equal(objectWithoutUndefinedProperties, JSON.stringify(
|
||||
[objectWithUndefinedProperties, objectWithoutUndefinedProperties],
|
||||
null,
|
||||
2,
|
||||
));
|
||||
expect(objectWithUndefinedProperties).to.deep.equal(
|
||||
objectWithoutUndefinedProperties,
|
||||
JSON.stringify([objectWithUndefinedProperties, objectWithoutUndefinedProperties], null, 2),
|
||||
);
|
||||
}
|
||||
|
||||
@test
|
||||
async update() {
|
||||
const message: SCMessage = {
|
||||
audiences: [
|
||||
'employees',
|
||||
],
|
||||
categories: [
|
||||
'news'
|
||||
],
|
||||
audiences: ['employees'],
|
||||
categories: ['news'],
|
||||
messageBody: 'Lorem ipsum.',
|
||||
name: 'foo',
|
||||
origin: {
|
||||
@@ -454,13 +451,16 @@ export class ConnectorClientSpec {
|
||||
expect(httpClient.request).to.have.been.called.with({
|
||||
body: message,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: thingUpdateRoute.method,
|
||||
url: new URL('http://localhost' + thingUpdateRoute.getUrlPath({
|
||||
TYPE: SCThingType.Message,
|
||||
UID: 'foo',
|
||||
})),
|
||||
url: new URL(
|
||||
'http://localhost' +
|
||||
thingUpdateRoute.getUrlPath({
|
||||
TYPE: SCThingType.Message,
|
||||
UID: 'foo',
|
||||
}),
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,63 +57,73 @@ export class CopySpec {
|
||||
async copy() {
|
||||
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.getUrlPath().toString()) {
|
||||
const body = request.body as SCSearchRequest;
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlPath().toString()) {
|
||||
const body = request.body as SCSearchRequest;
|
||||
|
||||
let count = 0;
|
||||
if (typeof body.size === 'number' && body.size > 0) {
|
||||
count = 1;
|
||||
let count = 0;
|
||||
if (typeof body.size === 'number' && body.size > 0) {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
data: [
|
||||
{
|
||||
categories: ['main dish'],
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
indexed: moment().format(),
|
||||
name: 'bar',
|
||||
},
|
||||
type: SCThingType.Dish,
|
||||
uid: 'foo',
|
||||
},
|
||||
],
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: count,
|
||||
offset: 0,
|
||||
total: 1,
|
||||
},
|
||||
stats: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (
|
||||
request.url.toString() ===
|
||||
'http://localhost' +
|
||||
bulkAddRoute
|
||||
.getUrlPath({
|
||||
UID: 'foo',
|
||||
})
|
||||
.toString()
|
||||
) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
data: [{
|
||||
categories: [
|
||||
'main dish',
|
||||
],
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
indexed: moment().format(),
|
||||
name: 'bar',
|
||||
},
|
||||
type: SCThingType.Dish,
|
||||
uid: 'foo',
|
||||
}],
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: count,
|
||||
offset: 0,
|
||||
total: 1,
|
||||
},
|
||||
stats: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
}).toString()) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
await copy(httpClient, {
|
||||
batchSize: 5,
|
||||
@@ -129,62 +139,72 @@ export class CopySpec {
|
||||
async copyShouldFail() {
|
||||
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.getUrlPath().toString()) {
|
||||
const body = request.body as SCSearchRequest;
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||
if (request.url.toString() === 'http://foo.bar' + searchRoute.getUrlPath().toString()) {
|
||||
const body = request.body as SCSearchRequest;
|
||||
|
||||
if (typeof body.size === 'number' && body.size > 0) {
|
||||
throw new ApiError({});
|
||||
if (typeof body.size === 'number' && body.size > 0) {
|
||||
throw new ApiError({});
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
data: [
|
||||
{
|
||||
categories: ['main dish'],
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
indexed: moment().format(),
|
||||
name: 'bar',
|
||||
},
|
||||
type: SCThingType.Dish,
|
||||
uid: 'foo',
|
||||
},
|
||||
],
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: 0,
|
||||
offset: 0,
|
||||
total: 1,
|
||||
},
|
||||
stats: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (
|
||||
request.url.toString() ===
|
||||
'http://localhost' +
|
||||
bulkAddRoute
|
||||
.getUrlPath({
|
||||
UID: 'foo',
|
||||
})
|
||||
.toString()
|
||||
) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {
|
||||
data: [{
|
||||
categories: [
|
||||
'main dish',
|
||||
],
|
||||
name: 'foobar',
|
||||
origin: {
|
||||
indexed: moment().format(),
|
||||
name: 'bar',
|
||||
},
|
||||
type: SCThingType.Dish,
|
||||
uid: 'foo',
|
||||
}],
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: 0,
|
||||
offset: 0,
|
||||
total: 1,
|
||||
},
|
||||
stats: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlPath().toString()) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlPath({
|
||||
UID: 'foo',
|
||||
}).toString()) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return copy(httpClient, {
|
||||
batchSize: 5,
|
||||
|
||||
@@ -80,80 +80,93 @@ export class E2EConnectorSpec {
|
||||
let failOnCompare = false;
|
||||
let failOnLookup = false;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||
if (request.url.toString() === `http://localhost${bulkRoute.getUrlPath().toString()}`) {
|
||||
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (request.url.toString() === `http://localhost${bulkAddRoute.getUrlPath({UID: 'foo'}).toString()}`) {
|
||||
storedThings.set(request.body.uid, clone()(request.body));
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (request.url.toString() === `http://localhost${bulkDoneRoute.getUrlPath({UID: 'foo'}).toString()}`) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (request.url.toString() === `http://localhost${searchRoute.getUrlPath().toString()}`) {
|
||||
const thing = storedThings.get(request.body.filter.arguments.value);
|
||||
if (failOnCompare) {
|
||||
thing!.origin!.modified = 'altered';
|
||||
sandbox.on(
|
||||
httpClient,
|
||||
'request',
|
||||
async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||
if (request.url.toString() === `http://localhost${bulkRoute.getUrlPath().toString()}`) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
request.url.toString() === `http://localhost${bulkAddRoute.getUrlPath({UID: 'foo'}).toString()}`
|
||||
) {
|
||||
storedThings.set(request.body.uid, clone()(request.body));
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
request.url.toString() === `http://localhost${bulkDoneRoute.getUrlPath({UID: 'foo'}).toString()}`
|
||||
) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
if (request.url.toString() === `http://localhost${searchRoute.getUrlPath().toString()}`) {
|
||||
const thing = storedThings.get(request.body.filter.arguments.value);
|
||||
if (failOnCompare) {
|
||||
thing!.origin!.modified = 'altered';
|
||||
}
|
||||
const returnThing = failOnLookup ? [] : [thing];
|
||||
const returnBody = {
|
||||
data: returnThing,
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: returnThing.length,
|
||||
offset: 0,
|
||||
total: returnThing.length,
|
||||
},
|
||||
stats: {
|
||||
time: 42,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
body: returnBody,
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
const returnThing = failOnLookup ? [] : [thing];
|
||||
const returnBody = {
|
||||
data: returnThing,
|
||||
facets: [],
|
||||
pagination: {
|
||||
count: returnThing.length,
|
||||
offset: 0,
|
||||
total: returnThing.length,
|
||||
},
|
||||
stats: {
|
||||
time: 42,
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
body: returnBody,
|
||||
body: {},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: searchRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: './node_modules/@openstapps/core/test/resources'});
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
});
|
||||
|
||||
failOnLookup = true;
|
||||
failOnCompare = false;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: './node_modules/@openstapps/core/test/resources'})
|
||||
.should.be.rejectedWith('Search for single SCThing with uid');
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
}).should.be.rejectedWith('Search for single SCThing with uid');
|
||||
|
||||
failOnLookup = false;
|
||||
failOnCompare = true;
|
||||
// tslint:disable-next-line: max-line-length
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: './node_modules/@openstapps/core/test/resources'})
|
||||
.should.be.rejectedWith('Unexpected difference');
|
||||
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
}).should.be.rejectedWith('Unexpected difference');
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -161,7 +174,6 @@ export class E2EConnectorSpec {
|
||||
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse>;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (): Promise<RecursivePartial<responses>> => {
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: Number.MAX_SAFE_INTEGER,
|
||||
@@ -169,8 +181,10 @@ export class E2EConnectorSpec {
|
||||
});
|
||||
|
||||
// tslint:disable-next-line: max-line-length
|
||||
return e2eRun(httpClient, {to: 'http://localhost', samplesLocation: './node_modules/@openstapps/core/test/resources'})
|
||||
.should.be.rejectedWith(ApiError);
|
||||
return e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: './node_modules/@openstapps/core/test/resources',
|
||||
}).should.be.rejectedWith(ApiError);
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -179,8 +193,9 @@ export class E2EConnectorSpec {
|
||||
if (!existsSync(emptyDirPath)) {
|
||||
mkdirSync(emptyDirPath);
|
||||
}
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: emptyDirPath})
|
||||
.should.be.rejectedWith('Could not index samples. None were retrieved from the file system.');
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: emptyDirPath}).should.be.rejectedWith(
|
||||
'Could not index samples. None were retrieved from the file system.',
|
||||
);
|
||||
rmdirSync(emptyDirPath);
|
||||
}
|
||||
|
||||
@@ -190,10 +205,12 @@ export class E2EConnectorSpec {
|
||||
if (!existsSync(somewhatFilledDirPath)) {
|
||||
mkdirSync(somewhatFilledDirPath);
|
||||
}
|
||||
const nonJsonFile = join (somewhatFilledDirPath, 'nonjson.txt');
|
||||
const nonJsonFile = join(somewhatFilledDirPath, 'nonjson.txt');
|
||||
createFileSync(nonJsonFile);
|
||||
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: somewhatFilledDirPath})
|
||||
.should.be.rejectedWith('Could not index samples. None were retrieved from the file system.');
|
||||
await e2eRun(httpClient, {
|
||||
to: 'http://localhost',
|
||||
samplesLocation: somewhatFilledDirPath,
|
||||
}).should.be.rejectedWith('Could not index samples. None were retrieved from the file system.');
|
||||
unlinkSync(nonJsonFile);
|
||||
rmdirSync(somewhatFilledDirPath);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import {HttpClient} from '../src/http-client.js';
|
||||
|
||||
@suite()
|
||||
export class HttpClientSpec {
|
||||
|
||||
@test
|
||||
async construct() {
|
||||
expect(() => {
|
||||
@@ -37,9 +36,7 @@ export class HttpClientSpec {
|
||||
async request() {
|
||||
const client = new HttpClient();
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.reply(200, 'foo');
|
||||
nock('http://www.example.com').get('/resource').reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
url: new URL('http://www.example.com/resource'),
|
||||
@@ -52,12 +49,10 @@ export class HttpClientSpec {
|
||||
async requestWithBody() {
|
||||
const client = new HttpClient();
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.reply(200, 'foo');
|
||||
nock('http://www.example.com').get('/resource').reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
url: new URL('http://www.example.com/resource')
|
||||
url: new URL('http://www.example.com/resource'),
|
||||
});
|
||||
|
||||
expect(response.body).to.be.equal('foo');
|
||||
@@ -68,9 +63,7 @@ export class HttpClientSpec {
|
||||
const client = new HttpClient();
|
||||
let caughtErr;
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.replyWithError('foo');
|
||||
nock('http://www.example.com').get('/resource').replyWithError('foo');
|
||||
|
||||
try {
|
||||
await client.request({
|
||||
@@ -90,9 +83,7 @@ export class HttpClientSpec {
|
||||
async requestWithHeaders() {
|
||||
const client = new HttpClient();
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.reply(200, 'foo');
|
||||
nock('http://www.example.com').get('/resource').reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
headers: {
|
||||
@@ -108,9 +99,7 @@ export class HttpClientSpec {
|
||||
async requestWithMethodGet() {
|
||||
const client = new HttpClient();
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.reply(200, 'foo');
|
||||
nock('http://www.example.com').get('/resource').reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
method: 'GET',
|
||||
@@ -124,9 +113,7 @@ export class HttpClientSpec {
|
||||
async requestWithMethodPost() {
|
||||
const client = new HttpClient();
|
||||
|
||||
nock('http://www.example.com')
|
||||
.post('/resource')
|
||||
.reply(200, 'foo');
|
||||
nock('http://www.example.com').post('/resource').reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
method: 'POST',
|
||||
|
||||
@@ -41,7 +41,21 @@ export class PluginClientSpec {
|
||||
}
|
||||
|
||||
static async before() {
|
||||
this.plugin = new TestPlugin(4000, '', '', '', '', {getSchema: () => {/***/}} as any, '', '', '');
|
||||
this.plugin = new TestPlugin(
|
||||
4000,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
{
|
||||
getSchema: () => {
|
||||
/***/
|
||||
},
|
||||
} as any,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
);
|
||||
}
|
||||
|
||||
async after() {
|
||||
@@ -78,7 +92,7 @@ export class PluginClientSpec {
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: request,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: pluginRegisterRoute.method,
|
||||
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
|
||||
@@ -102,14 +116,14 @@ export class PluginClientSpec {
|
||||
await pluginClient.unregisterPlugin(PluginClientSpec.plugin);
|
||||
|
||||
const request: SCPluginRegisterRequest = {
|
||||
action: 'remove',
|
||||
route: PluginClientSpec.plugin.route,
|
||||
action: 'remove',
|
||||
route: PluginClientSpec.plugin.route,
|
||||
};
|
||||
|
||||
expect(httpClient.request).to.have.been.first.called.with({
|
||||
body: request,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method: pluginRegisterRoute.method,
|
||||
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*
|
||||
* @validatable
|
||||
*/
|
||||
export interface TestPluginResponse {
|
||||
export interface TestPluginResponse {
|
||||
/**
|
||||
* Query dummy
|
||||
*/
|
||||
query: string;
|
||||
query: string;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import {TestPlugin} from './plugin-resources/test-plugin.js';
|
||||
|
||||
chai.use(chaiSpies);
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -42,10 +42,21 @@ export class PluginSpec {
|
||||
}
|
||||
|
||||
static async before() {
|
||||
PluginSpec.testPlugin = new TestPlugin(4000, '', '', '', '', {
|
||||
getSchema: () => {/***/
|
||||
},
|
||||
} as any, '', '', '');
|
||||
PluginSpec.testPlugin = new TestPlugin(
|
||||
4000,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
{
|
||||
getSchema: () => {
|
||||
/***/
|
||||
},
|
||||
} as any,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
);
|
||||
}
|
||||
|
||||
async after() {
|
||||
@@ -54,9 +65,12 @@ export class PluginSpec {
|
||||
|
||||
@test
|
||||
async construct() {
|
||||
const converter = new Converter(__dirname, resolve(__dirname,'plugin-resources','test-plugin-response.ts'));
|
||||
const converter = new Converter(
|
||||
__dirname,
|
||||
resolve(__dirname, 'plugin-resources', 'test-plugin-response.ts'),
|
||||
);
|
||||
|
||||
sandbox.on(converter, 'getSchema', (schemaName) => {
|
||||
sandbox.on(converter, 'getSchema', schemaName => {
|
||||
return {$id: schemaName};
|
||||
});
|
||||
|
||||
@@ -98,10 +112,21 @@ export class PluginSpec {
|
||||
|
||||
@test
|
||||
async fullUrl() {
|
||||
const constructTestPlugin = new TestPlugin(4001, '', 'http://B', '', '', {
|
||||
getSchema: () => {/***/
|
||||
},
|
||||
} as any, '', '', '');
|
||||
const constructTestPlugin = new TestPlugin(
|
||||
4001,
|
||||
'',
|
||||
'http://B',
|
||||
'',
|
||||
'',
|
||||
{
|
||||
getSchema: () => {
|
||||
/***/
|
||||
},
|
||||
} as any,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
);
|
||||
expect(constructTestPlugin.fullUrl).to.be.equal('http://B:4001');
|
||||
await constructTestPlugin.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user