Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: reenable some tests #503

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions tests/bot_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config();
// const path = require('path');
// const fs = require('fs');
const path = require('path');
const fs = require('fs');
const TelegramServer = require('telegram-test-api');
const sinon = require('sinon');
const { expect } = require('chai');
Expand All @@ -9,7 +9,7 @@ const { User, Order } = require('../models');
const ordersActions = require('../bot/ordersActions');
const testUser = require('./user');
const testOrder = require('./order');
// const { getCurrenciesWithPrice } = require('../util');
const { getCurrenciesWithPrice } = require('../util');
const { connect: mongoConnect } = require('../db_connect');

mongoConnect();
Expand Down Expand Up @@ -114,33 +114,32 @@ describe('Telegram bot test', () => {
const command = client.makeCommand('/listcurrencies');
const res = await client.sendCommand(command);
expect(res.ok).to.be.equal(true);
// const updates = await client.getUpdates();
// userStub.restore();
// expect(updates.ok).to.be.equal(true);
// expect(
// (updates.result[0].message.text.match(/\n/g) || []).length - 1
// ).to.be.equal(getCurrenciesWithPrice().length);
const updates = await client.getUpdates();
userStub.restore();
expect(updates.ok).to.be.equal(true);
expect(
(updates.result[0].message.text.match(/\n/g) || []).length - 1
).to.be.equal(getCurrenciesWithPrice().length);
});

// it('should return flags of langs supported', async () => {
// const client = server.getClient(token, { timeout: 5000 });
// const userStub = sinon.stub(User, 'findOne');
// userStub.returns(testUser);
// const command = client.makeCommand('/setlang');
// const res = await client.sendCommand(command);
// console.log(res);
// expect(res.ok).to.be.equal(true);
// const updates = await client.getUpdates();
// userStub.restore();
// expect(updates.ok).to.be.equal(true);
// let flags = 0;
// updates.result[0].message.reply_markup.inline_keyboard.forEach(flag => {
// flags += flag.length;
// });
// let langs = 0;
// fs.readdirSync(path.join(__dirname, '../locales')).forEach(file => {
// langs++;
// });
// expect(flags).to.be.equal(langs);
// });
it('should return flags of langs supported', async () => {
const client = server.getClient(token, { timeout: 5000 });
const userStub = sinon.stub(User, 'findOne');
userStub.returns(testUser);
const command = client.makeCommand('/setlang');
const res = await client.sendCommand(command);
expect(res.ok).to.be.equal(true);
const updates = await client.getUpdates();
userStub.restore();
expect(updates.ok).to.be.equal(true);
let flags = 0;
updates.result[0].message.reply_markup.inline_keyboard.forEach(flag => {
flags += flag.length;
});
let langs = 0;
fs.readdirSync(path.join(__dirname, '../locales')).forEach(file => {
langs++;
});
expect(flags).to.be.equal(langs);
});
});
Loading