diff --git a/build.gradle.kts b/build.gradle.kts index 209c614..9b79263 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,9 @@ dependencies { implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - runtimeOnly("org.postgresql:postgresql") + implementation("org.json:json:20230618") + implementation("org.postgresql:postgresql") + implementation("org.flywaydb:flyway-core:9.3.1") testImplementation("org.springframework.boot:spring-boot-starter-test") } diff --git a/database.production.env b/database.production.env new file mode 100644 index 0000000..16e0bb6 --- /dev/null +++ b/database.production.env @@ -0,0 +1,9 @@ +DATABASE_DRIVER=org.postgresql.Driver +POSTGRES_USER=postgres +POSTGRES_PASSWORD=7gn[[G780PH[,JP'HIUG +DATABASE_NAME=organisations +DATABASE_HOSTNAME=database +DATABASE_URL=jdbc:postgresql://database:5432/ +DATABASE_PORT=5432 +DATABASE_MAX_CONNECTIONS=20 +DATABASE_MIGRATION=classpath:db/migration diff --git a/docker-compose.yml b/docker-compose.yml index 4756a1a..bf9904e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,6 @@ version: "3.9" +volumes: + billie_pairing_exercise_data: services: traefik: image: "traefik:v2.4" @@ -25,6 +27,8 @@ services: - database.env ports: - "5432:5432" + volumes: + - billie_pairing_exercise_data:/var/lib/postgresql/data service: build: . links: @@ -34,8 +38,10 @@ services: - traefik - database env_file: - - database.env + - database.production.env - service.env + ports: + - "8080:8080" labels: - "traefik.enable=true" - "traefik.http.routers.organisations.rule=PathPrefix(`/swagger-ui`) || PathPrefix(`/organisations`) || PathPrefix(`/countries`)" diff --git a/src/main/kotlin/io/billie/organisations/data/OrganisationRepository.kt b/src/main/kotlin/io/billie/organisations/data/OrganisationRepository.kt index 8c0026b..869cd11 100644 --- a/src/main/kotlin/io/billie/organisations/data/OrganisationRepository.kt +++ b/src/main/kotlin/io/billie/organisations/data/OrganisationRepository.kt @@ -2,6 +2,8 @@ package io.billie.organisations.data import io.billie.countries.model.CountryResponse import io.billie.organisations.viewmodel.* +import org.postgresql.util.PGobject +import org.json.JSONObject import org.springframework.beans.factory.annotation.Autowired import org.springframework.jdbc.core.JdbcTemplate import org.springframework.jdbc.core.ResultSetExtractor @@ -14,6 +16,8 @@ import java.sql.Date import java.sql.ResultSet import java.util.* +// use JPA instead of manually writing queries +// no unit tests for this file @Repository class OrganisationRepository { @@ -31,23 +35,29 @@ class OrganisationRepository { if(!valuesValid(organisation)) { throw UnableToFindCountry(organisation.countryCode) } - val id: UUID = createContactDetails(organisation.contactDetails) - return createOrganisation(organisation, id) + val contactDetailsId: UUID = createContactDetails(organisation.contactDetails) + val addressId = createAddress(organisation.address) + return createOrganisation(organisation, contactDetailsId, addressId) } private fun valuesValid(organisation: OrganisationRequest): Boolean { + val addressCountryCode = organisation.address.countryCode + return countryCodeValid(organisation.countryCode) && countryCodeValid(addressCountryCode) + } + + private fun countryCodeValid(countryCode: String): Boolean { val reply: Int? = jdbcTemplate.query( "select count(country_code) from organisations_schema.countries c WHERE c.country_code = ?", ResultSetExtractor { it.next() it.getInt(1) }, - organisation.countryCode + countryCode ) return (reply != null) && (reply > 0) } - private fun createOrganisation(org: OrganisationRequest, contactDetailsId: UUID): UUID { + private fun createOrganisation(org: OrganisationRequest, contactDetailsId: UUID, addressId: UUID): UUID { val keyHolder: KeyHolder = GeneratedKeyHolder() jdbcTemplate.update( { connection -> @@ -59,8 +69,9 @@ class OrganisationRepository { "vat_number, " + "registration_number, " + "legal_entity_type, " + - "contact_details_id" + - ") VALUES (?, ?, ?, ?, ?, ?, ?)", + "contact_details_id, " + + "address_id" + + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?)", arrayOf("id") ) ps.setString(1, org.name) @@ -70,12 +81,14 @@ class OrganisationRepository { ps.setString(5, org.registrationNumber) ps.setString(6, org.legalEntityType.toString()) ps.setObject(7, contactDetailsId) + ps.setObject(8, addressId) ps }, keyHolder ) return keyHolder.getKeyAs(UUID::class.java)!! } + // contact details creation can be moved to a separate repository private fun createContactDetails(contactDetails: ContactDetailsRequest): UUID { val keyHolder: KeyHolder = GeneratedKeyHolder() jdbcTemplate.update( @@ -99,24 +112,60 @@ class OrganisationRepository { return keyHolder.getKeyAs(UUID::class.java)!! } - private fun organisationQuery() = "select " + - "o.id as id, " + - "o.name as name, " + - "o.date_founded as date_founded, " + - "o.country_code as country_code, " + - "c.id as country_id, " + - "c.name as country_name, " + - "o.VAT_number as VAT_number, " + - "o.registration_number as registration_number," + - "o.legal_entity_type as legal_entity_type," + - "o.contact_details_id as contact_details_id, " + - "cd.phone_number as phone_number, " + - "cd.fax as fax, " + - "cd.email as email " + - "from " + - "organisations_schema.organisations o " + - "INNER JOIN organisations_schema.contact_details cd on o.contact_details_id::uuid = cd.id::uuid " + - "INNER JOIN organisations_schema.countries c on o.country_code = c.country_code " + private fun createAddress(address: AddressRequest): UUID { + val keyHolder: KeyHolder = GeneratedKeyHolder() + jdbcTemplate.update( + { connection -> + val addressData = hashMapOf("line1" to address.line1, + "country_code" to address.countryCode, + "city" to address.city, + "post_code" to address.postCode, + "line2" to address.line2 + ) +// val jsonObject = PGobject() +// jsonObject.setType("json") + val ps = connection.prepareStatement( + "insert into organisations_schema.addresses (data) VALUES (?) ", + arrayOf("id") + ) + val jsonObject = PGobject() + jsonObject.type = "json" + jsonObject.value = JSONObject(addressData).toString() + ps.setObject(1, jsonObject) + ps + }, + keyHolder + ) + return keyHolder.getKeyAs(UUID::class.java)!! + } + + private fun organisationQuery() = """ + select + o.id as id, + o.name as name, + o.date_founded as date_founded, + o.country_code as country_code, + c.id as country_id, + c.name as country_name, + o.VAT_number as VAT_number, + o.registration_number as registration_number, + o.legal_entity_type as legal_entity_type, + o.contact_details_id as contact_details_id, + cd.phone_number as phone_number, + cd.fax as fax, + cd.email as email, + o.address_id as address_id, + oa.data -> 'line1' as address_line1, + oa.data -> 'line2' as address_line2, + oa.data -> 'city' as address_city, + oa.data -> 'post_code' as address_post_code, + oa.data -> 'country_code' as address_country_code + from + organisations_schema.organisations o + INNER JOIN organisations_schema.contact_details cd on o.contact_details_id::uuid = cd.id::uuid + INNER JOIN organisations_schema.addresses oa on o.address_id::uuid = oa.id::uuid + INNER JOIN organisations_schema.countries c on o.country_code = c.country_code + """.trimIndent() private fun organisationMapper() = RowMapper { it: ResultSet, _: Int -> OrganisationResponse( @@ -127,7 +176,8 @@ class OrganisationRepository { it.getString("vat_number"), it.getString("registration_number"), LegalEntityType.valueOf(it.getString("legal_entity_type")), - mapContactDetails(it) + mapContactDetails(it), + mapAddress(it) ) } @@ -140,6 +190,18 @@ class OrganisationRepository { ) } + private fun mapAddress(it: ResultSet): Address? { + val addressId: String = it.getString("address_id") ?: return null + return Address( + UUID.fromString(addressId), + it.getString("address_line1"), + it.getString("address_line2"), + it.getString("address_post_code"), + it.getString("address_city"), + it.getString("address_country_code") + ) + } + private fun mapCountry(it: ResultSet): CountryResponse { return CountryResponse( it.getObject("country_id", UUID::class.java), diff --git a/src/main/kotlin/io/billie/organisations/viewmodel/Address.kt b/src/main/kotlin/io/billie/organisations/viewmodel/Address.kt new file mode 100644 index 0000000..709e68e --- /dev/null +++ b/src/main/kotlin/io/billie/organisations/viewmodel/Address.kt @@ -0,0 +1,13 @@ +package io.billie.organisations.viewmodel + +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.UUID + +data class Address( + val id: UUID, + val line1: String, + val line2: String?, + @JsonProperty("post_code") val postCode: String, + val city: String, + @JsonProperty("country_code") val countryCode: String +) \ No newline at end of file diff --git a/src/main/kotlin/io/billie/organisations/viewmodel/AddressRequest.kt b/src/main/kotlin/io/billie/organisations/viewmodel/AddressRequest.kt new file mode 100644 index 0000000..a7c82ec --- /dev/null +++ b/src/main/kotlin/io/billie/organisations/viewmodel/AddressRequest.kt @@ -0,0 +1,12 @@ +package io.billie.organisations.viewmodel + +import com.fasterxml.jackson.annotation.JsonProperty +import javax.validation.constraints.NotBlank + +data class AddressRequest( + @field:NotBlank val line1: String, + val line2: String?, + @field:NotBlank @JsonProperty("post_code") val postCode: String, + @field:NotBlank val city: String, + @field:NotBlank @JsonProperty("country_code") val countryCode: String +) diff --git a/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationRequest.kt b/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationRequest.kt index 2e31f21..b7846d2 100644 --- a/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationRequest.kt +++ b/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationRequest.kt @@ -16,4 +16,5 @@ data class OrganisationRequest( @JsonProperty("registration_number") val registrationNumber: String?, @JsonProperty("legal_entity_type") val legalEntityType: LegalEntityType, @JsonProperty("contact_details") val contactDetails: ContactDetailsRequest, + @JsonProperty("address") val address: AddressRequest ) diff --git a/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationResponse.kt b/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationResponse.kt index d0fec75..12b49e8 100644 --- a/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationResponse.kt +++ b/src/main/kotlin/io/billie/organisations/viewmodel/OrganisationResponse.kt @@ -17,4 +17,5 @@ data class OrganisationResponse( @JsonProperty("registration_number") val registrationNumber: String?, @JsonProperty("legal_entity_type") val legalEntityType: LegalEntityType, @JsonProperty("contact_details") val contactDetails: ContactDetails, + @JsonProperty("address") val address: Address? ) diff --git a/src/main/resources/application-production.properties b/src/main/resources/application-production.properties new file mode 100644 index 0000000..cd3084a --- /dev/null +++ b/src/main/resources/application-production.properties @@ -0,0 +1,12 @@ +spring.config.import=optional:file:./database.production.env[.properties] +spring.datasource.driver-class-name=${DATABASE_DRIVER} +spring.datasource.url=${DATABASE_URL} +spring.datasource.username=${POSTGRES_USER} +spring.datasource.password=${POSTGRES_PASSWORD} +spring.datasource.schema=${DATABASE_SCHEMA} +spring.datasource.initialization-mode=always +spring.flyway.enabled=true +spring.flyway.locations=${DATABASE_MIGRATION} +spring.flyway.url = ${DATABASE_URL} +spring.flyway.password=${POSTGRES_PASSWORD} +spring.flyway.user=${POSTGRES_USER} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 09b6bce..aeb0181 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,3 +5,8 @@ spring.datasource.username=${POSTGRES_USER} spring.datasource.password=${POSTGRES_PASSWORD} spring.datasource.schema=${DATABASE_SCHEMA} spring.datasource.initialization-mode=always +spring.flyway.enabled=true +spring.flyway.locations=${DATABASE_MIGRATION} +spring.flyway.url = ${DATABASE_URL} +spring.flyway.password=${POSTGRES_PASSWORD} +spring.flyway.user=${POSTGRES_USER} diff --git a/src/main/resources/db/migration/V10__add_address_to_organisations.sql b/src/main/resources/db/migration/V10__add_address_to_organisations.sql new file mode 100644 index 0000000..bdf71a1 --- /dev/null +++ b/src/main/resources/db/migration/V10__add_address_to_organisations.sql @@ -0,0 +1,2 @@ +ALTER TABLE organisations_schema.organisations +ADD COLUMN address_id VARCHAR(36); \ No newline at end of file diff --git a/src/main/resources/db/migration/V9__add_adresses_table.sql b/src/main/resources/db/migration/V9__add_adresses_table.sql new file mode 100644 index 0000000..993b005 --- /dev/null +++ b/src/main/resources/db/migration/V9__add_adresses_table.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS organisations_schema.addresses +( + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, + data jsonb NOT NULL +); diff --git a/src/test/kotlin/io/billie/functional/CanStoreAndReadOrganisationTest.kt b/src/test/kotlin/io/billie/functional/CanStoreAndReadOrganisationTest.kt index 2d57630..0cdb5ff 100644 --- a/src/test/kotlin/io/billie/functional/CanStoreAndReadOrganisationTest.kt +++ b/src/test/kotlin/io/billie/functional/CanStoreAndReadOrganisationTest.kt @@ -1,20 +1,26 @@ package io.billie.functional - +// database is not cleaned up after each test run import com.fasterxml.jackson.databind.ObjectMapper +import io.billie.functional.data.Fixtures.bbcAddressFixture import io.billie.functional.data.Fixtures.bbcContactFixture import io.billie.functional.data.Fixtures.bbcFixture import io.billie.functional.data.Fixtures.orgRequestJson +import io.billie.functional.data.Fixtures.orgRequestJsonAddressCountryCodeIncorrect import io.billie.functional.data.Fixtures.orgRequestJsonCountryCodeBlank import io.billie.functional.data.Fixtures.orgRequestJsonCountryCodeIncorrect import io.billie.functional.data.Fixtures.orgRequestJsonNoName import io.billie.functional.data.Fixtures.orgRequestJsonNameBlank +import io.billie.functional.data.Fixtures.orgRequestJsonNoAddres import io.billie.functional.data.Fixtures.orgRequestJsonNoContactDetails import io.billie.functional.data.Fixtures.orgRequestJsonNoCountryCode import io.billie.functional.data.Fixtures.orgRequestJsonNoLegalEntityType import io.billie.organisations.viewmodel.Entity import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.core.IsEqual.equalTo +import org.json.JSONObject +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.postgresql.util.PGobject import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest @@ -94,6 +100,14 @@ class CanStoreAndReadOrganisationTest { .andExpect(status().isBadRequest) } + @Test + fun cannotStoreOrgWhenAddressCountryCodeIsNotRecognised() { + mockMvc.perform( + post("/organisations").contentType(APPLICATION_JSON).content(orgRequestJsonAddressCountryCodeIncorrect()) + ) + .andExpect(status().isBadRequest) + } + @Test fun cannotStoreOrgWhenNoLegalEntityType() { mockMvc.perform( @@ -110,6 +124,14 @@ class CanStoreAndReadOrganisationTest { .andExpect(status().isBadRequest) } + @Test + fun cannotStoreOrgWhenNoAddress() { + mockMvc.perform( + post("/organisations").contentType(APPLICATION_JSON).content(orgRequestJsonNoAddres()) + ) + .andExpect(status().isBadRequest) + } + @Test fun canStoreOrg() { val result = mockMvc.perform( @@ -126,6 +148,13 @@ class CanStoreAndReadOrganisationTest { val contactDetailsId: UUID = UUID.fromString(org["contact_details_id"] as String) val contactDetails: Map = contactDetailsFromDatabase(contactDetailsId) assertDataMatches(contactDetails, bbcContactFixture(contactDetailsId)) + + if (org["address_id"] != null){ + val addressId: UUID = UUID.fromString(org["address_id"] as String) + val address: Map = addressFromDatabase(addressId) + assertEquals(address["id"],addressId) + assertDataMatches(JSONObject((address["data"] as PGobject).value).toMap(), bbcAddressFixture()) + } } fun assertDataMatches(reply: Map, assertions: Map) { @@ -143,4 +172,6 @@ class CanStoreAndReadOrganisationTest { private fun contactDetailsFromDatabase(id: UUID): MutableMap = queryEntityFromDatabase("select * from organisations_schema.contact_details where id = ?", id) + private fun addressFromDatabase(id: UUID): MutableMap = + queryEntityFromDatabase("select * from organisations_schema.addresses where id = ?", id) } diff --git a/src/test/kotlin/io/billie/functional/data/Fixtures.kt b/src/test/kotlin/io/billie/functional/data/Fixtures.kt index 9954801..7162fcc 100644 --- a/src/test/kotlin/io/billie/functional/data/Fixtures.kt +++ b/src/test/kotlin/io/billie/functional/data/Fixtures.kt @@ -7,123 +7,189 @@ import kotlin.collections.HashMap object Fixtures { fun orgRequestJsonNameBlank(): String { - return "{\n" + - " \"name\": \"\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"GB\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJsonNoName(): String { - return "{\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"GB\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJsonNoLegalEntityType(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"GB\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJsonNoContactDetails(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"GB\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\"\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION" + } + """.trimIndent() + } + + fun orgRequestJsonNoAddres(): String { + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJson(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"GB\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + }, + "address": { + "line1": "BBC street 1", + "line2": "", + "post_code": "123456", + "city": "London", + "country_code": "GB" + } + } + """.trimIndent() } fun orgRequestJsonCountryCodeBlank(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJsonNoCountryCode(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() } fun orgRequestJsonCountryCodeIncorrect(): String { - return "{\n" + - " \"name\": \"BBC\",\n" + - " \"date_founded\": \"18/10/1922\",\n" + - " \"country_code\": \"XX\",\n" + - " \"vat_number\": \"333289454\",\n" + - " \"registration_number\": \"3686147\",\n" + - " \"legal_entity_type\": \"NONPROFIT_ORGANIZATION\",\n" + - " \"contact_details\": {\n" + - " \"phone_number\": \"+443700100222\",\n" + - " \"fax\": \"\",\n" + - " \"email\": \"yourquestions@bbc.co.uk\"\n" + - " }\n" + - "}" + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "XX", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + } + } + """.trimIndent() + } + + fun orgRequestJsonAddressCountryCodeIncorrect(): String { + return """ + { + "name": "BBC", + "date_founded": "18/10/1922", + "country_code": "GB", + "vat_number": "333289454", + "registration_number": "3686147", + "legal_entity_type": "NONPROFIT_ORGANIZATION", + "contact_details": { + "phone_number": "+443700100222", + "fax": "", + "email": "yourquestions@bbc.co.uk" + }, + "address": { + "line1": "BBC street 1", + "line2": "", + "post_code": "123456", + "city": "London", + "country_code": "XX" + } + } + """.trimIndent() } fun bbcFixture(id: UUID): Map { @@ -147,6 +213,15 @@ object Fixtures { return data } + fun bbcAddressFixture(): Map { + val data:HashMap = hashMapOf("line1" to "BBC street 1", + "line2" to "", + "city" to "London", + "country_code" to "GB", + "post_code" to "123456") + return data + } + }