def lockTest()

in app/services/DynamoChannelTests.scala [251:280]


  def lockTest(testName: String, channel: Channel, email: String, force: Boolean): ZIO[ZEnv, DynamoError, Unit] = {
    val lockStatus = LockStatus(
      locked = true,
      email = Some(email),
      timestamp = Some(OffsetDateTime.now())
    )
    val request = {
      val builder = UpdateItemRequest
        .builder
        .tableName(tableName)
        .key(buildKey(channel, testName))
        .updateExpression("set lockStatus = :lockStatus")
        .expressionAttributeValues(Map(
          ":lockStatus" -> jsonToDynamo(lockStatus.asJson),
        ).asJava)
        .expressionAttributeNames(Map("#name" -> "name").asJava)

      val itemExistsExpression = "attribute_exists(#name)" // only update if it already exists in the table
      if (!force) {
        // Check it isn't already locked
        builder.conditionExpression(s"$itemExistsExpression and attribute_not_exists(lockStatus.email)")
      } else {
        builder.conditionExpression(itemExistsExpression)
      }

      builder.build()
    }

    update(request)
  }