1
- import CustomApi from 'binary-common-utils/lib/customApi' ;
1
+ import CustomApi from 'binary-common-utils/lib/customApi'
2
2
import { expect } from 'chai' ; // eslint-disable-line import/no-extraneous-dependencies
3
- import { observer } from 'binary-common-utils/lib/observer' ;
4
- import Bot from '../' ;
5
- import mockWebsocket from '../../../common/mock/websocket' ;
3
+ import { observer } from 'binary-common-utils/lib/observer'
4
+ import Bot from '../'
5
+ import mockWebsocket from '../../../common/mock/websocket'
6
6
7
7
describe ( 'Bot' , ( ) => {
8
8
const option = {
@@ -14,122 +14,122 @@ describe('Bot', () => {
14
14
duration : 5 ,
15
15
duration_unit : 't' ,
16
16
symbol : 'R_100' ,
17
- } ;
17
+ }
18
18
19
- let api ;
20
- let bot ;
21
- const token = 'nmjKBPWxM00E8Fh' ;
19
+ let api
20
+ let bot
21
+ const token = 'nmjKBPWxM00E8Fh'
22
22
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
23
- observer . eventActionMap = { } ;
24
- api = new CustomApi ( mockWebsocket ) ;
25
- bot = new Bot ( api ) ;
23
+ observer . eventActionMap = { }
24
+ api = new CustomApi ( mockWebsocket )
25
+ bot = new Bot ( api )
26
26
bot . initPromise . then ( ( ) => {
27
- done ( ) ;
28
- } ) ;
29
- } ) ;
27
+ done ( )
28
+ } )
29
+ } )
30
30
it ( 'initialize bot with the symbols' , ( ) => {
31
- const markets = bot . symbol . activeSymbols . getMarkets ( ) ;
31
+ const markets = bot . symbol . activeSymbols . getMarkets ( )
32
32
expect ( markets ) . to . be . an ( 'Object' )
33
- . and . to . have . property ( 'forex' ) ;
34
- } ) ;
33
+ . and . to . have . property ( 'forex' )
34
+ } )
35
35
describe ( 'Bot cannot start with a fake token' , ( ) => {
36
- let error ;
36
+ let error
37
37
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
38
38
observer . register ( 'api.error' , ( _error ) => {
39
- error = _error ;
40
- done ( ) ;
41
- } , true ) ;
42
- bot . start ( 'FakeToken' , null , null , null , null ) ;
43
- } ) ;
39
+ error = _error
40
+ done ( )
41
+ } , true )
42
+ bot . start ( 'FakeToken' , null , null , null , null )
43
+ } )
44
44
it ( 'fake token should cause an error' , ( ) => {
45
45
expect ( error ) . to . have . deep . property ( '.error.code' )
46
- . that . is . equal ( 'InvalidToken' ) ;
47
- } ) ;
48
- } ) ;
46
+ . that . is . equal ( 'InvalidToken' )
47
+ } )
48
+ } )
49
49
describe ( 'Start trading' , ( ) => {
50
50
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
51
51
observer . register ( 'bot.waiting_for_purchase' , ( ) => {
52
- done ( ) ;
53
- } , true ) ;
52
+ done ( )
53
+ } , true )
54
54
observer . register ( 'bot.stop' , ( ) => {
55
- bot . start ( token , option , ( ) => { } , ( ) => { } , ( ) => { } ) ;
56
- } , true ) ;
57
- bot . stop ( ) ;
58
- } ) ;
59
- it ( 'start bot with the token, option' , ( ) => { } ) ;
60
- } ) ;
55
+ bot . start ( token , option , ( ) => { } , ( ) => { } , ( ) => { } )
56
+ } , true )
57
+ bot . stop ( )
58
+ } )
59
+ it ( 'start bot with the token, option' , ( ) => { } )
60
+ } )
61
61
describe ( 'Start the trade without real after purchase and before purchase functions' , ( ) => {
62
62
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
63
63
observer . register ( 'bot.stop' , ( ) => {
64
64
bot . initPromise . then ( ( ) => {
65
65
observer . register ( 'bot.waiting_for_purchase' , ( ) => {
66
- done ( ) ;
67
- } , true ) ;
68
- bot . start ( token , option , ( ) => { } , ( ) => { } , ( ) => { } ) ;
69
- } ) ;
70
- } , true ) ;
71
- bot . stop ( ) ;
72
- } ) ;
73
- it ( 'It is possible to restart the trade' , ( ) => { } ) ;
74
- } ) ;
66
+ done ( )
67
+ } , true )
68
+ bot . start ( token , option , ( ) => { } , ( ) => { } , ( ) => { } )
69
+ } )
70
+ } , true )
71
+ bot . stop ( )
72
+ } )
73
+ it ( 'It is possible to restart the trade' , ( ) => { } )
74
+ } )
75
75
describe ( 'Start the trade with real after purchase and before purchase functions' , ( ) => {
76
- let finishedContractFromFinishFunction ;
77
- let finishedContractFromFinishSignal ;
78
- let numOfTicks = 0 ;
76
+ let finishedContractFromFinishFunction
77
+ let finishedContractFromFinishSignal
78
+ let numOfTicks = 0
79
79
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
80
- this . timeout ( '20000' ) ;
80
+ this . timeout ( '20000' )
81
81
observer . register ( 'bot.stop' , ( ) => {
82
82
bot . initPromise . then ( ( ) => {
83
83
observer . register ( 'bot.finish' , ( _finishedContractFromFinishSignal ) => {
84
- finishedContractFromFinishSignal = _finishedContractFromFinishSignal ;
85
- done ( ) ;
86
- } , true ) ;
84
+ finishedContractFromFinishSignal = _finishedContractFromFinishSignal
85
+ done ( )
86
+ } , true )
87
87
bot . start ( token , option , ( tick , proposals , _purchaseCtrl ) => {
88
- if ( ! _purchaseCtrl ) return ;
88
+ if ( ! _purchaseCtrl ) return
89
89
if ( ++ numOfTicks === 3 ) {
90
- _purchaseCtrl . purchase ( 'DIGITEVEN' ) ;
90
+ _purchaseCtrl . purchase ( 'DIGITEVEN' )
91
91
}
92
92
} , ( ) => { } , ( _finishedContract ) => {
93
- finishedContractFromFinishFunction = _finishedContract ;
94
- } ) ;
95
- } ) ;
96
- } , true ) ;
97
- bot . stop ( ) ;
98
- } ) ;
99
- it ( 'Before Purchase decides to purchase the trade' , ( ) => { } ) ;
93
+ finishedContractFromFinishFunction = _finishedContract
94
+ } )
95
+ } )
96
+ } , true )
97
+ bot . stop ( )
98
+ } )
99
+ it ( 'Before Purchase decides to purchase the trade' , ( ) => { } )
100
100
it ( 'Calls the after purchase function when trade is finished' , ( ) => {
101
- expect ( finishedContractFromFinishSignal ) . to . be . equal ( finishedContractFromFinishFunction ) ;
102
- } ) ;
103
- } ) ;
101
+ expect ( finishedContractFromFinishSignal ) . to . be . equal ( finishedContractFromFinishFunction )
102
+ } )
103
+ } )
104
104
describe ( 'Trade again' , ( ) => {
105
- let finishedContractFromFinishFunction ;
106
- let finishedContractFromFinishSignal ;
107
- let numOfTicks = 0 ;
105
+ let finishedContractFromFinishFunction
106
+ let finishedContractFromFinishSignal
107
+ let numOfTicks = 0
108
108
before ( function beforeAll ( done ) { // eslint-disable-line prefer-arrow-callback
109
109
bot . start ( token , option , ( tick , proposals , _purchaseCtrl ) => {
110
110
if ( ++ numOfTicks === 3 ) {
111
- _purchaseCtrl . purchase ( 'DIGITEVEN' ) ;
111
+ _purchaseCtrl . purchase ( 'DIGITEVEN' )
112
112
}
113
113
} , ( ) => { } , ( _finishedContract ) => {
114
- finishedContractFromFinishFunction = _finishedContract ;
115
- } ) ;
114
+ finishedContractFromFinishFunction = _finishedContract
115
+ } )
116
116
observer . register ( 'bot.stop' , ( _finishedContractFromFinishSignal ) => {
117
- finishedContractFromFinishSignal = _finishedContractFromFinishSignal ;
118
- done ( ) ;
119
- } , true ) ;
120
- bot . stop ( ) ;
121
- } ) ;
122
- it ( 'Before Purchase decides to purchase the trade' , ( ) => { } ) ;
117
+ finishedContractFromFinishSignal = _finishedContractFromFinishSignal
118
+ done ( )
119
+ } , true )
120
+ bot . stop ( )
121
+ } )
122
+ it ( 'Before Purchase decides to purchase the trade' , ( ) => { } )
123
123
it ( 'Calls the after purchase function when trade is finished' , ( ) => {
124
- expect ( finishedContractFromFinishSignal ) . to . be . equal ( finishedContractFromFinishFunction ) ;
125
- } ) ;
126
- } ) ;
124
+ expect ( finishedContractFromFinishSignal ) . to . be . equal ( finishedContractFromFinishFunction )
125
+ } )
126
+ } )
127
127
after ( function afterAll ( done ) { // eslint-disable-line prefer-arrow-callback
128
128
observer . register ( 'bot.stop' , ( ) => {
129
- observer . destroy ( ) ;
130
- api . destroy ( ) ;
131
- done ( ) ;
132
- } ) ;
133
- bot . stop ( ) ;
134
- } ) ;
135
- } ) ;
129
+ observer . destroy ( )
130
+ api . destroy ( )
131
+ done ( )
132
+ } )
133
+ bot . stop ( )
134
+ } )
135
+ } )
0 commit comments