-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated core and firstrade to getcontact info
- Loading branch information
Showing
9 changed files
with
118 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,54 @@ | ||
const firstrade = require("../firstrade.js"); | ||
|
||
const { firstrade } = require("../../index"); | ||
const CUSTOM_TIMEOUT = 30000; | ||
const toTest = [ | ||
"getBalance", | ||
"getPosition", | ||
"getTradeHistory", | ||
"getSessionTimeLeft", | ||
"getContact", | ||
]; | ||
let credential | ||
|
||
beforeAll(() => { | ||
require("dotenv").config(); | ||
credential = { | ||
username: process.env.FIRSTRADE_USERNAME, | ||
password: process.env.FIRSTRADE_PASSWORD, | ||
pin: process.env.FIRSTRADE_PIN | ||
} | ||
jest.setTimeout(CUSTOM_TIMEOUT); | ||
}); | ||
|
||
describe("with previous session", () => { | ||
let session; | ||
let session = []; | ||
|
||
beforeAll(async () => { | ||
session = await firstrade.login(credential); | ||
}); | ||
|
||
test("Should login and return session cookies", async () => { | ||
console.log(session); | ||
}); | ||
|
||
test("Should return balance using previous session", async () => { | ||
const res = await firstrade.getBalance(session); | ||
console.log(res); | ||
session = await loginTry(session); | ||
}); | ||
|
||
test("Should return position using previous session", async () => { | ||
const res = await firstrade.getPosition(session); | ||
console.log(res); | ||
test.each(toTest)('Should invoke %s using previous session', async (fn) => { | ||
const res = await firstrade[fn](session); | ||
expect(res).toStrictEqual(expect.anything()); | ||
}); | ||
|
||
test("Should return history using previous session", async () => { | ||
const res = await firstrade.getTradeHistory(session); | ||
console.log( | ||
res); | ||
}, 30000); | ||
test("Should return session time left using previous session", async () => { | ||
const res = await firstrade.getSessionTimeLeft(session); | ||
console.log(res); | ||
}); | ||
}); | ||
|
||
describe("without previous session", () => { | ||
test("Should return balance after login", async () => { | ||
const res = await firstrade.getBalance(credential); | ||
console.log(res); | ||
}, 30000); | ||
|
||
test("Should return position after login", async () => { | ||
const res = await firstrade.getPosition(credential); | ||
console.log(res); | ||
}, 30000); | ||
|
||
test("Should return history after login", async () => { | ||
const res = await firstrade.getTradeHistory(credential); | ||
console.log(res); | ||
}, 30000); | ||
test.each(toTest)('Should invoke %s after login', async (fn) => { | ||
const res = await firstrade[fn](credential); | ||
expect(res).toStrictEqual(expect.anything()); | ||
}); | ||
|
||
test("Should return session time left after login", async () => { | ||
const res = await firstrade.getSessionTimeLeft(credential); | ||
console.log(res); | ||
}, 30000); | ||
}); | ||
|
||
async function loginTry(session, limit = 5) { | ||
let sid; | ||
do { | ||
session = await firstrade.login(credential); | ||
sid = (session.find(x => x.key == "SID") || {}).value; | ||
} while (!sid && limit-- > 0); | ||
if (!sid) | ||
throw new Error("Login Failure"); | ||
return session; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters