@@ -168,12 +168,12 @@ lab.experiment('Tests Repository', function () {
168168 } ) ;
169169 } ) ;
170170
171- lab . test ( 'updates test if it is an existing test' , function ( done ) {
171+ lab . test ( 'updates test if it is an existing test and the same owner ' , function ( done ) {
172172 genericQueryStub . returns ( Promise . resolve ( { affectedRows : 1 } ) ) ;
173173 let tClone = Hoek . clone ( t ) ;
174174 tClone [ 0 ] . testID = 123 ;
175175 tClone [ 1 ] . testID = 321 ;
176- tests . bulkUpdate ( pageID , tClone , false )
176+ tests . bulkUpdate ( pageID , tClone , true )
177177 . then ( results => {
178178 const call1 = genericQueryStub . getCall ( 0 ) . args ;
179179 const call2 = genericQueryStub . getCall ( 1 ) . args ;
@@ -186,6 +186,24 @@ lab.experiment('Tests Repository', function () {
186186 } ) ;
187187 } ) ;
188188
189+ lab . test ( 'inserts new test if user is not the original owner' , function ( done ) {
190+ genericQueryStub . returns ( Promise . resolve ( { affectedRows : 1 } ) ) ;
191+ let tClone = Hoek . clone ( t ) ;
192+ tClone [ 0 ] . testID = 123 ;
193+ tClone [ 1 ] . testID = 321 ;
194+ tests . bulkUpdate ( pageID , tClone , false )
195+ . then ( results => {
196+ const call1 = genericQueryStub . getCall ( 0 ) . args ;
197+ const call2 = genericQueryStub . getCall ( 1 ) . args ;
198+ Code . expect ( call2 [ 0 ] ) . to . equal ( 'INSERT INTO ?? (??) VALUES (1, `t2`, `n`, `a = 2`)' ) ;
199+ Code . expect ( call2 [ 1 ] ) . to . equal ( [ 'tests' , [ 'pageID' , 'title' , 'defer' , 'code' ] ] ) ;
200+
201+ Code . expect ( call1 [ 0 ] ) . to . equal ( 'INSERT INTO ?? (??) VALUES (1, `t1`, `n`, `a = 1`)' ) ;
202+ Code . expect ( call1 [ 1 ] ) . to . equal ( [ 'tests' , [ 'pageID' , 'title' , 'defer' , 'code' ] ] ) ;
203+ done ( ) ;
204+ } ) ;
205+ } ) ;
206+
189207 lab . test ( 'deletes existing test if no title and no code' , function ( done ) {
190208 genericQueryStub . returns ( Promise . resolve ( { affectedRows : 1 } ) ) ;
191209 let tClone = Hoek . clone ( t ) ;
0 commit comments