Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eletallbetagouv committed Jan 22, 2025
1 parent 892b96c commit 6459f3c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ class SignalConsoComponents(

private val reportOrchestratorWithFakeMailer = buildReportOrchestrator(_ => Future.unit)

val openFoodFactsService = new OpenFoodFactsService
val openBeautyFactsService = new OpenBeautyFactsService
val barcodeProductRepository = new BarcodeProductRepository(dbConfig)
val gs1Service = new GS1Service(applicationConfiguration.gs1)
val openFoodFactsService = new OpenFoodFactsService
val openBeautyFactsService = new OpenBeautyFactsService
val barcodeProductRepository = new BarcodeProductRepository(dbConfig)
def gs1Service: GS1ServiceInterface = new GS1Service(applicationConfiguration.gs1)
val gs1AuthTokenActor: typed.ActorRef[actors.GS1AuthTokenActor.Command] = actorSystem.spawn(
GS1AuthTokenActor(gs1Service),
"gs1-auth-token-actor"
Expand Down
4 changes: 3 additions & 1 deletion app/models/report/sampledata/ReportGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import scala.util.Random

object ReportGenerator {

val sampleGtin = "3474341105842"

case class SampleReportBlueprint(
conso: ConsumerUser,
category: ReportCategory,
Expand Down Expand Up @@ -108,7 +110,7 @@ object ReportGenerator {
"Avez-vous déjà contacté le commerçant ou le fabricant pour ce problème :" -> "Oui",
"Description :" -> "Bonjour, Je souhaite signaler une erreur d'étiquetage d'un pain qui était censé être un pain aux figues mais qui était un pain \"sportif\" dans un mauvais emballage. Nous l'avons acheté à FRANCHOUILLE MAGASIN à Anse (69480) et c'est la deuxième fois que cela nous arrive. \nJe tiens à préciser que le pain sportif contient des fruits à coque, des allergènes qui peuvent provoquer un choc anaphylactique aux gens allergiques comportant un risque vital. Je considère cette erreur du Franchouille gravissime. Cela doit être signalé.\nCordialement"
),
barcodeProductGtin = Some("3474341105842")
barcodeProductGtin = Some(sampleGtin)
)

val reportReponseConso = SampleReportBlueprint(
Expand Down
68 changes: 67 additions & 1 deletion test/tasks/report/SampleDataGenerationTaskTest.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package tasks.report

import cats.implicits.toTraverseOps
import loader.SignalConsoComponents
import models.barcode.gs1.OAuthAccessToken
import models.company.CompanyWithAccess
import models.report.Report
import models.report.ReportStatus
import models.report.sampledata.ProUserGenerator._
import models.report.sampledata.ReportGenerator.sampleGtin
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
import play.api.Application
import play.api.ApplicationLoader
import play.api.libs.json.Json
import play.api.mvc.Results
import play.api.test.WithApplication
import services.GS1ServiceInterface
import utils.AppSpec
import utils.Fixtures
import utils.TestApp
Expand All @@ -25,7 +32,66 @@ class SampleDataGenerationTaskTest(implicit ee: ExecutionEnv)
with Results
with FutureMatchers {

val (app, components) = TestApp.buildApp()
val oauthAccessToken = OAuthAccessToken("dummyToken")
val exampleGs1Response = Json.parse("""
{
"isA": [
"gs1:Offer",
"s:Offer"
],
"itemOffered": {
"isA": [
"gs1:Product",
"s:Product"
],
"gtin": "3474341105842",
"brandOwner": {
"isA": [
"gs1:Organization",
"s:Organization"
],
"license": {
"key": "347434"
},
"companyName": "MONBANA",
"globalLocationNumber": "3014743400109"
},
"postalAddress": {
"isA": "gs1:PostalAddress",
"postalCode": "53500",
"addressCountry": "France",
"addressLocality": {
"lang": "fr",
"value": "ERNEE"
}
},
"additionalPartyIdentificationValue": "562100032"
}
}
""")
val mockGs1Service: GS1ServiceInterface = mock[GS1ServiceInterface]

mockGs1Service.authenticate(
) returns Future.successful(oauthAccessToken)

mockGs1Service.getProductByGTIN(
oauthAccessToken,
sampleGtin
) returns Future.successful(Right(Some(exampleGs1Response)))

class FakeApplicationLoader extends ApplicationLoader {
var components: SignalConsoComponents = _
override def load(context: ApplicationLoader.Context): Application = {
components = new SignalConsoComponents(context) {
override def gs1Service: GS1ServiceInterface = mockGs1Service
}
components.application
}
}

val appLoader = new FakeApplicationLoader()
val app: Application = TestApp.buildApp(appLoader)
val components: SignalConsoComponents = appLoader.components

lazy val reportRepository = components.reportRepository
lazy val sampleDataGenerationTask = components.sampleDataGenerationTask
Expand Down

0 comments on commit 6459f3c

Please sign in to comment.