Skip to content

Commit 61faf5b

Browse files
authored
Merge pull request #331 from NEMStudios/fix-lister-unit-test
Fixed Listener Unit Test
2 parents 03a3214 + 9012d44 commit 61faf5b

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

test/infrastructure/Listener.spec.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {expect} from 'chai';
18-
import {Listener} from '../../src/infrastructure/Listener';
19-
import {Address} from "../../src/model/account/Address";
20-
import {deepEqual} from "assert";
21-
import {UInt64} from "../../src/model/UInt64";
22-
import {timeout} from "rxjs/operators";
17+
import { expect } from 'chai';
18+
import { Listener } from '../../src/infrastructure/Listener';
19+
import { Address } from "../../src/model/account/Address";
20+
import { deepEqual } from "assert";
21+
import { UInt64 } from "../../src/model/UInt64";
22+
import { timeout } from "rxjs/operators";
23+
import { TransactionStatusError } from "../../src/model/transaction/TransactionStatusError";
2324

2425
describe('Listener', () => {
2526
it('should createComplete a WebSocket instance given url parameter', () => {
@@ -37,7 +38,7 @@ describe('Listener', () => {
3738
});
3839

3940
describe('onStatusWhenAddressIsTheSame', () => {
40-
it('Should forward status', (done) => {
41+
it('Should forward status', () => {
4142

4243

4344
const errorEncodedAddress = '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB';
@@ -64,24 +65,27 @@ describe('Listener', () => {
6465

6566
listener.open();
6667

67-
listener.status(errorAddress).pipe(timeout(2000)).subscribe((transactionStatusError) => {
68-
expect(transactionStatusError.address).to.deep.equal(errorAddress);
69-
expect(transactionStatusError.hash).to.be.equal(statusInfoErrorDTO.hash);
70-
expect(transactionStatusError.status).to.be.equal(statusInfoErrorDTO.status);
71-
deepEqual(transactionStatusError.deadline.toDTO(), UInt64.fromNumericString(statusInfoErrorDTO.deadline).toDTO());
72-
done();
73-
}, err => {
74-
done('Should have not timed out!');
68+
const reportedStatus = new Array<TransactionStatusError>();
69+
70+
listener.status(errorAddress).subscribe((transactionStatusError) => {
71+
reportedStatus.push(transactionStatusError);
7572
});
7673

7774
listener.handleMessage(statusInfoErrorDTO, null);
7875

76+
expect(reportedStatus.length).to.be.equal(1);
77+
const transactionStatusError = reportedStatus[0];
78+
expect(transactionStatusError.address).to.deep.equal(errorAddress);
79+
expect(transactionStatusError.hash).to.be.equal(statusInfoErrorDTO.hash);
80+
expect(transactionStatusError.status).to.be.equal(statusInfoErrorDTO.status);
81+
deepEqual(transactionStatusError.deadline.toDTO(), UInt64.fromNumericString(statusInfoErrorDTO.deadline).toDTO());
82+
7983

8084
});
8185
});
8286

8387
describe('onStatusWhenAddressIsDifferentAddress', () => {
84-
it('Should not forward status', (done) => {
88+
it('Should not forward status', () => {
8589

8690

8791
const errorEncodedAddress = '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB';
@@ -110,14 +114,15 @@ describe('Listener', () => {
110114

111115
listener.open();
112116

113-
listener.status(subscribedAddress).pipe(timeout(100)).subscribe(status => {
114-
done('Should have timed out!');
115-
}, err => {
116-
expect(err.name).to.be.eq('TimeoutError');
117-
done();
117+
const reportedStatus = new Array<TransactionStatusError>();
118+
119+
listener.status(subscribedAddress).subscribe((transactionStatusError) => {
120+
reportedStatus.push(transactionStatusError);
118121
});
119122

120123
listener.handleMessage(statusInfoErrorDTO, null);
124+
125+
expect(reportedStatus.length).to.be.equal(0);
121126

122127

123128
});
@@ -127,12 +132,12 @@ describe('Listener', () => {
127132
it('should reject because of wrong server url', async () => {
128133
const listener = new Listener('https://notcorrecturl:0000');
129134
await listener.open()
130-
.then((result) => {
131-
throw new Error('This should not be called when expecting error');
132-
})
133-
.catch((error) => {
134-
expect(error.message.toString()).not.to.be.equal('');
135-
});
135+
.then((result) => {
136+
throw new Error('This should not be called when expecting error');
137+
})
138+
.catch((error) => {
139+
expect(error.message.toString()).not.to.be.equal('');
140+
});
136141
});
137142
});
138143
});

0 commit comments

Comments
 (0)