Skip to content

πŸ“ˆ Get real-time stocks from TradingView

Update tests

Mathieu Colmon7c482b9efcc3
diff --git a/src/client.js b/src/client.js
index 015d456..8a07c4d 100644
--- a/src/client.js
+++ b/src/client.js
@@ -231,7 +231,10 @@ module.exports = class Client {
});
if (clientOptions.token) {
- misc.getUser(clientOptions.token, clientOptions.signature ? clientOptions.signature : '').then((user) => {
+ misc.getUser(
+ clientOptions.token,
+ clientOptions.signature ? clientOptions.signature : '',
+ ).then((user) => {
this.#sendQueue.unshift(protocol.formatWSPacket({
m: 'set_auth_token',
p: [user.authToken],
diff --git a/src/miscRequests.js b/src/miscRequests.js
index 886ccd8..dbffb49 100644
--- a/src/miscRequests.js
+++ b/src/miscRequests.js
@@ -439,7 +439,7 @@ module.exports = {
authToken: /"auth_token":"(.*?)"/.exec(rs)[1],
joinDate: new Date(/"date_joined":"(.*?)"/.exec(rs)[1] || 0),
});
- } else err(new Error('Wrong or expired sessionid'));
+ } else err(new Error('Wrong or expired sessionid/signature'));
});
res.on('error', err);
diff --git a/tests/09. AllErrors.js b/tests/09. AllErrors.js
index a21e475..701fcf7 100644
--- a/tests/09. AllErrors.js
+++ b/tests/09. AllErrors.js
@@ -135,6 +135,32 @@ module.exports = async (log, success, warn, err, cb) => {
next();
});
},
+
+ async (next) => { /* Testing "Wrong or expired sessionid/signature" using getUser method */
+ log('Testing "Wrong or expired sessionid/signature" error using getUser method:');
+ try {
+ await TradingView.getUser(process.env.SESSION);
+ err('=> User found !');
+ } catch (error) {
+ success('=> User not found:', error);
+ next();
+ }
+ },
+
+ async (next) => { /* Testing "Wrong or expired sessionid/signature" using client */
+ log('Testing "Wrong or expired sessionid/signature" error using client:');
+
+ log('Creating a new client...');
+ const client2 = new TradingView.Client({
+ token: process.env.SESSION,
+ });
+
+ client2.onError((...error) => {
+ success('=> Client error:', error);
+ client2.end();
+ next();
+ });
+ },
];
(async () => {
diff --git a/tests/10. Authenticated.js b/tests/10. Authenticated.js
index 3ba89e1..b6c6bea 100644
--- a/tests/10. Authenticated.js
+++ b/tests/10. Authenticated.js
@@ -7,7 +7,7 @@ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
module.exports = async (log, success, warn, err, cb) => {
log('Getting user info');
- const userInfos = await TradingView.getUser(process.env.SESSION);
+ const userInfos = await TradingView.getUser(process.env.SESSION, process.env.SIGNATURE);
if (userInfos && userInfos.id) {
success('User info:', {
id: userInfos.id,
@@ -36,6 +36,7 @@ module.exports = async (log, success, warn, err, cb) => {
log('Creating logged client');
const client = new TradingView.Client({
token: process.env.SESSION,
+ signature: process.env.SIGNATURE,
});
client.onError((...error) => {
err('Client error', error);