All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.gianluigip.spectacle.report.publisher.central.CentralSpecPublisher.kt Maven / Gradle / Ivy

The newest version!
package io.gianluigip.spectacle.report.publisher.central

import io.gianluigip.spectacle.report.config.ReportConfiguration
import io.gianluigip.spectacle.report.utils.removeStartAndEndSpacesOnEachLine
import io.gianluigip.spectacle.specification.Specification
import io.gianluigip.spectacle.specification.api.model.FeatureToUpdateRequest
import io.gianluigip.spectacle.specification.api.model.SpecificationToUpdateRequest
import io.gianluigip.spectacle.specification.api.model.SpecificationsToUpdateRequest

object CentralSpecPublisher {

    suspend fun publishSpecs(specifications: List, centralClient: CentralClient, config: ReportConfiguration) {
        val requestBody = generateRequestBody(specifications, config)
        centralClient.putSpecs(requestBody)
    }

    private fun generateRequestBody(specifications: List, config: ReportConfiguration): SpecificationsToUpdateRequest {
        val features = mutableListOf()
        val specificationsByFeature = specifications.groupBy { it.metadata.featureName }.entries.sortedBy { it.key }
        specificationsByFeature.forEach { (_, specsInFeature) ->
            val featureMetadata = specsInFeature.first().metadata
            val specs = mutableListOf()
            specsInFeature.forEach { spec ->
                val specMetadata = spec.metadata
                val specToUpdate = SpecificationToUpdateRequest(
                    name = spec.name, team = specMetadata.team, status = spec.metadata.status, tags = specMetadata.tags,
                    steps = spec.steps, interactions = spec.interactions,
                )
                specs.add(specToUpdate)
            }
            val featureToUpdate = FeatureToUpdateRequest(
                name = featureMetadata.featureName,
                description = featureMetadata.featureDescription.removeStartAndEndSpacesOnEachLine(),
                specs = specs
            )
            features.add(featureToUpdate)
        }
        return SpecificationsToUpdateRequest(source = config.source, component = config.component, features = features)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy