Skip to content

Commit

Permalink
#1208 remove Webhook change from StoredProject.rename(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 10, 2021
1 parent 86a0f26 commit 48865bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,25 +271,8 @@ public void rename(final String newName) {
+ " at " + provider + " to " + this.repoFullName.split("/")[0]
+ "/" + newName + "... "
);
final Webhooks hooks = this.projectManager.provider().repo(
this.repoFullName.split("/")[0],
this.repoFullName.split("/")[1]
).webhooks();
boolean noWebhooks = hooks.remove();
if(noWebhooks) {
LOG.debug("Successfully removed Webhooks! Renaming...");
final Project renamed = this.storage.projects()
.rename(this, newName);
LOG.debug("Project successfully renamed!");
boolean addedNewWebhook = hooks.add(renamed);
if(addedNewWebhook) {
LOG.debug("New Webhook successfully added!");
} else {
LOG.error("Failed to add new Webhook.");
}
} else {
LOG.error("Problem while removing webhooks. Rename aborted.");
}
this.storage.projects().rename(this, newName);
LOG.debug("Project successfully renamed!");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,78 +501,29 @@ public void canBeDeactivated() {
public void canBeRenamed() {
final Project renamed = Mockito.mock(Project.class);

final Webhooks hooks = Mockito.mock(Webhooks.class);
Mockito.when(hooks.remove()).thenReturn(true);

final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.webhooks()).thenReturn(hooks);

final Storage storage = Mockito.mock(Storage.class);
final Provider prov = Mockito.mock(Provider.class);
Mockito.when(prov.name()).thenReturn(Provider.Names.GITHUB);
Mockito.when(prov.repo("john", "test")).thenReturn(repo);

final User owner = Mockito.mock(User.class);
Mockito.when(owner.provider()).thenReturn(prov);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
Mockito.when(manager.provider()).thenReturn(prov);

final Project project = new StoredProject(
owner,
"john/test",
"wh123token",
manager,
Mockito.mock(ProjectManager.class),
storage
);

final Projects all = Mockito.mock(Projects.class);
Mockito.when(all.rename(project, "newName"))
.thenReturn(renamed);
Mockito.when(storage.projects()).thenReturn(all);
Mockito.when(hooks.add(renamed)).thenReturn(true);

project.rename("newName");

Mockito.verify(hooks, Mockito.times(1)).remove();
Mockito.verify(all, Mockito.times(1)).rename(project, "newName");
Mockito.verify(hooks, Mockito.times(1)).add(renamed);
}

/**
* StoredProject should not be renamed if we fail to remove the original
* Webhooks.
*/
@Test
public void doesNotRenameWhenWebhookRemovalFails() {
final Webhooks hooks = Mockito.mock(Webhooks.class);
Mockito.when(hooks.remove()).thenReturn(false);

final Repo repo = Mockito.mock(Repo.class);
Mockito.when(repo.webhooks()).thenReturn(hooks);

final Storage storage = Mockito.mock(Storage.class);
final Provider prov = Mockito.mock(Provider.class);
Mockito.when(prov.name()).thenReturn(Provider.Names.GITHUB);
Mockito.when(prov.repo("john", "test")).thenReturn(repo);

final User owner = Mockito.mock(User.class);
Mockito.when(owner.provider()).thenReturn(prov);
final ProjectManager manager = Mockito.mock(ProjectManager.class);
Mockito.when(manager.provider()).thenReturn(prov);

final Project project = new StoredProject(
owner,
"john/test",
"wh123token",
manager,
storage
);

project.rename("newName");

Mockito.verify(hooks, Mockito.times(1)).remove();
Mockito.verify(storage, Mockito.times(0)).projects();
Mockito.verify(hooks, Mockito.times(0)).add(Mockito.any());
}

/**
Expand Down

1 comment on commit 48865bb

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've closed the Issues [#1207] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.