@@ -283,6 +283,9 @@ pub trait BillServiceApi: Send + Sync {
283
283
async fn get_bills ( & self , current_identity_node_id : & str )
284
284
-> Result < Vec < BitcreditBillToReturn > > ;
285
285
286
+ /// Gets all bills from all identities
287
+ async fn get_bills_from_all_identities ( & self ) -> Result < Vec < BitcreditBillToReturn > > ;
288
+
286
289
/// Gets the combined bitcoin private key for a given bill
287
290
async fn get_combined_bitcoin_key_for_bill (
288
291
& self ,
@@ -1815,6 +1818,22 @@ impl BillServiceApi for BillService {
1815
1818
Ok ( result)
1816
1819
}
1817
1820
1821
+ async fn get_bills_from_all_identities ( & self ) -> Result < Vec < BitcreditBillToReturn > > {
1822
+ let mut res = vec ! [ ] ;
1823
+ let bill_ids = self . store . get_ids ( ) . await ?;
1824
+ let identity = self . identity_store . get ( ) . await ?;
1825
+ let current_timestamp = external:: time:: TimeApi :: get_atomic_time ( ) . await . timestamp ;
1826
+
1827
+ for bill_id in bill_ids {
1828
+ let bill = self
1829
+ . get_full_bill ( & bill_id, & identity, & identity. node_id , current_timestamp)
1830
+ . await ?;
1831
+ res. push ( bill)
1832
+ }
1833
+
1834
+ Ok ( res)
1835
+ }
1836
+
1818
1837
async fn get_bills (
1819
1838
& self ,
1820
1839
current_identity_node_id : & str ,
@@ -4081,6 +4100,87 @@ pub mod tests {
4081
4100
assert ! ( service. get_bill_keys( "test" ) . await . is_err( ) ) ;
4082
4101
}
4083
4102
4103
+ #[ tokio:: test]
4104
+ async fn get_bills_from_all_identities_baseline ( ) {
4105
+ let (
4106
+ mut storage,
4107
+ mut chain_storage,
4108
+ mut identity_storage,
4109
+ file_upload_storage,
4110
+ identity_chain_store,
4111
+ company_chain_store,
4112
+ contact_storage,
4113
+ company_storage,
4114
+ ) = get_storages ( ) ;
4115
+ let company_node_id = BcrKeys :: new ( ) . get_public_key ( ) ;
4116
+ let mut bill1 = get_baseline_bill ( "1234" ) ;
4117
+ bill1. drawee = IdentityPublicData :: new_only_node_id ( BcrKeys :: new ( ) . get_public_key ( ) ) ;
4118
+ bill1. drawer = IdentityPublicData :: new_only_node_id ( BcrKeys :: new ( ) . get_public_key ( ) ) ;
4119
+ bill1. payee = IdentityPublicData :: new ( get_baseline_identity ( ) . identity ) . unwrap ( ) ;
4120
+ let mut bill2 = get_baseline_bill ( "5555" ) ;
4121
+ bill2. drawee = IdentityPublicData :: new_only_node_id ( BcrKeys :: new ( ) . get_public_key ( ) ) ;
4122
+ bill2. drawer = IdentityPublicData :: new_only_node_id ( BcrKeys :: new ( ) . get_public_key ( ) ) ;
4123
+ bill2. payee = IdentityPublicData :: new_only_node_id ( company_node_id. clone ( ) ) ;
4124
+
4125
+ let mut notification_service = MockNotificationServiceApi :: new ( ) ;
4126
+
4127
+ identity_storage
4128
+ . expect_get ( )
4129
+ . returning ( || Ok ( get_baseline_identity ( ) . identity ) ) ;
4130
+ storage. expect_get_keys ( ) . returning ( |_| {
4131
+ Ok ( BillKeys {
4132
+ private_key : TEST_PRIVATE_KEY_SECP . to_owned ( ) ,
4133
+ public_key : TEST_PUB_KEY_SECP . to_owned ( ) ,
4134
+ } )
4135
+ } ) ;
4136
+ chain_storage
4137
+ . expect_get_chain ( )
4138
+ . withf ( |id| id == "1234" )
4139
+ . returning ( move |_| {
4140
+ let chain = get_genesis_chain ( Some ( bill1. clone ( ) ) ) ;
4141
+ Ok ( chain)
4142
+ } ) ;
4143
+ chain_storage
4144
+ . expect_get_chain ( )
4145
+ . withf ( |id| id == "5555" )
4146
+ . returning ( move |_| {
4147
+ let chain = get_genesis_chain ( Some ( bill2. clone ( ) ) ) ;
4148
+ Ok ( chain)
4149
+ } ) ;
4150
+ storage
4151
+ . expect_get_ids ( )
4152
+ . returning ( || Ok ( vec ! [ "1234" . to_string( ) , "5555" . to_string( ) ] ) ) ;
4153
+ storage. expect_is_paid ( ) . returning ( |_| Ok ( true ) ) ;
4154
+
4155
+ notification_service
4156
+ . expect_get_active_bill_notification ( )
4157
+ . returning ( |_| None ) ;
4158
+
4159
+ let service = get_service_base (
4160
+ storage,
4161
+ chain_storage,
4162
+ identity_storage,
4163
+ file_upload_storage,
4164
+ identity_chain_store,
4165
+ notification_service,
4166
+ company_chain_store,
4167
+ contact_storage,
4168
+ company_storage,
4169
+ ) ;
4170
+
4171
+ let res_personal = service
4172
+ . get_bills ( & get_baseline_identity ( ) . identity . node_id )
4173
+ . await ;
4174
+ let res_company = service. get_bills ( & company_node_id) . await ;
4175
+ let res_both = service. get_bills_from_all_identities ( ) . await ;
4176
+ assert ! ( res_personal. is_ok( ) ) ;
4177
+ assert ! ( res_company. is_ok( ) ) ;
4178
+ assert ! ( res_both. is_ok( ) ) ;
4179
+ assert ! ( res_personal. as_ref( ) . unwrap( ) . len( ) == 1 ) ;
4180
+ assert ! ( res_company. as_ref( ) . unwrap( ) . len( ) == 1 ) ;
4181
+ assert ! ( res_both. as_ref( ) . unwrap( ) . len( ) == 2 ) ;
4182
+ }
4183
+
4084
4184
#[ tokio:: test]
4085
4185
async fn get_bills_baseline ( ) {
4086
4186
let (
@@ -4093,8 +4193,71 @@ pub mod tests {
4093
4193
contact_storage,
4094
4194
company_storage,
4095
4195
) = get_storages ( ) ;
4196
+ let mut bill = get_baseline_bill ( "1234" ) ;
4197
+ bill. payee = IdentityPublicData :: new ( get_baseline_identity ( ) . identity ) . unwrap ( ) ;
4198
+
4096
4199
let mut notification_service = MockNotificationServiceApi :: new ( ) ;
4200
+
4201
+ identity_storage
4202
+ . expect_get ( )
4203
+ . returning ( || Ok ( get_baseline_identity ( ) . identity ) ) ;
4204
+ storage. expect_get_keys ( ) . returning ( |_| {
4205
+ Ok ( BillKeys {
4206
+ private_key : TEST_PRIVATE_KEY_SECP . to_owned ( ) ,
4207
+ public_key : TEST_PUB_KEY_SECP . to_owned ( ) ,
4208
+ } )
4209
+ } ) ;
4210
+ chain_storage. expect_get_chain ( ) . returning ( move |_| {
4211
+ let chain = get_genesis_chain ( Some ( bill. clone ( ) ) ) ;
4212
+ Ok ( chain)
4213
+ } ) ;
4214
+ storage
4215
+ . expect_get_ids ( )
4216
+ . returning ( || Ok ( vec ! [ "1234" . to_string( ) ] ) ) ;
4217
+ storage. expect_is_paid ( ) . returning ( |_| Ok ( true ) ) ;
4218
+
4219
+ notification_service
4220
+ . expect_get_active_bill_notification ( )
4221
+ . with ( eq ( "1234" ) )
4222
+ . returning ( |_| None ) ;
4223
+
4224
+ let service = get_service_base (
4225
+ storage,
4226
+ chain_storage,
4227
+ identity_storage,
4228
+ file_upload_storage,
4229
+ identity_chain_store,
4230
+ notification_service,
4231
+ company_chain_store,
4232
+ contact_storage,
4233
+ company_storage,
4234
+ ) ;
4235
+
4236
+ let res = service
4237
+ . get_bills ( & get_baseline_identity ( ) . identity . node_id )
4238
+ . await ;
4239
+ assert ! ( res. is_ok( ) ) ;
4240
+ let returned_bills = res. unwrap ( ) ;
4241
+ assert ! ( returned_bills. len( ) == 1 ) ;
4242
+ assert_eq ! ( returned_bills[ 0 ] . id, "1234" . to_string( ) ) ;
4243
+ }
4244
+
4245
+ #[ tokio:: test]
4246
+ async fn get_bills_baseline_company ( ) {
4247
+ let (
4248
+ mut storage,
4249
+ mut chain_storage,
4250
+ mut identity_storage,
4251
+ file_upload_storage,
4252
+ identity_chain_store,
4253
+ company_chain_store,
4254
+ contact_storage,
4255
+ company_storage,
4256
+ ) = get_storages ( ) ;
4097
4257
let company_node_id = BcrKeys :: new ( ) . get_public_key ( ) ;
4258
+ let mut bill = get_baseline_bill ( "1234" ) ;
4259
+ bill. payee = IdentityPublicData :: new ( get_baseline_identity ( ) . identity ) . unwrap ( ) ;
4260
+ let mut notification_service = MockNotificationServiceApi :: new ( ) ;
4098
4261
4099
4262
identity_storage
4100
4263
. expect_get ( )
0 commit comments