@@ -300,4 +300,41 @@ describe("deployScript", () => {
300300 } ) ;
301301 } ) ;
302302 } ) ;
303+
304+ describe ( "backend script" , ( ) => {
305+ const meta = { id : "hello-world" , type : "backend" , run : "backendStartup" , title : "Hello World" } ;
306+ const content = `api.log("Hello from script-deployer!");` ;
307+ const mime = "application/javascript;env=backend" ;
308+
309+ it ( "creates a code note with #run label" , ( ) => {
310+ deployScript ( meta , content , mime , becca , notesService ) ;
311+
312+ const codeId = codeNoteId ( meta . id ) ;
313+ const codeNote = becca . notes [ codeId ] ;
314+
315+ expect ( codeNote ) . toBeDefined ( ) ;
316+ expect ( codeNote . type ) . toBe ( "code" ) ;
317+
318+ const runLabel = codeNote . getLabels ( ) . find ( ( a ) => a . name === "run" ) ;
319+ expect ( runLabel ) . toBeDefined ( ) ;
320+ expect ( runLabel ! . value ) . toBe ( "backendStartup" ) ;
321+ } ) ;
322+
323+ it ( "places the code note under scripts folder, no render note" , ( ) => {
324+ deployScript ( meta , content , mime , becca , notesService ) ;
325+
326+ const codeId = codeNoteId ( meta . id ) ;
327+ const codeNote = becca . notes [ codeId ] ;
328+ expect ( codeNote . getParentBranches ( ) . some ( ( b ) => b . parentNoteId === SCRIPTS_NOTE_ID ) ) . toBe ( true ) ;
329+ expect ( becca . notes [ renderNoteId ( meta . id ) ] ) . toBeUndefined ( ) ;
330+ } ) ;
331+
332+ it ( "does not set #run when run field is absent" , ( ) => {
333+ const metaNoRun = { id : "no-run" , type : "backend" , title : "No Run" } ;
334+ deployScript ( metaNoRun , content , mime , becca , notesService ) ;
335+
336+ const codeNote = becca . notes [ codeNoteId ( metaNoRun . id ) ] ;
337+ expect ( codeNote . getLabels ( ) . find ( ( a ) => a . name === "run" ) ) . toBeUndefined ( ) ;
338+ } ) ;
339+ } ) ;
303340} ) ;
0 commit comments