@@ -4,9 +4,9 @@ import { SpentHeightIndicators } from '../../../src/types/Coin';
4
4
import { ObjectId } from 'mongodb' ;
5
5
import sinon from 'sinon' ;
6
6
import { BlockStorage } from '../../../src/models/block' ;
7
- import { mockStorage } from '../../helpers/index.js' ;
7
+ import { mockStorage , mockModel } from '../../helpers/index.js' ;
8
8
9
- describe ( 'Coin Model' , function ( ) {
9
+ describe ( 'Coin Model' , function ( ) {
10
10
describe ( '_apiTransform' , ( ) => {
11
11
it ( 'should return the transform object with coin info' , ( ) => {
12
12
let id = new ObjectId ( ) ;
@@ -91,41 +91,41 @@ describe('Coin Model', function () {
91
91
sandbox . restore ( ) ;
92
92
} ) ;
93
93
94
- it ( 'should return an object with confirmed, unconfirmed, and balance when additional time parameter is passed in' , async ( ) => {
95
- let id = new ObjectId ( " 5c364e342ab5602e97a56f0e" ) ;
94
+ it ( 'should return an object with confirmed, unconfirmed, and balance when additional time parameter is passed in' , async ( ) => {
95
+ let id = new ObjectId ( ' 5c364e342ab5602e97a56f0e' ) ;
96
96
let chain = 'BTC' ;
97
97
let network = 'regtest' ;
98
98
let time = new Date ( ) . toISOString ( ) ;
99
99
let query = { wallets : id , 'wallets.0' : { $exists : true } } ;
100
- let matchObject = {
101
- " $or" : [
100
+ let matchObject = {
101
+ $or : [
102
102
{
103
- " spentHeight" : {
104
- " $gt" : 123
103
+ spentHeight : {
104
+ $gt : 123
105
105
}
106
106
} ,
107
107
{
108
- " spentHeight" : {
109
- " $lt" : 0
108
+ spentHeight : {
109
+ $lt : 0
110
110
}
111
111
}
112
112
] ,
113
- " mintHeight" : {
114
- " $lte" : 123
113
+ mintHeight : {
114
+ $lte : 123
115
115
} ,
116
- " wallets" : new ObjectId ( '5c364e342ab5602e97a56f0e' ) ,
117
- " wallets.0" : { ' $exists' : true } ,
118
- }
116
+ wallets : new ObjectId ( '5c364e342ab5602e97a56f0e' ) ,
117
+ ' wallets.0' : { $exists : true }
118
+ } ;
119
119
120
120
let blockModelHeight = { height : 123 } ;
121
- mockStorage ( [ { _id : 'confirmed' , balance : 123123 } , { _id : 'unconfirmed' , balance : 1 } ] ) ;
122
- Object . assign ( BlockStorage . collection . findOne , sandbox . stub ( ) . resolves ( blockModelHeight ) ) ;
121
+ mockModel ( 'coins' , [ { _id : 'confirmed' , balance : 123123 } , { _id : 'unconfirmed' , balance : 1 } ] ) ;
122
+ mockModel ( 'blocks' , blockModelHeight ) ;
123
123
let coinModelAggregateSpy = CoinStorage . collection . aggregate as sinon . SinonSpy ;
124
- let blockModelFindOneSpy = BlockStorage . collection . findOne as sinon . SinonSpy ;
124
+ let blockModelFindSpy = BlockStorage . collection . find as sinon . SinonSpy ;
125
125
126
- const result = await CoinStorage . getBalanceAtTime ( { query, time, chain, network} ) ;
127
- expect ( coinModelAggregateSpy . called ) . to . deep . equal ( true , " CoinStorage.aggregation should have been called" ) ;
128
- expect ( blockModelFindOneSpy . called ) . to . deep . equal ( true , 'BlockModel.findOne should have been called' ) ;
126
+ const result = await CoinStorage . getBalanceAtTime ( { query, time, chain, network } ) ;
127
+ expect ( coinModelAggregateSpy . called ) . to . deep . equal ( true , ' CoinStorage.aggregation should have been called' ) ;
128
+ expect ( blockModelFindSpy . called ) . to . deep . equal ( true , 'BlockModel.find should have been called' ) ;
129
129
expect ( coinModelAggregateSpy . getCall ( 0 ) . args [ 0 ] [ 0 ] . $match ) . to . deep . equal ( matchObject ) ;
130
130
expect ( result ) . to . has . property ( 'confirmed' ) ;
131
131
expect ( result ) . to . has . property ( 'unconfirmed' ) ;
@@ -143,20 +143,20 @@ describe('Coin Model', function () {
143
143
sandbox . restore ( ) ;
144
144
} ) ;
145
145
146
- it ( 'should return an object with confirmed, unconfirmed, and balance' , async ( ) => {
147
- let id = new ObjectId ( " 5c364e342ab5602e97a56f0e" ) ;
146
+ it ( 'should return an object with confirmed, unconfirmed, and balance' , async ( ) => {
147
+ let id = new ObjectId ( ' 5c364e342ab5602e97a56f0e' ) ;
148
148
let query = {
149
- " wallets" : id ,
150
- 'wallets.0' : { " $exists" : true } ,
151
- " spentHeight" : { " $lt" : 0 } ,
152
- " mintHeight" : { " $gt" : - 3 }
149
+ wallets : id ,
150
+ 'wallets.0' : { $exists : true } ,
151
+ spentHeight : { $lt : 0 } ,
152
+ mintHeight : { $gt : - 3 }
153
153
} ;
154
154
155
- mockStorage ( [ { _id : 'confirmed' , balance : 123123 } , { _id : 'unconfirmed' , balance : 1 } ] ) ;
155
+ mockStorage ( [ { _id : 'confirmed' , balance : 123123 } , { _id : 'unconfirmed' , balance : 1 } ] ) ;
156
156
let coinModelAggregateSpy = CoinStorage . collection . aggregate as sinon . SinonSpy ;
157
157
158
- const result = await CoinStorage . getBalance ( { query} ) ;
159
- expect ( coinModelAggregateSpy . called ) . to . deep . equal ( true , " CoinStorage.aggregation should have been called" ) ;
158
+ const result = await CoinStorage . getBalance ( { query } ) ;
159
+ expect ( coinModelAggregateSpy . called ) . to . deep . equal ( true , ' CoinStorage.aggregation should have been called' ) ;
160
160
expect ( coinModelAggregateSpy . getCall ( 0 ) . args [ 0 ] [ 0 ] . $match ) . to . deep . equal ( query ) ;
161
161
expect ( result ) . to . has . property ( 'confirmed' ) ;
162
162
expect ( result ) . to . has . property ( 'unconfirmed' ) ;
0 commit comments