Skip to content

Commit

Permalink
chore: prepare 2.33.0 (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro authored May 9, 2023
2 parents 58e7e5e + a34cc3e commit 08f8e85
Show file tree
Hide file tree
Showing 81 changed files with 1,734 additions and 1,403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CommitHistoryChangesSpec

sleep((1 second).toMillis)

`check no hook exists`(project.id, user.accessToken)
`check hook cannot be found`(project.id, user.accessToken)

Then("the project and its datasets should be removed from the knowledge-graph")

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2023 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.graph.acceptancetests

import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Positive
import io.circe.Json
import io.renku.generators.CommonGraphGenerators.authUsers
import io.renku.generators.Generators.Implicits._
import io.renku.graph.acceptancetests.data.Project.Statistics.CommitsCount
import io.renku.graph.acceptancetests.data._
import io.renku.graph.acceptancetests.flows.{AccessTokenPresence, TSProvisioning}
import io.renku.graph.acceptancetests.testing.AcceptanceTestPatience
import io.renku.graph.acceptancetests.tooling.{AcceptanceSpec, ApplicationServices, ModelImplicits}
import io.renku.graph.model.EventsGenerators.commitIds
import io.renku.graph.model.events.EventStatusProgress
import io.renku.graph.model.testentities.generators.EntitiesGenerators._
import org.http4s.Status._
import org.scalatest.concurrent.Eventually

class ProjectStatusResourceSpec
extends AcceptanceSpec
with ModelImplicits
with ApplicationServices
with TSProvisioning
with AccessTokenPresence
with Eventually
with AcceptanceTestPatience {

private val numberOfEvents: Int Refined Positive = 5

Feature("Project Status API for a given project") {

val memberUser = authUsers.generateOne
val project =
dataProjects(renkuProjectEntities(visibilityPublic, creatorGen = cliShapedPersons).modify(removeMembers()),
CommitsCount(numberOfEvents.value)
).map(addMemberWithId(memberUser.id)).generateOne

Scenario("Call be a user who is not a member of the project") {

gitLabStub.addProject(project)

When("there's no webhook for a given project in GitLab")
And("project hasn't been activated (no trace of it in the EL)")

Given("the user is authenticated")
val someAuthUser = authUsers.generateOne
gitLabStub.addAuthenticated(someAuthUser)

When("the user who is not a member of the project is calling the Status API")
Then("the Status API should return NOT_FOUND")
webhookServiceClient.`GET projects/:id/events/status`(project.id, someAuthUser.accessToken).status shouldBe NotFound

When("a member of the project activates it")
gitLabStub.addAuthenticated(memberUser)
val commitId = commitIds.generateOne
gitLabStub.replaceCommits(project.id, commitId)
// making the triples generation be happy and not throwing exceptions to the logs
`GET <triples-generator>/projects/:id/commits/:id returning OK with some triples`(project, commitId)

webhookServiceClient.`POST projects/:id/webhooks`(project.id, memberUser.accessToken).status shouldBe Created

Then("the non-member user should get OK with 'activated' = true")
eventually {
val authUserResponse = webhookServiceClient.`GET projects/:id/events/status`(project.id, someAuthUser.accessToken)
authUserResponse.status shouldBe Ok
authUserResponse.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe true
}
}

Scenario("Call be a user who is a member of the project") {

When("there's no webhook for a given project in GitLab")
gitLabStub.addProject(project)

Given("the member is authenticated")
gitLabStub.addAuthenticated(memberUser)

Then("the member of the project calling the Status API should get OK with 'activated' = false")
val response = webhookServiceClient.`GET projects/:id/events/status`(project.id, memberUser.accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe false

When("there's a webhook created for the project")
And("there are events under processing")
val allCommitIds = commitIds.generateNonEmptyList(min = numberOfEvents, max = numberOfEvents)
gitLabStub.setupProject(project, allCommitIds.toList: _*)
mockCommitDataOnTripleGenerator(project, toPayloadJsonLD(project), allCommitIds)
`data in the Triples Store`(project, allCommitIds, memberUser.accessToken)

Then("the Status API should return OK with some status info")
eventually {
val response = webhookServiceClient.`GET projects/:id/events/status`(project.id, memberUser.accessToken)

response.status shouldBe Ok

val responseJson = response.jsonBody.hcursor
responseJson.downField("activated").as[Boolean].value shouldBe true

val progressObjCursor = responseJson.downField("progress").as[Json].fold(throw _, identity).hcursor
progressObjCursor.downField("done").as[Int].value shouldBe EventStatusProgress.Stage.Final.value
progressObjCursor.downField("total").as[Int].value shouldBe EventStatusProgress.Stage.Final.value
progressObjCursor.downField("percentage").as[Float].value shouldBe 100f

val detailsObjCursor = responseJson.downField("details").as[Json].fold(throw _, identity).hcursor
detailsObjCursor.downField("status").as[String].value shouldBe "success"
detailsObjCursor.downField("message").as[String].value shouldBe "triples store"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,24 @@

package io.renku.graph.acceptancetests

import data.Project.Statistics.CommitsCount
import data._
import flows.AccessTokenPresence
import io.circe.syntax.EncoderOps
import io.renku.generators.CommonGraphGenerators.authUsers
import io.renku.generators.Generators.Implicits._
import io.renku.graph.acceptancetests.data.Project.Statistics.CommitsCount
import io.renku.graph.acceptancetests.data._
import io.renku.graph.acceptancetests.flows.AccessTokenPresence
import io.renku.graph.acceptancetests.tooling.{AcceptanceSpec, ApplicationServices, ModelImplicits}
import io.renku.graph.model.EventsGenerators.commitIds
import io.renku.graph.model.testentities.cliShapedPersons
import io.renku.graph.model.testentities.generators.EntitiesGenerators._
import io.renku.http.client.AccessToken
import org.http4s.Status._
import tooling.{AcceptanceSpec, ApplicationServices, ModelImplicits}

class WebhookCreationSpec extends AcceptanceSpec with ModelImplicits with ApplicationServices with AccessTokenPresence {

Feature("A Graph Services hook can be created for a project") {

Scenario("Graph Services hook is present on the project in GitLab") {

val user = authUsers.generateOne
val project =
dataProjects(renkuProjectEntities(visibilityPublic, creatorGen = cliShapedPersons).modify(removeMembers()),
CommitsCount.zero
).map(addMemberWithId(user.id)).generateOne

Given("api user is authenticated")
gitLabStub.addAuthenticated(user)

Given("project is present in GitLab with has Graph Services hook")
gitLabStub.setupProject(project)

When("user does POST webhook-service/projects/:id/webhooks")
val response = webhookServiceClient.POST(s"projects/${project.id}/webhooks", user.accessToken)

Then("he should get OK response back")
response.status shouldBe Ok
}

Scenario("No Graph Services webhook on the project in GitLab") {
Scenario("No Graph Services webhook present on the project in GitLab") {

val user = authUsers.generateOne
val project =
Expand All @@ -71,15 +50,13 @@ class WebhookCreationSpec extends AcceptanceSpec with ModelImplicits with Applic
gitLabStub.addProject(project)

Given("some Commit exists for the project in GitLab")
givenAccessTokenPresentFor(project, user.accessToken)
val commitId = commitIds.generateOne
gitLabStub.replaceCommits(project.id, commitId)

// making the triples generation be happy and not throwing exceptions to the logs
`GET <triples-generator>/projects/:id/commits/:id returning OK with some triples`(project, commitId)

When("user does POST webhook-service/projects/:id/webhooks")
val response = webhookServiceClient.POST(s"projects/${project.id}/webhooks", user.accessToken)
When("the user does POST webhook-service/projects/:id/webhooks")
val response = webhookServiceClient.`POST projects/:id/webhooks`(project.id, user.accessToken)

Then("he should get CREATED response back")
response.status shouldBe Created
Expand All @@ -93,5 +70,26 @@ class WebhookCreationSpec extends AcceptanceSpec with ModelImplicits with Applic
.asInstanceOf[AccessToken]
.asJson
}

Scenario("Graph Services hook is present on the project in GitLab") {

val user = authUsers.generateOne
val project =
dataProjects(renkuProjectEntities(visibilityPublic, creatorGen = cliShapedPersons).modify(removeMembers()),
CommitsCount.zero
).map(addMemberWithId(user.id)).generateOne

Given("api user is authenticated")
gitLabStub.addAuthenticated(user)

Given("project is present in GitLab with has Graph Services hook")
gitLabStub.setupProject(project)

When("user does POST webhook-service/projects/:id/webhooks")
val response = webhookServiceClient.`POST projects/:id/webhooks`(project.id, user.accessToken)

Then("he should get OK response back")
response.status shouldBe Ok
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package io.renku.graph.acceptancetests

import io.circe.syntax.EncoderOps
import io.circe.syntax._
import io.renku.generators.CommonGraphGenerators._
import io.renku.generators.Generators.Implicits._
import io.renku.graph.acceptancetests.data.Project.Statistics.CommitsCount
Expand All @@ -34,11 +34,11 @@ class WebhookValidationEndpointSpec extends AcceptanceSpec with ApplicationServi

Scenario("There's a Graph Services hook on a Public project in GitLab") {

val user = authUsers.generateOne
val project =
dataProjects(renkuProjectEntities(visibilityPublic, creatorGen = cliShapedPersons).modify(removeMembers()),
CommitsCount.zero
).generateOne
val user = authUsers.generateOne
).map(addMemberWithId(user.id)).generateOne

Given("api user is authenticated")
gitLabStub.addAuthenticated(user)
Expand All @@ -55,11 +55,11 @@ class WebhookValidationEndpointSpec extends AcceptanceSpec with ApplicationServi

Scenario("There's no Graph Services hook on a Public project in GitLab") {

val user = authUsers.generateOne
val project =
dataProjects(renkuProjectEntities(visibilityPublic, creatorGen = cliShapedPersons).modify(removeMembers()),
CommitsCount.zero
).generateOne
val user = authUsers.generateOne
).map(addMemberWithId(user.id)).generateOne

Given("api user is authenticated")
gitLabStub.addAuthenticated(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,16 @@ trait TSProvisioning

def `wait for events to be processed`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion =
eventually {
val response = fetchProcessingStatus(projectId, accessToken)
val response = webhookServiceClient.`GET projects/:id/events/status`(projectId, accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe true
response.jsonBody.hcursor.downField("progress").downField("percentage").as[Double].value shouldBe 100d
}

def `check no hook exists`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion = eventually {
val response = fetchProcessingStatus(projectId, accessToken)
response.status shouldBe Ok
response.jsonBody.hcursor.downField("activated").as[Boolean].value shouldBe false
def `check hook cannot be found`(projectId: projects.GitLabId, accessToken: AccessToken): Assertion = eventually {
webhookServiceClient.`GET projects/:id/events/status`(projectId, accessToken).status shouldBe NotFound
}

private def fetchProcessingStatus(projectId: projects.GitLabId, accessToken: AccessToken) =
webhookServiceClient.fetchProcessingStatus(projectId, accessToken)

def `wait for the Fast Tract event`(projectId: projects.GitLabId)(implicit ioRuntime: IORuntime): Unit = eventually {

val sleepTime = 1 second
Expand Down
Loading

0 comments on commit 08f8e85

Please sign in to comment.