refactor: build system

This commit is contained in:
2023-03-22 11:45:30 +01:00
parent 4df19e8c20
commit 8cb9285462
427 changed files with 3978 additions and 9810 deletions

View File

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