@@ -36,65 +36,65 @@ module.exports = (createTempRepo) => {
3636    } ) 
3737
3838    beforeEach ( async  ( )  =>  { 
39-       ( {   instance :  repo  }   =  await  createTempRepo ( { } ) ) 
39+       repo  =  await  createTempRepo ( ) 
4040      sinon . reset ( ) 
4141    } ) 
4242
43-     it ( 'should migrate by default' ,  async  ( )  =>  { 
44-       migrateStub . resolves ( ) 
45-       repoVersionStub . value ( 8 ) 
46-       getLatestMigrationVersionStub . returns ( 9 ) 
47- 
48-       await  repo . version . set ( 7 ) 
49-       await  repo . close ( ) 
43+     // Testing migration logic 
44+     const  migrationLogic  =  [ 
45+       {  config : true ,  option : true ,  result : true  } , 
46+       {  config : true ,  option : false ,  result : false  } , 
47+       {  config : true ,  option : undefined ,  result : true  } , 
48+       {  config : false ,  option : true ,  result : true  } , 
49+       {  config : false ,  option : false ,  result : false  } , 
50+       {  config : false ,  option : undefined ,  result : false  } , 
51+       {  config : undefined ,  option : true ,  result : true  } , 
52+       {  config : undefined ,  option : false ,  result : false  } , 
53+       {  config : undefined ,  option : undefined ,  result : true  } , 
54+     ] 
55+ 
56+     migrationLogic . forEach ( ( {  config,  option,  result } )  =>  { 
57+       it ( `should ${ result  ? ''  : 'not ' } ${ config } ${ option }  ,  async  ( )  =>  { 
58+         migrateStub . resolves ( ) 
59+         repoVersionStub . value ( 8 ) 
60+         getLatestMigrationVersionStub . returns ( 9 ) 
61+ 
62+         if  ( config  !==  undefined )  { 
63+           await  repo . config . set ( 'repoAutoMigrate' ,  config ) 
64+         } 
65+         await  repo . version . set ( 7 ) 
66+         await  repo . close ( ) 
67+ 
68+         const  newOpts  =  Object . assign ( { } ,  repo . options ) 
69+         newOpts . autoMigrate  =  option 
70+         const  newRepo  =  new  IPFSRepo ( repo . path ,  newOpts ) 
5071
51-       expect ( migrateStub . called ) . to . be . false ( ) 
72+          expect ( migrateStub . called ) . to . be . false ( ) 
5273
53-       await  repo . open ( ) 
74+         try  { 
75+           await  newRepo . open ( ) 
76+           if  ( ! result )  expect . fail ( 'should have thrown error' ) 
77+         }  catch  ( err )  { 
78+           expect ( err . code ) . to . equal ( errors . InvalidRepoVersionError . code ) 
79+         } 
5480
55-       expect ( migrateStub . called ) . to . be . true ( ) 
81+         expect ( migrateStub . called ) . to . eq ( result ) 
82+       } ) 
5683    } ) 
5784
58-     it ( 'should not  migrate when option autoMigrate is false ' ,  async  ( )  =>  { 
85+     it ( 'should migrate by default ' ,  async  ( )  =>  { 
5986      migrateStub . resolves ( ) 
60-       repoVersionStub . resolves ( 8 ) 
87+       repoVersionStub . value ( 8 ) 
6188      getLatestMigrationVersionStub . returns ( 9 ) 
6289
6390      await  repo . version . set ( 7 ) 
6491      await  repo . close ( ) 
6592
66-       const  newOpts  =  Object . assign ( { } ,  repo . options ) 
67-       newOpts . autoMigrate  =  false 
68-       const  newRepo  =  new  IPFSRepo ( repo . path ,  newOpts ) 
69- 
70-       expect ( migrateStub . called ) . to . be . false ( ) 
71-       try  { 
72-         await  newRepo . open ( ) 
73-         expect . fail ( 'should have thrown error' ) 
74-       }  catch  ( err )  { 
75-         expect ( err . code ) . to . equal ( errors . InvalidRepoVersionError . code ) 
76-       } 
77- 
7893      expect ( migrateStub . called ) . to . be . false ( ) 
79-     } ) 
80- 
81-     it ( 'should not migrate when config option repoAutoMigrate is false' ,  async  ( )  =>  { 
82-       migrateStub . resolves ( ) 
83-       repoVersionStub . resolves ( 8 ) 
84-       getLatestMigrationVersionStub . returns ( 9 ) 
8594
86-       await  repo . config . set ( 'repoAutoMigrate' ,  false ) 
87-       await  repo . version . set ( 7 ) 
88-       await  repo . close ( ) 
95+       await  repo . open ( ) 
8996
90-       expect ( migrateStub . called ) . to . be . false ( ) 
91-       try  { 
92-         await  repo . open ( ) 
93-         expect . fail ( 'should have thrown error' ) 
94-       }  catch  ( err )  { 
95-         expect ( migrateStub . called ) . to . be . false ( ) 
96-         expect ( err . code ) . to . equal ( errors . InvalidRepoVersionError . code ) 
97-       } 
97+       expect ( migrateStub . called ) . to . be . true ( ) 
9898    } ) 
9999
100100    it ( 'should not migrate when versions matches' ,  async  ( )  =>  { 
0 commit comments