mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
test: add tests for new e2e command
This commit is contained in:
114
test/e2e.spec.ts
Normal file
114
test/e2e.spec.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* 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 {
|
||||
SCBulkAddResponse,
|
||||
SCBulkAddRoute,
|
||||
SCBulkDoneResponse,
|
||||
SCBulkDoneRoute,
|
||||
SCBulkResponse,
|
||||
SCBulkRoute,
|
||||
SCThing,
|
||||
} from '@openstapps/core';
|
||||
import * as chai from 'chai';
|
||||
import * as chaiAsPromised from 'chai-as-promised';
|
||||
import * as chaiSpies from 'chai-spies';
|
||||
import {suite, test} from 'mocha-typescript';
|
||||
import {getItemsFromSamples, indexSamples} from '../src/e2e';
|
||||
import {ApiError} from '../src/errors';
|
||||
import {HttpClient, RequestOptions, Response} from '../src/httpClient';
|
||||
import {RecursivePartial} from './client.spec';
|
||||
|
||||
chai.should();
|
||||
chai.use(chaiSpies);
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
const sandbox = chai.spy.sandbox();
|
||||
|
||||
const bulkRoute = new SCBulkRoute();
|
||||
const bulkAddRoute = new SCBulkAddRoute();
|
||||
const bulkDoneRoute = new SCBulkDoneRoute();
|
||||
|
||||
const httpClient = new HttpClient();
|
||||
|
||||
@suite
|
||||
export class E2EConnectorSpec {
|
||||
async after() {
|
||||
sandbox.restore();
|
||||
}
|
||||
|
||||
@test
|
||||
getCoreTestSamples() {
|
||||
return getItemsFromSamples('./node_modules/@openstapps/core/test/resources')
|
||||
.then(<T extends SCThing>(items: T[]) => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
chai.expect(items).to.not.be.a.instanceof(Error);
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
chai.expect(items).to.not.be.empty;
|
||||
});
|
||||
}
|
||||
|
||||
@test
|
||||
getCoreTestSamplesShouldFail() {
|
||||
return getItemsFromSamples('./nonexistantdirectory')
|
||||
.then(<T extends SCThing>(items: T[]) => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
chai.expect(items).to.be.a.instanceof(Error);
|
||||
});
|
||||
}
|
||||
|
||||
@test
|
||||
async index() {
|
||||
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse>;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (request: RequestOptions): Promise<RecursivePartial<responses>> => {
|
||||
if (request.url.toString() === 'http://localhost' + bulkRoute.getUrlFragment().toString()) {
|
||||
return {
|
||||
body: {
|
||||
state: 'in progress',
|
||||
uid: 'foo',
|
||||
},
|
||||
statusCode: bulkRoute.statusCodeSuccess,
|
||||
};
|
||||
} else if (request.url.toString() === 'http://localhost' + bulkAddRoute.getUrlFragment({
|
||||
UID: 'foo',
|
||||
}).toString()) {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkAddRoute.statusCodeSuccess,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
body: {},
|
||||
statusCode: bulkDoneRoute.statusCodeSuccess,
|
||||
};
|
||||
});
|
||||
await indexSamples(httpClient, {to: 'http://localhost', samples: './node_modules/@openstapps/core/test/resources'});
|
||||
}
|
||||
|
||||
@test
|
||||
async indexShouldFail() {
|
||||
type responses = Response<SCBulkAddResponse | SCBulkDoneResponse | SCBulkResponse>;
|
||||
|
||||
sandbox.on(httpClient, 'request', async (): Promise<RecursivePartial<responses>> => {
|
||||
return {
|
||||
body: {},
|
||||
statusCode: Number.MAX_SAFE_INTEGER,
|
||||
};
|
||||
});
|
||||
return indexSamples(httpClient, {to: 'http://localhost', samples: './node_modules/@openstapps/core/test/resources'})
|
||||
.should.be.rejectedWith(ApiError);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user