Skip to content

Commit

Permalink
Merge pull request #1222 from amihaiemil/1220
Browse files Browse the repository at this point in the history
#1220 Projects.getByWebHookToken removed
  • Loading branch information
amihaiemil committed Aug 28, 2021
2 parents 32a2e0f + 9cf0fa0 commit 4ce71b6
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 208 deletions.
7 changes: 0 additions & 7 deletions self-api/src/main/java/com/selfxdsd/api/Projects.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ Project getProjectById(
final String repoProvider
);

/**
* Get the Project with the specified webHookToken.
* @param webHookToken String WebHook Token.
* @return Project or null if no Project found.
*/
Project getByWebHookToken(final String webHookToken);

/**
* Get the Projects at the provided Page.
* @param page Page number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,6 @@ public Project getProjectById(
.orElse(null);
}

@Override
public Project getByWebHookToken(final String webHookToken) {
final Page page = super.current();
return this.projects.get()
.skip((page.getNumber() - 1) * page.getSize())
.limit(page.getSize())
.filter(p -> p.webHookToken().equals(webHookToken))
.findFirst()
.orElse(null);
}

@Override
public Projects page(final Paged.Page page) {
return new PmProjects(this.pmId, this.projects, this.storage, page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,6 @@ public Project getProjectById(
return found;
}

@Override
public Project getByWebHookToken(final String webHookToken) {
Project found = this.storage.projects().getByWebHookToken(
webHookToken
);
if(found != null) {
final String ownerUsername = found.owner().username();
if(!ownerUsername.equalsIgnoreCase(this.user.username())) {
found = null;
}
}
return found;
}

@Override
public Projects page(final Paged.Page page) {
return new UserProjects(this.user, this.projects, this.storage, page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ public Project getProjectById(
.findFirst().orElse(null);
}

@Override
public Project getByWebHookToken(final String webHookToken) {
throw new UnsupportedOperationException("Not yet implemented.");
}

@Override
public Projects page(final Paged.Page page) {
return new InMemoryProjects(this.storage, this.projects, page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,81 +357,6 @@ public void doesNotRemoveProjectIfNotOwnedBySamePm() {
Mockito.verify(toRemove, Mockito.times(0)).deactivate(repo);
}

/**
* Should find a project by its Webhook Token.
*/
@Test
public void projectByWebhookTokenFound() {
final Projects projects = new PmProjects(
1,
() -> List.of(
mockProject("john/test", "github", "wt-1"),
mockProject("john/test2", "github", "wt-2")
).stream(),
Mockito.mock(Storage.class)
);
final Project found = projects.getByWebHookToken("wt-1");
MatcherAssert.assertThat(
found.repoFullName(),
Matchers.equalTo("john/test")
);
MatcherAssert.assertThat(
found.provider(),
Matchers.equalTo("github")
);
}

/**
* Should return null if project is not found by webhook token.
*/
@Test
public void projectByWebHookTokenNotFound() {
final Projects projects = new PmProjects(
1, Stream::empty, Mockito.mock(Storage.class)
);
MatcherAssert.assertThat(
projects.getByWebHookToken("wt-1"),
Matchers.nullValue()
);
}

/**
* Should find a project by its webhook token in a random page.
*/
@Test
public void projectByWebHookTokenFoundInPage(){
final Project found = new PmProjects(1, () -> IntStream
.rangeClosed(1, 14)
.mapToObj(i -> mockProject("repo-" + i,
Provider.Names.GITHUB, "wt-" + i)),
Mockito.mock(Storage.class)
).page(new Paged.Page(2, 5)).getByWebHookToken("wt-7");
MatcherAssert.assertThat(
found.repoFullName(),
Matchers.equalTo("repo-7")
);
MatcherAssert.assertThat(
found.provider(),
Matchers.equalTo("github")
);
}

/**
* Should return null if project is not found by webhook token in the
* specified page, even though project exists in overall.
*/
@Test
public void existingProjectNotFoundByWebHookTokenInPage(){
final Project found = new PmProjects(
1, () -> IntStream
.rangeClosed(1, 14)
.mapToObj(i -> mockProject("repo-" + i,
Provider.Names.GITHUB, "wt-" + i)),
Mockito.mock(Storage.class)
).page(new Paged.Page(2, 5)).getByWebHookToken("wt-1");
MatcherAssert.assertThat(found, Matchers.nullValue());
}

/**
* Mock a User.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,102 +244,6 @@ public void projectByIdNotFound() {
);
}

/**
* Should find a project by it's webhook token.
*/
@Test
public void projectByWebHookToken() {
final User user = this.mockUser("mihai", "github");

final Project project = Mockito.mock(Project.class);
Mockito.when(project.owner()).thenReturn(user);
final Projects all = Mockito.mock(Projects.class);
Mockito.when(
all.getByWebHookToken("wt123")
).thenReturn(project);

final Storage storage = Mockito.mock(Storage.class);
Mockito.when(storage.projects()).thenReturn(all);

final Projects projects = new UserProjects(
user,
() -> List.of(
mockProject("mihai/test", "github", "wt123"),
mockProject("mihai/test2", "github", "wt124")
).stream(),
storage
);
final Project found = projects.getByWebHookToken("wt123");
MatcherAssert.assertThat(
found,
Matchers.is(project)
);
}

/**
* A Project is found but it belongs to another User so the
* method should return null.
*/
@Test
public void projectByWebHookTokenFoundButHasOtherOwner() {
final User mihai = this.mockUser("mihai", "github");
final User vlad = this.mockUser("vlad", "github");

final Project project = Mockito.mock(Project.class);
Mockito.when(project.owner()).thenReturn(vlad);
final Projects all = Mockito.mock(Projects.class);
Mockito.when(
all.getByWebHookToken("wt200")
).thenReturn(project);

final Storage storage = Mockito.mock(Storage.class);
Mockito.when(storage.projects()).thenReturn(all);

final Projects projects = new UserProjects(
mihai,
() -> List.of(
mockProject("mihai/test", "github", "wt123"),
mockProject("mihai/test2", "github", "wt124")
).stream(),
storage
);
final Project found = projects.getByWebHookToken("wt200");
MatcherAssert.assertThat(
found,
Matchers.nullValue()
);
}

/**
* Should return null is project is not found by webhook token.
*/
@Test
public void projectByWebHookTokenNotFound() {
final User user = this.mockUser("mihai", "github");

final Projects all = Mockito.mock(Projects.class);
Mockito.when(
all.getByWebHookToken("wt404")
).thenReturn(null);

final Storage storage = Mockito.mock(Storage.class);
Mockito.when(storage.projects()).thenReturn(all);

final Projects projects = new UserProjects(
user,
() -> List.of(
mockProject("mihai/test", "github", "wt123"),
mockProject("mihai/test2", "github", "wt124")
).stream(),
storage
);
final Project found = projects.getByWebHookToken("wt404");
MatcherAssert.assertThat(
found,
Matchers.nullValue()
);
}

/**
* We can remove a Project if it's owned by the same User.
*/
Expand Down

0 comments on commit 4ce71b6

Please sign in to comment.