-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Niloofar Sadeghi
committed
Jan 8, 2023
1 parent
f7e7986
commit f161c73
Showing
1 changed file
with
179 additions
and
202 deletions.
There are no files selected for viewing
381 changes: 179 additions & 202 deletions
381
packages/trader/src/Stores/Modules/Trading/Helpers/__tests__/proposal.js
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,212 +1,189 @@ | ||
// TODO refactor old tests in this component | ||
import React from 'react'; | ||
import * as Proposal from '../proposal'; | ||
import { getProposalInfo, createProposalRequests } from '../proposal'; | ||
|
||
describe('Proposal', () => { | ||
describe('getProposalInfo', () => { | ||
// const store = { | ||
// currency: 'EUR', | ||
// basis_list: [ | ||
// { | ||
// text: 'Payout', | ||
// value: 'payout', | ||
// }, | ||
// { | ||
// text: 'Stake', | ||
// value: 'stake', | ||
// }, | ||
// ], | ||
// basis: 'payout', | ||
// }; | ||
it('should return 0 as profit when proposal has error', () => { | ||
// const obj_prev_contract_basis = { | ||
// text: 'Payout', | ||
// value: 1234, | ||
// }; | ||
// const response = { | ||
// error: { | ||
// message: 'This is error', | ||
// }, | ||
// }; | ||
// expect(Proposal.getProposalInfo(store, response, obj_prev_contract_basis)).toEqual({ | ||
// profit: '0.00', | ||
// returns: '0.00%', | ||
// stake: undefined, | ||
// payout: undefined, | ||
// cancellation: undefined, | ||
// commission: undefined, | ||
// error_code: undefined, | ||
// error_field: undefined, | ||
// limit_order: undefined, | ||
// id: '', | ||
// message: 'This is error', | ||
// has_error: true, | ||
// has_error_details: false, | ||
// has_increased: false, | ||
// obj_contract_basis: { | ||
// text: 'Stake', | ||
// value: '', | ||
// }, | ||
// }); | ||
describe('getProposalInfo function', () => { | ||
const fake_store = { | ||
currency: 'EUR', | ||
basis_list: [ | ||
{ text: 'Payout', value: 'payout' }, | ||
{ text: 'Stake', value: 'stake' }, | ||
], | ||
basis: 'payout', | ||
}; | ||
|
||
const fake_obj_prev_contract_basis = { | ||
text: 'payout', | ||
value: 1234, | ||
}; | ||
|
||
it('should return 0 as profit when proposal has an error', () => { | ||
const fake_response = { | ||
error: { message: 'This is error' }, | ||
}; | ||
|
||
expect(getProposalInfo(fake_store, fake_response, fake_obj_prev_contract_basis)).toEqual({ | ||
profit: '0.00', | ||
returns: '0.00%', | ||
stake: undefined, | ||
payout: undefined, | ||
cancellation: undefined, | ||
commission: undefined, | ||
error_code: undefined, | ||
error_field: undefined, | ||
limit_order: undefined, | ||
id: '', | ||
message: 'This is error', | ||
has_error: true, | ||
has_error_details: false, | ||
has_increased: false, | ||
obj_contract_basis: { | ||
text: 'Stake', | ||
value: '', | ||
}, | ||
}); | ||
}); | ||
// it('should return profit and return calculated if proposal has no error', () => { | ||
// const response = { | ||
// proposal: { | ||
// proposal: 1, | ||
// ask_price: 50, | ||
// display_value: 200, | ||
// payout: 300, | ||
// id: 'id1', | ||
// longcode: 'This is a longcode', | ||
// }, | ||
// }; | ||
// const obj_prev_contract_basis = { | ||
// text: 'payout', | ||
// value: 1234, | ||
// }; | ||
// expect(Proposal.getProposalInfo(store, response, obj_prev_contract_basis)).toEqual({ | ||
// cancellation: undefined, | ||
// commission: undefined, | ||
// error_code: undefined, | ||
// error_field: undefined, | ||
// limit_order: undefined, | ||
// profit: '250.00', | ||
// returns: '500.00%', | ||
// stake: 200, | ||
// payout: 300, | ||
// id: 'id1', | ||
// message: 'This is a longcode', | ||
// has_error: false, | ||
// has_error_details: false, | ||
// has_increased: false, | ||
// obj_contract_basis: { | ||
// text: 'Stake', | ||
// value: 200, | ||
// }, | ||
// }); | ||
// }); | ||
}); | ||
|
||
// describe('createProposalRequests', () => { | ||
// it('should return request containing trade type which is not already in request', () => { | ||
// const store = { | ||
// amount: '10', | ||
// basis: 'payout', | ||
// currency: 'USD', | ||
// symbol: 'frxAUDJPY', | ||
// start_time: '12:30', | ||
// duration: '5', | ||
// duration_unit: 't', | ||
// trade_types: { | ||
// CALL: 'Higher', | ||
// PUT: 'Lower', | ||
// }, | ||
// expiry_type: 'duration', | ||
// form_components: ['duration', 'amount', 'start_date'], | ||
// root_store: { | ||
// client: { | ||
// currency: 'USD', | ||
// }, | ||
// }, | ||
// proposal_requests: { | ||
// CALL: { | ||
// amount: 10, | ||
// basis: 'payout', | ||
// contract_type: 'CALL', | ||
// currency: 'USD', | ||
// duration: 5, | ||
// duration_unit: 't', | ||
// proposal: 1, | ||
// req_id: 7, | ||
// subscribe: 1, | ||
// symbol: 'frxAUDJPY', | ||
// }, | ||
// }, | ||
// }; | ||
it('should return profit and return calculated if proposal has no error', () => { | ||
const fake_response = { | ||
proposal: { | ||
proposal: 1, | ||
ask_price: 50, | ||
display_value: 200, | ||
payout: 300, | ||
id: 'id1', | ||
longcode: 'This is a longcode', | ||
}, | ||
}; | ||
|
||
// expect(Proposal.createProposalRequests(store)).toEqual({ | ||
// CALL: { | ||
// amount: 10, | ||
// basis: 'payout', | ||
// contract_type: 'CALL', | ||
// currency: 'USD', | ||
// duration: 5, | ||
// duration_unit: 't', | ||
// proposal: 1, | ||
// subscribe: 1, | ||
// symbol: 'frxAUDJPY', | ||
// }, | ||
// PUT: { | ||
// proposal: 1, | ||
// subscribe: 1, | ||
// amount: 10, | ||
// basis: 'payout', | ||
// contract_type: 'PUT', | ||
// currency: 'USD', | ||
// symbol: 'frxAUDJPY', | ||
// duration: 5, | ||
// duration_unit: 't', | ||
// }, | ||
// }); | ||
// }); | ||
expect(getProposalInfo(fake_store, fake_response, fake_obj_prev_contract_basis)).toEqual({ | ||
cancellation: undefined, | ||
commission: undefined, | ||
error_code: undefined, | ||
error_field: undefined, | ||
limit_order: undefined, | ||
profit: '250.00', | ||
returns: '500.00%', | ||
stake: 200, | ||
payout: 300, | ||
id: 'id1', | ||
message: 'This is a longcode', | ||
has_error: false, | ||
has_error_details: false, | ||
has_increased: false, | ||
obj_contract_basis: { | ||
text: 'Stake', | ||
value: 200, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
// it('should return request as before if all trade types already exist in request', () => { | ||
// const store = { | ||
// amount: '10', | ||
// basis: 'payout', | ||
// currency: 'USD', | ||
// symbol: 'frxAUDJPY', | ||
// start_time: '12:30', | ||
// duration: '5', | ||
// duration_unit: 't', | ||
// trade_types: { | ||
// CALL: 'Higher', | ||
// }, | ||
// expiry_type: 'duration', | ||
// form_components: ['duration', 'amount', 'start_date'], | ||
// root_store: { | ||
// client: { | ||
// currency: 'USD', | ||
// }, | ||
// }, | ||
// proposal_requests: { | ||
// CALL: { | ||
// amount: 10, | ||
// basis: 'payout', | ||
// contract_type: 'CALL', | ||
// currency: 'USD', | ||
// duration: 5, | ||
// duration_unit: 't', | ||
// proposal: 1, | ||
// req_id: 7, | ||
// subscribe: 1, | ||
// symbol: 'frxAUDJPY', | ||
// }, | ||
// }, | ||
// }; | ||
describe('createProposalRequests function', () => { | ||
it('should return the request containing trade type which is not already in the request', () => { | ||
const fake_store = { | ||
amount: '10', | ||
basis: 'payout', | ||
currency: 'USD', | ||
symbol: 'frxAUDJPY', | ||
start_time: '12:30', | ||
duration: '5', | ||
duration_unit: 't', | ||
trade_types: { CALL: 'Higher', PUT: 'Lower' }, | ||
expiry_type: 'duration', | ||
form_components: ['duration', 'amount', 'start_date'], | ||
root_store: { client: { currency: 'USD' } }, | ||
proposal_requests: { | ||
CALL: { | ||
amount: 10, | ||
basis: 'payout', | ||
contract_type: 'CALL', | ||
currency: 'USD', | ||
duration: 5, | ||
duration_unit: 't', | ||
proposal: 1, | ||
req_id: 7, | ||
subscribe: 1, | ||
symbol: 'frxAUDJPY', | ||
}, | ||
}, | ||
}; | ||
|
||
// expect(Proposal.createProposalRequests(store)).toEqual({ | ||
// CALL: { | ||
// amount: 10, | ||
// basis: 'payout', | ||
// contract_type: 'CALL', | ||
// currency: 'USD', | ||
// duration: 5, | ||
// duration_unit: 't', | ||
// proposal: 1, | ||
// subscribe: 1, | ||
// symbol: 'frxAUDJPY', | ||
// }, | ||
// }); | ||
// }); | ||
expect(createProposalRequests(fake_store)).toEqual({ | ||
CALL: { | ||
amount: 10, | ||
basis: 'payout', | ||
contract_type: 'CALL', | ||
currency: 'USD', | ||
duration: 5, | ||
duration_unit: 't', | ||
proposal: 1, | ||
subscribe: 1, | ||
symbol: 'frxAUDJPY', | ||
}, | ||
PUT: { | ||
proposal: 1, | ||
subscribe: 1, | ||
amount: 10, | ||
basis: 'payout', | ||
contract_type: 'PUT', | ||
currency: 'USD', | ||
symbol: 'frxAUDJPY', | ||
duration: 5, | ||
duration_unit: 't', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return the request as before if all trade types already exist in the request', () => { | ||
const fake_store = { | ||
amount: '10', | ||
basis: 'payout', | ||
currency: 'USD', | ||
symbol: 'frxAUDJPY', | ||
start_time: '12:30', | ||
duration: '5', | ||
duration_unit: 't', | ||
trade_types: { CALL: 'Higher' }, | ||
expiry_type: 'duration', | ||
form_components: ['duration', 'amount', 'start_date'], | ||
root_store: { client: { currency: 'USD' } }, | ||
proposal_requests: { | ||
CALL: { | ||
amount: 10, | ||
basis: 'payout', | ||
contract_type: 'CALL', | ||
currency: 'USD', | ||
duration: 5, | ||
duration_unit: 't', | ||
proposal: 1, | ||
req_id: 7, | ||
subscribe: 1, | ||
symbol: 'frxAUDJPY', | ||
}, | ||
}, | ||
}; | ||
|
||
// it('should return empty if there is no trade type', () => { | ||
// const store = { | ||
// trade_types: {}, | ||
// proposal_requests: {}, | ||
// }; | ||
expect(createProposalRequests(fake_store)).toEqual({ | ||
CALL: { | ||
amount: 10, | ||
basis: 'payout', | ||
contract_type: 'CALL', | ||
currency: 'USD', | ||
duration: 5, | ||
duration_unit: 't', | ||
proposal: 1, | ||
subscribe: 1, | ||
symbol: 'frxAUDJPY', | ||
}, | ||
}); | ||
}); | ||
|
||
// expect(Proposal.createProposalRequests(store)).toHaveLength(0); | ||
// }); | ||
// }); | ||
it('should return an empty object if there is no trade type', () => { | ||
const fake_store = { | ||
trade_types: {}, | ||
proposal_requests: {}, | ||
}; | ||
expect(createProposalRequests(fake_store)).toEqual({}); | ||
}); | ||
}); | ||
}); |