feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -12,9 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
// tslint:disable-next-line: max-line-length
// tslint:disable: completed-docs no-implicit-dependencies prefer-function-over-method newline-per-chained-call member-ordering
// eslint-disable-next-line unicorn/prevent-abbreviations
import {
SCBulkAddResponse,
SCBulkAddRoute,
@@ -32,12 +30,12 @@ import chaiSpies from 'chai-spies';
import clone = require('rfdc');
import {existsSync, mkdirSync, rmdirSync, unlinkSync} from 'fs';
import {createFileSync} from 'fs-extra';
import {suite, test} from '@testdeck/mocha';
import {join} from 'path';
import {e2eRun, getItemsFromSamples} from '../src/e2e.js';
import {ApiError} from '../src/errors.js';
import {HttpClient, RequestOptions, Response} from '../src/http-client.js';
import {RecursivePartial} from './client.spec';
// eslint-disable-next-line unicorn/prevent-abbreviations
import {e2eRun, getItemsFromSamples, ApiError, HttpClient, RequestOptions, Response} from '../src/index.js';
import {RecursivePartial} from './client.spec.js';
import {expect} from "chai";
import path from "path";
import {fileURLToPath} from "url";
chai.should();
chai.use(chaiSpies);
@@ -55,26 +53,21 @@ const httpClient = new HttpClient();
const storedThings: Map<string, SCThings> = new Map();
@suite
export class E2EConnectorSpec {
async after() {
describe('e2e Connector', function () {
afterEach(function () {
sandbox.restore();
}
});
@test
async getCoreTestSamples() {
it('should get core test samples', async function () {
const items = await getItemsFromSamples('./node_modules/@openstapps/core/test/resources');
// tslint:disable-next-line: no-unused-expression
chai.expect(items).to.not.be.empty;
}
expect(items).to.not.be.empty;
});
@test
async getCoreTestSamplesShouldFail() {
await chai.expect(getItemsFromSamples('./nonexistantdirectory')).to.be.rejectedWith(Error);
}
it('should fail to get core test samples', async function () {
await chai.expect(getItemsFromSamples('./non-existent-directory')).to.be.rejectedWith(Error);
});
@test
async e2eRunSimulation() {
it('should run e2e simulation', async function () {
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse | SCSearchResponse>;
let failOnCompare = false;
@@ -167,10 +160,9 @@ export class E2EConnectorSpec {
to: 'http://localhost',
samplesLocation: './node_modules/@openstapps/core/test/resources',
}).should.be.rejectedWith('Unexpected difference');
}
});
@test
async indexShouldFail() {
it('should fail to index', async function () {
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse>;
sandbox.on(httpClient, 'request', async (): Promise<RecursivePartial<responses>> => {
@@ -185,33 +177,31 @@ export class E2EConnectorSpec {
to: 'http://localhost',
samplesLocation: './node_modules/@openstapps/core/test/resources',
}).should.be.rejectedWith(ApiError);
}
});
@test
async indexShouldFailDirectoryWithoutData() {
const emptyDirPath = join(__dirname, 'emptyDir');
if (!existsSync(emptyDirPath)) {
mkdirSync(emptyDirPath);
it('should fail to index directory without data', async function () {
const emptyDirectoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'emptyDir');
if (!existsSync(emptyDirectoryPath)) {
mkdirSync(emptyDirectoryPath);
}
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: emptyDirPath}).should.be.rejectedWith(
await e2eRun(httpClient, {to: 'http://localhost', samplesLocation: emptyDirectoryPath}).should.be.rejectedWith(
'Could not index samples. None were retrieved from the file system.',
);
rmdirSync(emptyDirPath);
}
rmdirSync(emptyDirectoryPath);
});
@test
async indexShouldFailDirectoryWithoutJsonData() {
const somewhatFilledDirPath = join(__dirname, 'somewhatFilledDir');
if (!existsSync(somewhatFilledDirPath)) {
mkdirSync(somewhatFilledDirPath);
it('should fail to index directory without json data', async function () {
const somewhatFilledDirectoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'somewhatFilledDir');
if (!existsSync(somewhatFilledDirectoryPath)) {
mkdirSync(somewhatFilledDirectoryPath);
}
const nonJsonFile = join(somewhatFilledDirPath, 'nonjson.txt');
const nonJsonFile = path.join(somewhatFilledDirectoryPath, 'nonjson.txt');
createFileSync(nonJsonFile);
await e2eRun(httpClient, {
to: 'http://localhost',
samplesLocation: somewhatFilledDirPath,
samplesLocation: somewhatFilledDirectoryPath,
}).should.be.rejectedWith('Could not index samples. None were retrieved from the file system.');
unlinkSync(nonJsonFile);
rmdirSync(somewhatFilledDirPath);
}
}
rmdirSync(somewhatFilledDirectoryPath);
});
});