refactor: split api into api, api-cli & api-plugin

This commit is contained in:
2023-06-02 16:41:25 +02:00
parent 495a63977c
commit b21833de40
205 changed files with 1981 additions and 1492 deletions

View File

@@ -32,8 +32,6 @@ import chai from 'chai';
import {expect} from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import clone = require('rfdc');
import moment from 'moment';
import traverse from 'traverse';
import {
ConnectorClient,
@@ -82,10 +80,12 @@ describe('ConnectorClient', function () {
});
it('should bulk', async function () {
sandbox.on(httpClient, 'request', async (): Promise<HttpClientResponse<SCBulkResponse>> => {
let expiration = 'ERROR';
sandbox.on(httpClient, 'request', async (response): Promise<HttpClientResponse<SCBulkResponse>> => {
expiration = response?.body?.expiration ?? 'ERROR';
return {
body: {
expiration: moment().add(1800, 'seconds').format(),
expiration,
source: 'foo',
state: 'in progress',
type: SCThingType.Message,
@@ -103,7 +103,7 @@ describe('ConnectorClient', function () {
expect(httpClient.request).to.have.been.first.called.with({
body: {
expiration: moment().add(1800, 'seconds').format(),
expiration,
source: 'foo',
type: SCThingType.Message,
},
@@ -116,10 +116,12 @@ describe('ConnectorClient', function () {
});
it('should bulk without timeout', async function () {
sandbox.on(httpClient, 'request', async (): Promise<HttpClientResponse<SCBulkResponse>> => {
let expiration = 'ERROR';
sandbox.on(httpClient, 'request', async (request): Promise<HttpClientResponse<SCBulkResponse>> => {
expiration = request?.body?.expiration ?? 'ERROR';
return {
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'foo',
state: 'in progress',
type: SCThingType.Message,
@@ -137,7 +139,7 @@ describe('ConnectorClient', function () {
expect(httpClient.request).to.have.been.first.called.with({
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'foo',
type: SCThingType.Message,
},
@@ -181,14 +183,17 @@ describe('ConnectorClient', function () {
type responses = SCBulkResponse | SCBulkAddResponse | SCBulkDoneResponse;
let expiration = 'ERROR';
sandbox.on(
httpClient,
'request',
async (request: HttpClientRequest): Promise<HttpClientResponse<responses>> => {
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expiration = (request?.body as any)?.expiration ?? 'ERROR';
return {
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'copy',
state: 'in progress',
type: SCThingType.Message,
@@ -226,7 +231,7 @@ describe('ConnectorClient', function () {
expect(httpClient.request).to.have.been.first.called.with({
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'copy',
type: SCThingType.Message,
},
@@ -275,14 +280,17 @@ describe('ConnectorClient', function () {
type responses = SCBulkResponse | SCBulkAddResponse | SCBulkDoneResponse;
let expiration = 'ERROR';
sandbox.on(
httpClient,
'request',
async (request: HttpClientRequest): Promise<HttpClientResponse<responses>> => {
if (request.url.toString() === new URL('http://localhost' + bulkRoute.getUrlPath()).toString()) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expiration = (request?.body as any)?.expiration ?? 'ERROR';
return {
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'stapps-api',
state: 'in progress',
type: SCThingType.Message,
@@ -320,7 +328,7 @@ describe('ConnectorClient', function () {
expect(httpClient.request).to.have.been.first.called.with({
body: {
expiration: moment().add(3600, 'seconds').format(),
expiration,
source: 'stapps-api',
type: SCThingType.Message,
},
@@ -370,7 +378,7 @@ describe('ConnectorClient', function () {
);
for (const testInstance of testInstances) {
const checkInstance = clone()(testInstance);
const checkInstance = JSON.parse(JSON.stringify(testInstance));
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
expect(doesContainThings(testInstanceWithoutReferences)).to.be.equal(