Skip to content

Commit

Permalink
FIX front tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed May 13, 2024
1 parent 1b82d7d commit 5942c62
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions daikoku/app/controllers/AdminApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.apache.pekko.http.scaladsl.util.FastFuture
import org.apache.pekko.stream.Materializer
import org.apache.pekko.stream.scaladsl.Source
import org.apache.pekko.util.ByteString
import org.joda.time.DateTime
import play.api.http.HttpEntity
import play.api.libs.json._
import play.api.libs.streams.Accumulator
Expand Down Expand Up @@ -148,7 +149,15 @@ class StateController(
AuditTrailEvent(s"@{user.name} has accessed state of anonymous reporting")
)(ctx) {
env.dataStore.reportsInfoRepo.findAll()
.map(info => Ok(Json.obj("activated" -> info.head.activated, "id" -> info.head.id.value, "date" -> info.head.date, "message" -> "info fetched correctly"))
.map(info => {
val date: Long = info.headOption.flatMap(_.date).getOrElse(DateTime.now().getMillis)
Ok(Json.obj(
"activated" -> info.headOption.exists(_.activated),
"id" -> info.headOption.map(_.id.asJson).getOrElse(JsNull).as[JsValue],
"date" -> date,
"message" -> "info fetched correctly"
))
}
)
}
}
Expand All @@ -160,7 +169,7 @@ class StateController(
val body = ctx.request.body.as[JsObject]
for {
maybeDate <- env.dataStore.reportsInfoRepo.findAll().map(info => info.head.date)
_ <- env.dataStore.reportsInfoRepo.save(ReportsInfo(DatastoreId((body \ "id").as[String]), (body \ "value").as[Boolean], (body \ "currentDate").asOpt[Double] match {
_ <- env.dataStore.reportsInfoRepo.save(ReportsInfo(DatastoreId((body \ "id").as[String]), (body \ "value").as[Boolean], (body \ "currentDate").asOpt[Long] match {
case Some(value) => Some(value)
case None => maybeDate
}))
Expand Down
2 changes: 1 addition & 1 deletion daikoku/app/domain/entities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ case class Evolution(
case class ReportsInfo(
id: DatastoreId,
activated: Boolean,
date: Option[Double] = None,
date: Option[Long] = None,
) extends CanJson[ReportsInfo] {
override def asJson: JsValue = json.ReportsInfoFormat.writes(this)
}
2 changes: 1 addition & 1 deletion daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4343,7 +4343,7 @@ object json {
JsSuccess(ReportsInfo(
(json \ "_id").as(DatastoreIdFormat),
(json \ "activated").as[Boolean],
(json \ "date").asOpt[Double]
(json \ "date").asOpt[Long]
))
} recover {
case e => JsError(e.getMessage)
Expand Down
2 changes: 1 addition & 1 deletion daikoku/javascript/tests/completeJourney.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test('test a complete user journey', async ({ page }) => {


await page.getByRole('heading', { name: 'second test api' }).click();
await expect(page.locator('section')).toContainText('second test api');
await expect(page.locator('h1.jumbotron-heading')).toContainText('second test api');
await expect(page.locator('#a-new-test-api')).toContainText('A new test API');
await page.getByText('Plans').click();
await expect(page.locator('#usage-plans__list')).toContainText('dev plan');
Expand Down
2 changes: 1 addition & 1 deletion daikoku/javascript/tests/connectedUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ test('API admin can transfer his own API ownership', async ({ page }) => {
await page.getByRole('link', { name: 'Daikoku home' }).click();
await page.locator('h3').filter({ hasText: 'test API' }).waitFor({ state: 'visible' })
await page.locator('small').filter({ hasText: 'Consumers' }).click();
await expect(page.locator('.preview')).toContainText('test API');
await expect(page.locator('h3')).toContainText('test API');
});

test('Filter API List', async ({page, request}) => {
Expand Down

0 comments on commit 5942c62

Please sign in to comment.