Skip to content

Commit

Permalink
toggle private build when stage type changes (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxzhu authored Nov 12, 2024
1 parent 520d3db commit 2a4f35c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public void update(

if (environBean.getStage_type() == EnvType.DEV) {
environBean.setAllow_private_build(true);
} else if (origBean.getStage_type() == EnvType.DEV) {
environBean.setAllow_private_build(false);
}
environBean.setEnv_name(origBean.getEnv_name());
environBean.setStage_name(origBean.getStage_name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setup() throws Exception {
}

@Test
public void createEnvStage() throws Exception {
public void updateEnvToDev_setsAllowPrivateBuildTrue() throws Exception {
ArgumentCaptor<EnvironBean> argument = ArgumentCaptor.forClass(EnvironBean.class);
EnvironBean envBean = new EnvironBean();
envBean.setStage_type(EnvType.DEV);
Expand All @@ -57,4 +57,22 @@ public void createEnvStage() throws Exception {
verify(environDAO).update(Mockito.any(), Mockito.any(), argument.capture());
assertEquals(true, argument.getValue().getAllow_private_build());
}

@Test
public void updateEnvStageOffDev_unsetsAllowPrivateBuild() throws Exception {
ArgumentCaptor<EnvironBean> argument = ArgumentCaptor.forClass(EnvironBean.class);
EnvironBean envBean = new EnvironBean();
EnvironBean origBean = new EnvironBean();
origBean.setAllow_private_build(true);
origBean.setStage_type(EnvType.DEV);
envBean.setStage_type(EnvType.STAGING);
Mockito.when(environDAO.getByStage(Mockito.anyString(), Mockito.anyString()))
.thenReturn(origBean);
SecurityContext mockSC = mock(SecurityContext.class);
Principal mockPrincipal = mock(Principal.class);
Mockito.when(mockSC.getUserPrincipal()).thenReturn(mockPrincipal);
envStages.update(mockSC, "test-env", "test-stage", envBean);
verify(environDAO).update(Mockito.any(), Mockito.any(), argument.capture());
assertEquals(false, argument.getValue().getAllow_private_build());
}
}

0 comments on commit 2a4f35c

Please sign in to comment.