Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#303 implemented and tested getByWebHookToken(...) #304

Merged
merged 1 commit into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/main/java/com/selfxdsd/storage/SelfProjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @todo #301:60min Implement methods rename(...) and getByWebHookToken(...) and
* write integration tests for them.
* @todo #303:60min Implement method rename(...) and write integration tests
* for it.
*/
public final class SelfProjects extends BasePaged implements Projects {

Expand Down Expand Up @@ -234,7 +234,22 @@ public Project getProjectById(

@Override
public Project getByWebHookToken(final String webHookToken) {
throw new UnsupportedOperationException("Not yet implemented");
return this.database.jooq()
.select()
.from(SLF_PROJECTS_XDSD)
.join(SLF_USERS_XDSD)
.on(
SLF_PROJECTS_XDSD.USERNAME.eq(SLF_USERS_XDSD.USERNAME).and(
SLF_PROJECTS_XDSD.PROVIDER.eq(SLF_USERS_XDSD.PROVIDER)
)
)
.join(SLF_PMS_XDSD)
.on(SLF_PROJECTS_XDSD.PMID.eq(SLF_PMS_XDSD.ID))
.where(SLF_PROJECTS_XDSD.WEBHOOK_TOKEN.eq(webHookToken))
.stream()
.map(rec -> projectFromRecord(rec, false))
.findFirst()
.orElse(null);
}

@Override
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/com/selfxdsd/storage/SelfProjectsITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ public void returnsNullIfProjectMissing() {
);
}

/**
* Returns a project by its WebHook Token.
*/
@Test
public void getsProjectByWebHookToken() {
final Projects projects = new SelfJooq(new H2Database()).projects();
final Project found = projects.getByWebHookToken("whtoken123");
MatcherAssert.assertThat(
found.repoFullName(),
Matchers.equalTo("amihaiemil/docker-java-api")
);
MatcherAssert.assertThat(
found.owner().username(),
Matchers.equalTo("amihaiemil")
);
MatcherAssert.assertThat(
found.projectManager().id(),
Matchers.equalTo(1)
);
MatcherAssert.assertThat(
found.projectManager().provider().name(),
Matchers.equalTo(Provider.Names.GITHUB)
);
}

/**
* Returns null the project is not found by webhook token.
*/
@Test
public void returnsNullIfProjectNotFountByWebHookToken() {
final Projects projects = new SelfJooq(new H2Database()).projects();
final Project found = projects.getByWebHookToken("missing-token-123");
MatcherAssert.assertThat(found, Matchers.nullValue());
}

/**
* SelfProjects can return the Projects owned by a certain User.
*/
Expand Down