diff --git a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt index dbb018a..f12d70f 100644 --- a/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt +++ b/src/main/kotlin/com/aitrainer/api/controller/CustomerController.kt @@ -10,6 +10,9 @@ import org.springframework.http.HttpHeaders import org.springframework.http.ResponseEntity import org.springframework.security.access.annotation.Secured import org.springframework.web.bind.annotation.* +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.util.* import javax.validation.Valid @@ -101,7 +104,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) { fitnessLevel = newCustomer.fitnessLevel, bodyType = newCustomer.bodyType, goal = newCustomer.goal, - dataPolicyAllowed = newCustomer.dataPolicyAllowed + dateChange = newCustomer.dateChange ) } else { updatedCustomer = @@ -114,7 +117,7 @@ class CustomerController ( private val customerRepository: CustomerRepository) { fitnessLevel = newCustomer.fitnessLevel, bodyType = newCustomer.bodyType, goal = newCustomer.goal, - dataPolicyAllowed = newCustomer.dataPolicyAllowed + dateChange = newCustomer.dateChange ) } @@ -126,11 +129,16 @@ class CustomerController ( private val customerRepository: CustomerRepository) { fun registration(@Valid @RequestBody json: String): ResponseEntity<*> { val customer = Customer() + val current = LocalDateTime.now() + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS") + val nowFormatted = current.format(formatter) + val newUser: User = User().fromJson(json) with (customer) { email = newUser.username password = serviceBeans!!.passwordEncoder().encode(newUser.password) firebaseUid = newUser.firebaseUid + dateAdd = nowFormatted } val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let { diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt index 537e2a1..21a629a 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerPropertyTest.kt @@ -4,7 +4,6 @@ import com.aitrainer.api.controller.CustomerPropertyController import com.aitrainer.api.model.CustomerProperty import com.aitrainer.api.repository.CustomerPropertyRepository import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestFactory import org.junit.jupiter.api.TestInstance import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest diff --git a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt index 88e691c..ff6a9a2 100644 --- a/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt +++ b/src/test/kotlin/com/aitrainer/api/test/CustomerTests.kt @@ -13,8 +13,11 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import kotlin.test.assertEquals import kotlin.test.assertNotNull +import kotlin.test.assertTrue @SpringBootTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -80,11 +83,11 @@ class CustomerTests { assertNotNull(updatedCustomer) updatedCustomer.firstname ="Tiborka" - updatedCustomer.dataPolicyAllowed = 1; + updatedCustomer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val customer: Customer = customerRepository.save( updatedCustomer ) assertEquals( customer.firstname, "Tiborka") - assertEquals(customer.dataPolicyAllowed, 1) + assertTrue(customer.dateChange != null) customerRepository.delete(updatedCustomer) } @@ -106,11 +109,13 @@ class CustomerTests { customer.bodyType = "endomorph" customer.dataPolicyAllowed = 1 customer.fitnessLevel = "advanced" + customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val updatedCustomer = customerRepository.save(customer) assertEquals(updatedCustomer.customerId, 90) assertEquals(updatedCustomer.birthYear, 1972) assertEquals(updatedCustomer.fitnessLevel, "advanced") + assertTrue(customer.dateChange != null) } @Test @@ -129,6 +134,7 @@ class CustomerTests { customer.fitnessLevel = "intermediate" //customer.weight = 79 customer.birthYear = 1972 + customer.dateChange = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) val customerController = CustomerController(customerRepository) var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) ) @@ -136,8 +142,9 @@ class CustomerTests { var newCustomer: Customer? = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) //assertEquals(newCustomer?.weight, 79) - assertEquals(newCustomer?.password, "123456789") - assertEquals(newCustomer?.firstname, "Tib") + assertEquals(newCustomer!!.password, "123456789") + assertEquals(newCustomer.firstname, "Tib") + assertTrue(newCustomer.dateChange != null) // test not found id = 1000 @@ -177,6 +184,7 @@ class CustomerTests { val newCustomer: Customer = response.body as Customer assertEquals(response.statusCode, HttpStatus.OK) assertEquals(newCustomer.firebaseUid, "3Firebase8Uid") + assertTrue(newCustomer.dateAdd != null) val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}" response = customerController.registration(json2)