Skip to content

Commit

Permalink
Test case added for issue #193
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Oct 11, 2023
1 parent 8cfe8d8 commit e2f2415
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/tests/unit/api-next/subscription-registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Subscription } from "rxjs";
import { IBApiNext, IBApiNextError } from "../../..";

const _awaitTimeout = (delay: number): Promise<unknown> =>
new Promise((resolve): NodeJS.Timeout => setTimeout(resolve, delay * 1000));

describe("Subscription registry Tests", () => {
jest.setTimeout(20000);

const clientId = Math.floor(Math.random() * 32766) + 1; // ensure unique client

let subscription$: Subscription;

Check warning on line 12 in src/tests/unit/api-next/subscription-registry.test.ts

View workflow job for this annotation

GitHub Actions / job

'subscription$' is assigned a value but never used. Allowed unused vars must match /^_/u
let api: IBApiNext;
let error$: Subscription;

beforeEach(() => {
api = new IBApiNext();

if (!error$) {
error$ = api.errorSubject.subscribe((error) => {
if (error.reqId === -1) {
console.warn(`${error.error.message} (Error #${error.code})`);
} else {
console.error(
`${error.error.message} (Error #${error.code}) ${
error.advancedOrderReject ? error.advancedOrderReject : ""
}`,
);
}
});
}

try {
api.connect(clientId);
} catch (error) {
console.error(error.message);
}
});

afterEach(() => {
if (api) {
api.disconnect();
api = undefined;
}
});

it("Twice the same event callback bug", (done) => {
subscription$ = api.getOpenOrders().subscribe({
next: (data) => {
console.log(data);
},
error: (err: IBApiNextError) => {
console.error(`getOpenOrders failed with '${err.error.message}'`);
},
});

api
.getAllOpenOrders()
.then((orders) => {
console.log(orders);
done();
})
.catch((err: IBApiNextError) => {
console.error(`getAllOpenOrders failed with '${err}'`);
});

// awaitTimeout(15).then(() => {
// subscription$.unsubscribe();
// done();
// });
});
});

0 comments on commit e2f2415

Please sign in to comment.