mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
committed by
Karl-Philipp Wulfert
parent
1ae3beb347
commit
766205049b
65
test/Transport.spec.ts
Normal file
65
test/Transport.spec.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 {expect} from 'chai';
|
||||
import {slow, suite, test, timeout} from 'mocha-typescript';
|
||||
import {isTransportWithVerification} from '../src/common';
|
||||
import {Transport, VerifiableTransport} from '../src/Transport';
|
||||
|
||||
export class DummyTransport extends Transport {
|
||||
send(subject: string, message: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (0 === 0) {
|
||||
resolve(subject);
|
||||
}
|
||||
|
||||
reject(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class VerifiableDummyTransport extends VerifiableTransport {
|
||||
isVerified(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
send(subject: string, message: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (0 === 0) {
|
||||
resolve(subject);
|
||||
}
|
||||
|
||||
reject(message);
|
||||
});
|
||||
}
|
||||
|
||||
verify(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@suite(timeout(2000), slow(1000))
|
||||
export class TransportSpec {
|
||||
@test
|
||||
isNotTransportWithVerification() {
|
||||
return expect(isTransportWithVerification(new DummyTransport())).to.be.false;
|
||||
}
|
||||
|
||||
@test
|
||||
isTransportWithVerification() {
|
||||
return expect(isTransportWithVerification(new VerifiableDummyTransport())).to.be.true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user