@@ -663,69 +663,76 @@ describe("panel builds", () => {
663663 } ) ;
664664
665665 describe ( "restartWorkspace" , ( ) => {
666- const versions = {
667- workspace : {
668- template_active_version_id : "v-new" ,
669- latest_build : { template_version_id : "v-original" } ,
670- } ,
671- } ;
672-
673- it ( "uses one on_success build on 2.36+ when the workspace is up to date" , async ( ) => {
674- const h = setup ( {
675- workspace : { outdated : false } ,
676- serverFeatures : { onSuccessBuild : true } ,
677- } ) ;
678- const queued = { ...h . workspace . latest_build , id : "server-start" } ;
679- h . client . getWorkspace . mockResolvedValueOnce ( {
680- ...h . workspace ,
681- latest_build : queued ,
682- } ) ;
683-
684- await expect (
685- restartWorkspace ( h . ctx , h . workspace , h . serverFeatures ) ,
686- ) . resolves . toBe ( queued ) ;
687- expect ( h . posted ( ) ) . toEqual ( [
688- {
689- transition : "stop" ,
690- on_success : { transition : "start" } ,
691- ...REASON ,
692- } ,
693- ] ) ;
694- expect ( h . client . waitForBuild . mock . calls ) . toEqual ( [
695- [ expect . objectContaining ( { id : "stop-build" } ) , h . ctx . signal ] ,
696- [ queued , h . ctx . signal ] ,
697- ] ) ;
698- } ) ;
699-
700- it . each ( [
666+ interface RestartCase {
667+ name : string ;
668+ outdated : boolean ;
669+ onSuccessBuild : boolean ;
670+ posted : CreateWorkspaceBuildRequest [ ] ;
671+ }
672+
673+ it . each < RestartCase > ( [
701674 {
702- when : "before 2.36" ,
703- overrides : versions ,
675+ name : "uses one on_success build on 2.36+ when up to date" ,
676+ outdated : false ,
677+ onSuccessBuild : true ,
678+ posted : [
679+ {
680+ transition : "stop" ,
681+ on_success : { transition : "start" } ,
682+ ...REASON ,
683+ } ,
684+ ] ,
704685 } ,
705686 {
706- when : "on 2.36+ when the workspace is outdated" ,
707- overrides : {
708- workspace : { ...versions . workspace , outdated : true } ,
709- serverFeatures : { onSuccessBuild : true } ,
710- } ,
687+ name : "stops then starts on the original version before 2.36" ,
688+ outdated : false ,
689+ onSuccessBuild : false ,
690+ posted : [
691+ { transition : "stop" , ...REASON } ,
692+ { transition : "start" , template_version_id : "v-original" , ...REASON } ,
693+ ] ,
711694 } ,
712- ] ) (
713- "waits for its stop, then starts on the original version $when" ,
714- async ( { overrides } ) => {
715- const h = setup ( overrides ) ;
716-
717- await restartWorkspace ( h . ctx , h . workspace , h . serverFeatures ) ;
718-
719- expect ( h . client . waitForBuild ) . toHaveBeenCalledTimes ( 2 ) ;
720- expect ( h . posted ( ) ) . toEqual ( [
695+ {
696+ name : "stops then starts on the original version on 2.36+ when outdated" ,
697+ outdated : true ,
698+ onSuccessBuild : true ,
699+ posted : [
721700 { transition : "stop" , ...REASON } ,
722701 { transition : "start" , template_version_id : "v-original" , ...REASON } ,
723- ] ) ;
702+ ] ,
724703 } ,
725- ) ;
704+ ] ) ( "$name" , async ( { outdated, onSuccessBuild, posted } ) => {
705+ const h = setup ( {
706+ workspace : {
707+ outdated,
708+ template_active_version_id : "v-new" ,
709+ latest_build : { template_version_id : "v-original" } ,
710+ } ,
711+ serverFeatures : { onSuccessBuild } ,
712+ } ) ;
713+ const queued = { ...h . workspace . latest_build , id : "server-start" } ;
714+ if ( posted . length === 1 ) {
715+ h . client . getWorkspace . mockResolvedValueOnce ( {
716+ ...h . workspace ,
717+ latest_build : queued ,
718+ } ) ;
719+ }
720+
721+ const result = await restartWorkspace (
722+ h . ctx ,
723+ h . workspace ,
724+ h . serverFeatures ,
725+ ) ;
726+
727+ expect ( h . posted ( ) ) . toEqual ( posted ) ;
728+ expect ( h . client . waitForBuild ) . toHaveBeenCalledTimes ( 2 ) ;
729+ if ( posted . length === 1 ) {
730+ expect ( result ) . toBe ( queued ) ;
731+ }
732+ } ) ;
726733
727734 it ( "does not start over a build that superseded its stop" , async ( ) => {
728- const h = setup ( versions ) ;
735+ const h = setup ( ) ;
729736 h . client . getWorkspace . mockResolvedValue (
730737 createWorkspace ( { latest_build : { id : "another-build" } } ) ,
731738 ) ;
@@ -737,7 +744,7 @@ describe("panel builds", () => {
737744 } ) ;
738745
739746 it ( "does not start once aborted" , async ( ) => {
740- const h = setup ( versions ) ;
747+ const h = setup ( ) ;
741748 h . abortAfterWait ( ) ;
742749
743750 await expect (
0 commit comments