@@ -192,6 +192,120 @@ describe('UtilityemissionchannelGateway', () => {
192192 agent . close ( ) ;
193193 } ) ;
194194
195+ it ( 'should use emissions factors for the correct region' , async ( ) => {
196+ const mockUtilityID_DE = 'RWE_AG' ;
197+ const mockPartyID2 = uuid4 ( ) ;
198+ const usage = 100 ;
199+ const usage_uom_conversion = 1 / 1000 ;
200+ const agent = chai . request . agent ( 'http://127.0.0.1:5984' ) ;
201+
202+ const emissionUSA = await utilityEmissionsGateway . recordEmissions ( adminCaller , {
203+ utilityId : mockUtilityID ,
204+ partyId : mockPartyID2 ,
205+ fromDate : '2019-01-01T00:00:00Z' ,
206+ thruDate : '2019-01-31T00:00:00Z' ,
207+ energyUseAmount : usage ,
208+ energyUseUom : 'kWh' ,
209+ url : '' ,
210+ md5 : '' ,
211+ } ) ;
212+
213+ const emissionDE = await utilityEmissionsGateway . recordEmissions ( adminCaller , {
214+ utilityId : mockUtilityID_DE ,
215+ partyId : mockPartyID2 ,
216+ fromDate : '2019-01-01T00:00:00Z' ,
217+ thruDate : '2019-01-31T00:00:00Z' ,
218+ energyUseAmount : usage ,
219+ energyUseUom : 'kWh' ,
220+ url : '' ,
221+ md5 : '' ,
222+ } ) ;
223+
224+ emissionDE . emissionsAmount . should . not . eq ( emissionUSA . emissionsAmount ) ;
225+
226+ await agent . post ( '/_session' ) . set ( 'content-type' , 'application/json' ) . send ( {
227+ name : 'admin' ,
228+ password : 'adminpw' ,
229+ } ) ;
230+
231+ await agent
232+ . post ( '/utilityemissionchannel_utilityemissions/_find' )
233+ . set ( 'content-type' , 'application/json' )
234+ . send ( {
235+ selector : {
236+ class : {
237+ $eq : 'org.hyperledger.blockchain-carbon-accounting.utilityemissionsfactoritem' ,
238+ } ,
239+ division_id : {
240+ $eq : 'WECC' ,
241+ } ,
242+ division_type : {
243+ $eq : 'NERC_REGION' ,
244+ } ,
245+ year : {
246+ $eq : '2019' ,
247+ } ,
248+ } ,
249+ execution_stats : false ,
250+ } )
251+ . then ( ( response ) => {
252+ response . status . should . be . eq ( 200 ) ;
253+ const data = response . body ;
254+ const utilityFactor = data . docs [ 0 ] ;
255+ const emissions_uom_conversion = 1 ;
256+
257+ const emissions_value =
258+ ( Number ( utilityFactor . co2_equivalent_emissions ) /
259+ Number ( utilityFactor . net_generation ) ) *
260+ usage *
261+ usage_uom_conversion *
262+ emissions_uom_conversion ;
263+
264+ emissionUSA . emissionsAmount . should . be . eq ( emissions_value ) ;
265+ } ) ;
266+
267+ await agent
268+ . post ( '/utilityemissionchannel_utilityemissions/_find' )
269+ . set ( 'content-type' , 'application/json' )
270+ . send ( {
271+ selector : {
272+ class : {
273+ $eq : 'org.hyperledger.blockchain-carbon-accounting.utilityemissionsfactoritem' ,
274+ } ,
275+ division_id : {
276+ $eq : 'Germany' ,
277+ } ,
278+ division_type : {
279+ $eq : 'Country' ,
280+ } ,
281+ year : {
282+ $eq : '2019' ,
283+ } ,
284+ } ,
285+ execution_stats : false ,
286+ } )
287+ . then ( ( response ) => {
288+ response . status . should . be . eq ( 200 ) ;
289+ const data = response . body ;
290+ const utilityFactor = data . docs [ 0 ] ;
291+ const emissions_uom_conversion = 1000 ;
292+
293+ const emissions_value =
294+ Number ( utilityFactor . co2_equivalent_emissions ) *
295+ usage *
296+ ( usage_uom_conversion / emissions_uom_conversion ) ;
297+
298+ const percent_of_renewables = Number ( utilityFactor . percent_of_renewables ) / 100 ;
299+
300+ emissionDE . emissionsAmount . should . be . eq ( emissions_value ) ;
301+ emissionDE . renewableEnergyUseAmount . should . be . eq ( usage * percent_of_renewables ) ;
302+ emissionDE . nonrenewableEnergyUseAmount . should . be . eq (
303+ usage * ( 1 - percent_of_renewables ) ,
304+ ) ;
305+ } ) ;
306+ agent . close ( ) ;
307+ } ) ;
308+
195309 const mockTokenId = '0xMockToken' ;
196310 it ( 'should update token if for minted records' , async ( ) => {
197311 await utilityEmissionsGateway . updateEmissionsMintedToken ( adminCaller , {
@@ -269,7 +383,7 @@ describe('UtilityemissionchannelGateway', () => {
269383 thruDate : '2021-05-07T10:10:09Z' ,
270384 energyUseAmount : 100 ,
271385 energyUseUom : 'kWh' ,
272- url : 'localost :///tmp/filename' ,
386+ url : 'localhost :///tmp/filename' ,
273387 md5 : '' ,
274388 } ) ;
275389 const documentUrl = data . url ;
0 commit comments