@@ -168,12 +168,12 @@ lab.experiment('Tests Repository', function () {
168
168
} ) ;
169
169
} ) ;
170
170
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 ) {
172
172
genericQueryStub . returns ( Promise . resolve ( { affectedRows : 1 } ) ) ;
173
173
let tClone = Hoek . clone ( t ) ;
174
174
tClone [ 0 ] . testID = 123 ;
175
175
tClone [ 1 ] . testID = 321 ;
176
- tests . bulkUpdate ( pageID , tClone , false )
176
+ tests . bulkUpdate ( pageID , tClone , true )
177
177
. then ( results => {
178
178
const call1 = genericQueryStub . getCall ( 0 ) . args ;
179
179
const call2 = genericQueryStub . getCall ( 1 ) . args ;
@@ -186,6 +186,24 @@ lab.experiment('Tests Repository', function () {
186
186
} ) ;
187
187
} ) ;
188
188
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
+
189
207
lab . test ( 'deletes existing test if no title and no code' , function ( done ) {
190
208
genericQueryStub . returns ( Promise . resolve ( { affectedRows : 1 } ) ) ;
191
209
let tClone = Hoek . clone ( t ) ;
0 commit comments