Skip to content

Commit

Permalink
TRELLO-2537 : fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssedoudbgouv committed Sep 29, 2024
1 parent 46f2cab commit 023cdd9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 38 deletions.
19 changes: 18 additions & 1 deletion app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import org.apache.pekko.actor.typed
import org.apache.pekko.actor.typed.scaladsl.adapter.ClassicActorSystemOps
import org.apache.pekko.util.Timeout
import authentication._
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import config._
Expand Down Expand Up @@ -248,7 +251,21 @@ class SignalConsoComponents(
amazonBucketName = applicationConfiguration.amazonBucketName
)

val s3Service: S3ServiceInterface = new S3Service()
private val awsS3Client: AmazonS3 = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(
new EndpointConfiguration("https://cellar-c2.services.clever-cloud.com", "us-east-1")
)
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials(
bucketConfiguration.keyId,
bucketConfiguration.secretKey
)
)
)
.build()
def s3Service: S3ServiceInterface = new S3Service(awsS3Client)

// Actor
val antivirusScanActor: typed.ActorRef[AntivirusScanActor.ScanCommand] = actorSystem.spawn(
Expand Down
21 changes: 2 additions & 19 deletions app/services/S3Service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import org.apache.pekko.util.ByteString

import java.nio.file.Path
import com.amazonaws.HttpMethod
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest
import com.amazonaws.services.s3.model.ResponseHeaderOverrides
import config.BucketConfiguration
Expand All @@ -25,7 +22,7 @@ import play.api.Logger
import scala.concurrent.ExecutionContext
import scala.concurrent.Future

class S3Service(implicit
class S3Service(awsS3Client: AmazonS3)(implicit
val materializer: Materializer,
val executionContext: ExecutionContext,
val bucketConfiguration: BucketConfiguration
Expand All @@ -34,20 +31,6 @@ class S3Service(implicit
private[this] val bucketName = bucketConfiguration.amazonBucketName

private val pekkoS3Client = S3
private val awsS3Client = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(
new EndpointConfiguration("https://cellar-c2.services.clever-cloud.com", "us-east-1")
)
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials(
bucketConfiguration.keyId,
bucketConfiguration.secretKey
)
)
)
.build()

override def upload(bucketKey: String): Sink[ByteString, Future[MultipartUploadResult]] =
pekkoS3Client.multipartUpload(bucketName, bucketKey)
Expand Down
22 changes: 5 additions & 17 deletions test/controllers/ReportControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ import play.api.mvc.Results
import play.api.test.Helpers._
import play.api.test._
import repositories.event.EventFilter
import services.S3ServiceInterface
import utils.Constants.ActionEvent.CONSUMER_THREATEN_BY_PRO
import utils.Constants.ActionEvent.POST_ACCOUNT_ACTIVATION_DOC
import utils.Constants.ActionEvent.REFUND_BLACKMAIL
import utils.Constants.ActionEvent.OTHER_REASON_DELETE_REQUEST
import utils.Constants.ActionEvent.SOLVED_CONTRACTUAL_DISPUTE
import utils.Constants.EventType
import utils.EmailAddress
import utils.Fixtures
import utils.TestApp
import utils.{EmailAddress, Fixtures, S3ServiceMock, TestApp}
import utils.AuthHelpers._

import java.time.temporal.ChronoUnit
Expand Down Expand Up @@ -299,20 +298,9 @@ class ReportControllerSpec(implicit ee: ExecutionEnv) extends Specification with
super.configuration
)

// override val s3Service: S3ServiceInterface = {
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// println(s"------------------ = /////////////////////////////////////// ------------------")
// new S3ServiceMock()
// }
override def s3Service: S3ServiceInterface = {
new S3ServiceMock()
}
override def tokenConfiguration =
TokenConfiguration(None, None, 12.hours, Period.ofDays(60), Period.ZERO, None, Period.ZERO)
override def uploadConfiguration = UploadConfiguration(Seq.empty, false, "/tmp")
Expand Down
2 changes: 1 addition & 1 deletion test/utils/AppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DefaultApplicationLoader(
override def load(context: ApplicationLoader.Context): Application = {
components = new SignalConsoComponents(context) {

override val s3Service =
override def s3Service =
new S3ServiceMock()

override lazy val mailRetriesService: MailRetriesService = mailRetriesServiceMock
Expand Down

0 comments on commit 023cdd9

Please sign in to comment.