@ -367,7 +367,11 @@ class OpenGroupManagerSpec: QuickSpec {
mockOGMCache . when { $0 . hasPerformedInitialPoll } . thenReturn ( [ : ] )
mockOGMCache . when { $0 . timeSinceLastPoll } . thenReturn ( [ : ] )
mockOGMCache . when { $0 . getTimeSinceLastOpen ( using : dependencies ) } . thenReturn ( 0 )
mockOGMCache
. when { [ dependencies = dependencies ! ] cache in
cache . getTimeSinceLastOpen ( using : dependencies )
}
. thenReturn ( 0 )
mockOGMCache . when { $0 . isPolling } . thenReturn ( false )
mockOGMCache . when { $0 . pollers } . thenReturn ( [ : ] )
@ -816,7 +820,7 @@ class OpenGroupManagerSpec: QuickSpec {
var didComplete : Bool = false // P r e v e n t m u l t i - t h r e a d i n g t e s t b u g s
mockStorage
. writePublisher FlatMap { ( db : Database ) -> AnyPublisher < Void , Error > in
. writePublisher { ( db : Database ) -> Bool in
openGroupManager
. add (
db ,
@ -827,6 +831,16 @@ class OpenGroupManagerSpec: QuickSpec {
dependencies : dependencies
)
}
. flatMap { successfullyAddedGroup in
openGroupManager . performInitialRequestsAfterAdd (
successfullyAddedGroup : successfullyAddedGroup ,
roomToken : " testRoom " ,
server : " testServer " ,
publicKey : TestConstants . serverPublicKey ,
calledFromConfigHandling : true , // D o n ' t t r i g g e r S e s s i o n U t i l l o g i c
dependencies : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -847,7 +861,7 @@ class OpenGroupManagerSpec: QuickSpec {
var didComplete : Bool = false // P r e v e n t m u l t i - t h r e a d i n g t e s t b u g s
mockStorage
. writePublisher FlatMap { ( db : Database ) -> AnyPublisher < Void , Error > in
. writePublisher { ( db : Database ) -> Bool in
openGroupManager
. add (
db ,
@ -858,6 +872,16 @@ class OpenGroupManagerSpec: QuickSpec {
dependencies : dependencies
)
}
. flatMap { successfullyAddedGroup in
openGroupManager . performInitialRequestsAfterAdd (
successfullyAddedGroup : successfullyAddedGroup ,
roomToken : " testRoom " ,
server : " testServer " ,
publicKey : TestConstants . serverPublicKey ,
calledFromConfigHandling : true , // D o n ' t t r i g g e r S e s s i o n U t i l l o g i c
dependencies : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -884,7 +908,7 @@ class OpenGroupManagerSpec: QuickSpec {
var didComplete : Bool = false // P r e v e n t m u l t i - t h r e a d i n g t e s t b u g s
mockStorage
. writePublisher FlatMap { ( db : Database ) -> AnyPublisher < Void , Error > in
. writePublisher { ( db : Database ) -> Bool in
openGroupManager
. add (
db ,
@ -897,6 +921,18 @@ class OpenGroupManagerSpec: QuickSpec {
dependencies : dependencies
)
}
. flatMap { successfullyAddedGroup in
openGroupManager . performInitialRequestsAfterAdd (
successfullyAddedGroup : successfullyAddedGroup ,
roomToken : " testRoom " ,
server : " testServer " ,
publicKey : TestConstants . serverPublicKey
. replacingOccurrences ( of : " c3 " , with : " 00 " )
. replacingOccurrences ( of : " b3 " , with : " 00 " ) ,
calledFromConfigHandling : true , // D o n ' t t r i g g e r S e s s i o n U t i l l o g i c
dependencies : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -940,7 +976,7 @@ class OpenGroupManagerSpec: QuickSpec {
var error : Error ?
mockStorage
. writePublisher FlatMap { ( db : Database ) -> AnyPublisher < Void , Error > in
. writePublisher { ( db : Database ) -> Bool in
openGroupManager
. add (
db ,
@ -951,6 +987,16 @@ class OpenGroupManagerSpec: QuickSpec {
dependencies : dependencies
)
}
. flatMap { successfullyAddedGroup in
openGroupManager . performInitialRequestsAfterAdd (
successfullyAddedGroup : successfullyAddedGroup ,
roomToken : " testRoom " ,
server : " testServer " ,
publicKey : TestConstants . serverPublicKey ,
calledFromConfigHandling : true , // D o n ' t t r i g g e r S e s s i o n U t i l l o g i c
dependencies : dependencies
)
}
. mapError { result -> Error in error . setting ( to : result ) }
. sinkAndStore ( in : & disposables )
@ -3334,15 +3380,16 @@ class OpenGroupManagerSpec: QuickSpec {
upload : false ,
defaultUpload : nil
)
let publisher = Future < [ OpenGroup API. Room ] , Error > { resolver in
resolver ( Result . success ( [ uniqueRoomInstance ] ) )
let publisher = Future < [ OpenGroup Manager. DefaultRoomInfo ] , Error > { resolver in
resolver ( Result . success ( [ ( uniqueRoomInstance , nil ) ] ) )
}
. shareReplay ( 1 )
. eraseToAnyPublisher ( )
mockOGMCache . when { $0 . defaultRoomsPublisher } . thenReturn ( publisher )
let publisher2 = OpenGroupManager . getDefaultRoomsIfNeeded ( using : dependencies )
expect ( publisher2 . firstValue ( ) ) . to ( equal ( publisher . firstValue ( ) ) )
expect ( publisher2 . firstValue ( ) ? . map { $0 . room } )
. to ( equal ( publisher . firstValue ( ) ? . map { $0 . room } ) )
}
it ( " stores the open group information " ) {
@ -3376,13 +3423,13 @@ class OpenGroupManagerSpec: QuickSpec {
}
it ( " fetches rooms for the server " ) {
var response : [ OpenGroup API. Room ] ?
var response : [ OpenGroup Manager. DefaultRoomInfo ] ?
OpenGroupManager . getDefaultRoomsIfNeeded ( using : dependencies )
. handleEvents ( receiveOutput : { ( data : [ OpenGroupAPI . Room ] ) in response = data } )
. handleEvents ( receiveOutput : { response = $0 } )
. sinkAndStore ( in : & disposables )
expect ( response )
expect ( response ?. map { $0 . room } )
. toEventually (
equal (
[
@ -3598,17 +3645,14 @@ class OpenGroupManagerSpec: QuickSpec {
. thenReturn ( [ OpenGroup . idFor ( roomToken : " testRoom " , server : " testServer " ) : publisher ] )
var result : Data ?
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : " testServer " ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveOutput : { result = $0 } )
. sinkAndStore ( in : & disposables )
@ -3617,17 +3661,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " does not save the fetched image to storage " ) {
var didComplete : Bool = false
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : " testServer " ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -3648,17 +3689,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " does not update the image update timestamp " ) {
var didComplete : Bool = false
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : " testServer " ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -3690,17 +3728,14 @@ class OpenGroupManagerSpec: QuickSpec {
}
dependencies = dependencies . with ( onionApi : TestNeverReturningApi . self )
let publisher = mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
let publisher = OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : " testServer " ,
existingData : nil ,
using : dependencies
)
}
publisher . sinkAndStore ( in : & disposables )
expect ( mockOGMCache )
@ -3716,17 +3751,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " fetches a new image if there is no cached one " ) {
var result : Data ?
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : OpenGroupAPI . defaultServer ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveOutput : { ( data : Data ) in result = data } )
. sinkAndStore ( in : & disposables )
@ -3736,17 +3768,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " saves the fetched image to storage " ) {
var didComplete : Bool = false
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : OpenGroupAPI . defaultServer ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -3768,17 +3797,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " updates the image update timestamp " ) {
var didComplete : Bool = false
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : OpenGroupAPI . defaultServer ,
existingData : nil ,
using : dependencies
)
}
. handleEvents ( receiveCompletion : { _ in didComplete = true } )
. sinkAndStore ( in : & disposables )
@ -3816,17 +3842,14 @@ class OpenGroupManagerSpec: QuickSpec {
it ( " retrieves the cached image " ) {
var result : Data ?
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : OpenGroupAPI . defaultServer ,
existingData : Data ( [ 2 , 3 , 4 ] ) ,
using : dependencies
)
}
. handleEvents ( receiveOutput : { ( data : Data ) in result = data } )
. sinkAndStore ( in : & disposables )
@ -3846,17 +3869,14 @@ class OpenGroupManagerSpec: QuickSpec {
var result : Data ?
mockStorage
. readPublisherFlatMap { ( db : Database ) -> AnyPublisher < Data , Error > in
OpenGroupManager
. roomImage (
db ,
fileId : " 1 " ,
for : " testRoom " ,
on : OpenGroupAPI . defaultServer ,
existingData : Data ( [ 2 , 3 , 4 ] ) ,
using : dependencies
)
}
. handleEvents ( receiveOutput : { ( data : Data ) in result = data } )
. sinkAndStore ( in : & disposables )