Skip to content

Commit 4d86a57

Browse files
author
Grégory Saive
authored
Merge branch 'master' into master
2 parents de6aa54 + 5d2a35d commit 4d86a57

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/infrastructure/Listener.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class Listener {
104104
this.webSocket.onerror = (err) => {
105105
console.log('WebSocket Error ');
106106
console.log(err);
107+
reject(err);
107108
};
108109
this.webSocket.onmessage = (msg) => {
109110
const message = JSON.parse(msg.data as string);
@@ -155,6 +156,17 @@ export class Listener {
155156
});
156157
}
157158

159+
/**
160+
* returns a boolean that repressents the open state
161+
* @returns a boolean
162+
*/
163+
public isOpen(): boolean {
164+
if(this.webSocket){
165+
return this.webSocket.readyState === WebSocket.OPEN;
166+
}
167+
return false;
168+
}
169+
158170
/**
159171
* Close web socket connection.
160172
* @returns void

src/model/transaction/Transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ export abstract class Transaction {
158158
}
159159

160160
/**
161-
* @description re-aplly a given value to the transaction in an immutable way
161+
* @description reapply a given value to the transaction in an immutable way
162162
* @param {Deadline} deadline
163163
* @returns {Transaction}
164164
* @memberof Transaction
165165
*/
166-
public replyGiven(deadline: Deadline = Deadline.create()): Transaction {
166+
public reapplyGiven(deadline: Deadline = Deadline.create()): Transaction {
167167
if (this.isUnannounced()) {
168168
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {deadline});
169169
}

test/infrastructure/Listener.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@ describe('Listener', () => {
2323
expect('ws://localhost:3000/ws').to.be.equal(listener.url);
2424
listener.close();
2525
});
26+
27+
describe('isOpen', () => {
28+
it('should return false when listener is created and not opened', () => {
29+
const listener = new Listener('ws://localhost:3000');
30+
expect(listener.isOpen()).to.be.false;
31+
listener.close();
32+
});
33+
});
34+
35+
describe('onerror', () => {
36+
it('should reject because of wrong server url', async () => {
37+
const listener = new Listener('https://notcorrecturl:0000');
38+
await listener.open()
39+
.then((result) => {
40+
throw new Error('This should not be called when expecting error');
41+
})
42+
.catch((error) => {
43+
expect(error.toString()).to.be.equal("Error: getaddrinfo ENOTFOUND notcorrecturl notcorrecturl:0000");
44+
})
45+
});
46+
});
2647
});

test/model/transaction/Transaction.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Transaction', () => {
9999
});
100100
});
101101

102-
describe('replyGiven', () => {
102+
describe('reapplyGiven', () => {
103103
it('should throw an error if the transaction is announced', () => {
104104
const transaction = new FakeTransaction(TransactionType.TRANSFER,
105105
NetworkType.MIJIN_TEST,
@@ -111,7 +111,7 @@ describe('Transaction', () => {
111111
new TransactionInfo(UInt64.fromUint(100), 1, 'id_hash', 'hash', 'hash'),
112112
);
113113
expect(() => {
114-
transaction.replyGiven(Deadline.create());
114+
transaction.reapplyGiven(Deadline.create());
115115
}).to.throws('an Announced transaction can\'t be modified');
116116
});
117117
it('should return a new transaction', () => {
@@ -124,7 +124,7 @@ describe('Transaction', () => {
124124
undefined,
125125
);
126126

127-
const newTransaction = transaction.replyGiven(Deadline.create());
127+
const newTransaction = transaction.reapplyGiven(Deadline.create());
128128
expect(newTransaction).to.not.equal(transaction);
129129
});
130130
it('should overide deadline properly', () => {
@@ -138,7 +138,7 @@ describe('Transaction', () => {
138138
);
139139

140140
const newDeadline = Deadline.create(3);
141-
const newTransaction = transaction.replyGiven(newDeadline);
141+
const newTransaction = transaction.reapplyGiven(newDeadline);
142142
const equal = newTransaction.deadline.value.equals(transaction.deadline.value);
143143
const after = newTransaction.deadline.value.isAfter(transaction.deadline.value);
144144
expect(newTransaction.deadline).to.be.equal(newDeadline);

0 commit comments

Comments
 (0)