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

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