@@ -34,13 +34,13 @@ testsuites.forEach(testsuite => {
3434 t . truthy ( sut . replicateMasterToDetail . run ) ;
3535 } ) ;
3636 test ( `[${ name } ] test REPLICATE_ATTRIBUTES` , async t =>
37- testReplicateAttributes ( sut , t ) ) ;
37+ testReplicateAttributes ( sut , t , name ) ) ;
3838 test ( `[${ name } ] test DELETE_REFERENCES` , async t =>
39- testDeleteReferences ( sut , t ) ) ;
39+ testDeleteReferences ( sut , t , name ) ) ;
4040 test ( `[${ name } ] test MAINTAIN_COUNT` , async t => testMaintainCount ( sut , t ) ) ;
4141} ) ;
4242
43- async function testReplicateAttributes ( sut , t ) {
43+ async function testReplicateAttributes ( sut , t , name ) {
4444 // Add a couple of detail documents to follow master
4545 const masterId = makeid ( ) ;
4646 await db . collection ( 'detail1' ) . add ( { masterId : masterId } ) ;
@@ -62,11 +62,13 @@ async function testReplicateAttributes(sut, t) {
6262 setState ( { change : null , context : null } ) ;
6363 await wrapped ( change , { params : { masterId : masterId } } ) ;
6464
65- // Assert pre-hook was called
66- const state = getState ( ) ;
67- t . truthy ( state . change ) ;
68- t . truthy ( state . context ) ;
69- t . is ( state . context . params . masterId , masterId ) ;
65+ // Assert pre-hook was called (only for rules-in-situ)
66+ if ( name === 'rules-in-situ' ) {
67+ const state = getState ( ) ;
68+ t . truthy ( state . change ) ;
69+ t . truthy ( state . context ) ;
70+ t . is ( state . context . params . masterId , masterId ) ;
71+ }
7072
7173 // Assert that attributes get replicated to detail documents
7274 await assertQuerySizeEventually (
@@ -95,7 +97,7 @@ async function testReplicateAttributes(sut, t) {
9597 await t . pass ( ) ;
9698}
9799
98- async function testDeleteReferences ( sut , t ) {
100+ async function testDeleteReferences ( sut , t , name ) {
99101 // Create some docs referencing master doc
100102 const masterId = makeid ( ) ;
101103 await db . collection ( 'detail1' ) . add ( { masterId : masterId } ) ;
@@ -117,11 +119,13 @@ async function testDeleteReferences(sut, t) {
117119 setState ( { snap : null , context : null } ) ;
118120 await wrapped ( snap , { params : { masterId : masterId } } ) ;
119121
120- // Assert pre-hook was called
121- const state = getState ( ) ;
122- t . truthy ( state . snap ) ;
123- t . truthy ( state . context ) ;
124- t . is ( state . context . params . masterId , masterId ) ;
122+ // Assert pre-hook was called (only for rules-in-situ)
123+ if ( name === 'rules-in-situ' ) {
124+ const state = getState ( ) ;
125+ t . truthy ( state . snap ) ;
126+ t . truthy ( state . context ) ;
127+ t . is ( state . context . params . masterId , masterId ) ;
128+ }
125129
126130 // Assert referencing docs were deleted
127131 await assertQuerySizeEventually (
@@ -199,16 +203,16 @@ async function testMaintainCount(sut, t) {
199203}
200204
201205test ( 'test error conditions' , async t => {
202- t . throws ( ( ) => integrify ( { } ) , / I n p u t m u s t b e r u l e o r c o n f i g / i) ;
203- t . throws (
204- ( ) => integrify ( { rule : 'UNKNOWN_RULE_4a4e261a2e37' } ) ,
205- / U n k n o w n r u l e / i
206- ) ;
207- t . throws ( ( ) => require ( './functions-bad-rules-file' ) , / U n k n o w n r u l e / i) ;
208- t . throws (
209- ( ) => require ( './functions-absent-rules-file' ) ,
210- / R u l e s f i l e n o t f o u n d / i
211- ) ;
206+ t . throws ( ( ) => integrify ( { } ) , { message : / I n p u t m u s t b e r u l e o r c o n f i g / i } ) ;
207+ t . throws ( ( ) => integrify ( { rule : 'UNKNOWN_RULE_4a4e261a2e37' } ) , {
208+ message : / U n k n o w n r u l e / i ,
209+ } ) ;
210+ t . throws ( ( ) => require ( './functions-bad-rules-file' ) , {
211+ message : / U n k n o w n r u l e / i,
212+ } ) ;
213+ t . throws ( ( ) => require ( './functions-absent-rules-file' ) , {
214+ message : / R u l e s f i l e n o t f o u n d / i,
215+ } ) ;
212216
213217 t . pass ( ) ;
214218} ) ;
0 commit comments