package com.complycube.reactnative.config.parser import com.complycube.reactnative.config.parser.* import com.complycube.reactnative.config.TestFixtures import com.complycube.reactnative.config.helper.CustomerInfoFieldMapper import com.complycube.reactnative.config.helper.MetadataTemplateProcessor import com.complycube.sdk.common.data.CustomerInfoField import kotlin.test.Test import kotlin.test.assertTrue class CustomerInfoParserTest { private val parser = CustomerInfoParser(CustomerInfoFieldMapper(), MetadataTemplateProcessor()) @Test fun parsesTopLevelTemplatesAndMetadata() { val data = mapOf( "title" to "Customer Info", "metadataTemplates" to TestFixtures.tinTemplates(), "customerInfoFields" to listOf( "email", mapOf( "details" to listOf( mapOf( "person" to listOf("first_name"), "company" to listOf("name") ) ), "metadata" to listOf( TestFixtures.metadataSimple(), TestFixtures.metadataWithCountrySelection("inclusion", listOf("GB", "US")) ) ) ) ) val stage = parser.parseCustomerInfo(data) val fields = stage.customerInfoFields ?: emptyList() assertTrue(fields.any { it is CustomerInfoField.Metadata && it.key == "job" }) assertTrue(fields.any { it is CustomerInfoField.Metadata && it.key == "GB_TIN_HAS" }) assertTrue(fields.none { it is CustomerInfoField.Metadata && it.key == "US_TIN_HAS" }) } @Test fun fallsBackToNestedTemplates() { val nestedTemplates = TestFixtures.tinTemplates() val data = mapOf( "title" to "Customer Info", "customerInfoFields" to listOf( mapOf( "metadata" to listOf( TestFixtures.metadataWithCountrySelection("inclusion", listOf("GB")) ), "metadataTemplates" to nestedTemplates ) ) ) val stage = parser.parseCustomerInfo(data) val fields = stage.customerInfoFields ?: emptyList() assertTrue(fields.any { it is CustomerInfoField.Metadata && it.key == "GB_TIN_HAS" }) } }