1
1
require ( 'dotenv' ) . config ( ) ;
2
- // const path = require('path');
3
- // const fs = require('fs');
2
+ const path = require ( 'path' ) ;
3
+ const fs = require ( 'fs' ) ;
4
4
const TelegramServer = require ( 'telegram-test-api' ) ;
5
5
const sinon = require ( 'sinon' ) ;
6
6
const { expect } = require ( 'chai' ) ;
@@ -9,7 +9,7 @@ const { User, Order } = require('../models');
9
9
const ordersActions = require ( '../bot/ordersActions' ) ;
10
10
const testUser = require ( './user' ) ;
11
11
const testOrder = require ( './order' ) ;
12
- // const { getCurrenciesWithPrice } = require('../util');
12
+ const { getCurrenciesWithPrice } = require ( '../util' ) ;
13
13
const { connect : mongoConnect } = require ( '../db_connect' ) ;
14
14
15
15
mongoConnect ( ) ;
@@ -114,33 +114,32 @@ describe('Telegram bot test', () => {
114
114
const command = client . makeCommand ( '/listcurrencies' ) ;
115
115
const res = await client . sendCommand ( command ) ;
116
116
expect ( res . ok ) . to . be . equal ( true ) ;
117
- // const updates = await client.getUpdates();
118
- // userStub.restore();
119
- // expect(updates.ok).to.be.equal(true);
120
- // expect(
121
- // (updates.result[0].message.text.match(/\n/g) || []).length - 1
122
- // ).to.be.equal(getCurrenciesWithPrice().length);
117
+ const updates = await client . getUpdates ( ) ;
118
+ userStub . restore ( ) ;
119
+ expect ( updates . ok ) . to . be . equal ( true ) ;
120
+ expect (
121
+ ( updates . result [ 0 ] . message . text . match ( / \n / g) || [ ] ) . length - 1
122
+ ) . to . be . equal ( getCurrenciesWithPrice ( ) . length ) ;
123
123
} ) ;
124
124
125
- // it('should return flags of langs supported', async () => {
126
- // const client = server.getClient(token, { timeout: 5000 });
127
- // const userStub = sinon.stub(User, 'findOne');
128
- // userStub.returns(testUser);
129
- // const command = client.makeCommand('/setlang');
130
- // const res = await client.sendCommand(command);
131
- // console.log(res);
132
- // expect(res.ok).to.be.equal(true);
133
- // const updates = await client.getUpdates();
134
- // userStub.restore();
135
- // expect(updates.ok).to.be.equal(true);
136
- // let flags = 0;
137
- // updates.result[0].message.reply_markup.inline_keyboard.forEach(flag => {
138
- // flags += flag.length;
139
- // });
140
- // let langs = 0;
141
- // fs.readdirSync(path.join(__dirname, '../locales')).forEach(file => {
142
- // langs++;
143
- // });
144
- // expect(flags).to.be.equal(langs);
145
- // });
125
+ it ( 'should return flags of langs supported' , async ( ) => {
126
+ const client = server . getClient ( token , { timeout : 5000 } ) ;
127
+ const userStub = sinon . stub ( User , 'findOne' ) ;
128
+ userStub . returns ( testUser ) ;
129
+ const command = client . makeCommand ( '/setlang' ) ;
130
+ const res = await client . sendCommand ( command ) ;
131
+ expect ( res . ok ) . to . be . equal ( true ) ;
132
+ const updates = await client . getUpdates ( ) ;
133
+ userStub . restore ( ) ;
134
+ expect ( updates . ok ) . to . be . equal ( true ) ;
135
+ let flags = 0 ;
136
+ updates . result [ 0 ] . message . reply_markup . inline_keyboard . forEach ( flag => {
137
+ flags += flag . length ;
138
+ } ) ;
139
+ let langs = 0 ;
140
+ fs . readdirSync ( path . join ( __dirname , '../locales' ) ) . forEach ( file => {
141
+ langs ++ ;
142
+ } ) ;
143
+ expect ( flags ) . to . be . equal ( langs ) ;
144
+ } ) ;
146
145
} ) ;
0 commit comments