Merge branch 'tibor' into 'master'

Customer.firebaseUid

See merge request bossanyit/aitrainer_server!19
This commit is contained in:
Bossányi Tibor 2020-10-25 11:14:49 +00:00
commit 5258570f44
10 changed files with 97 additions and 27 deletions

View File

@ -11,7 +11,7 @@ plugins {
}
group = "com.aitrainer"
version = "1.0.9"
version = "1.0.10"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {

View File

@ -49,28 +49,29 @@ CREATE TABLE IF NOT EXISTS `customer` (
`goal` CHAR(20) NULL DEFAULT '' COLLATE 'utf8_hungarian_ci',
`fitness_level` ENUM('beginner','intermediate','advanced','professional') NOT NULL DEFAULT 'beginner' COLLATE 'utf8_hungarian_ci',
`body_type` ENUM('ectomorph','mesomorph','endomorph') NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
`firebase_uid` CHAR(50) NULL DEFAULT NULL COLLATE 'utf8_hungarian_ci',
PRIMARY KEY (`customer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci;
-- Tábla adatainak mentése aitrainer.customer: ~13 rows (hozzávetőleg)
/*!40000 ALTER TABLE `customer` DISABLE KEYS */;
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456789', 'm', 0, 'Y', NULL, NULL, 1, 1, 0, 137, 1972, 79, NULL, 'advanced', 'endomorph');
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (103, 'Bos', 'Kakadu', 'sw2@andio.biz', 'blabal', 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 1972, 79, NULL, 'intermediate', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`) VALUES (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (1, 'Átlag 13 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (2, 'Átlag 14 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (3, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (4, 'Átlag 15 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 137, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (5, 'Átlag 16 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (6, 'Átlag 17 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (7, 'Átlag 18 éves fiú', '', '', NULL, 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (8, 'Átlag 13 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (9, 'Átlag 14 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (10, 'Átlag 15 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (11, 'Átlag 16 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (12, 'Átlag 17 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (13, 'Átlag 18 éves lány', '', '', NULL, 'w', 0, 'N', NULL, NULL, 1, 0, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (54, 'Dummy User', '', 'bosi', '$2a$10$thOc8jS750c7xe9U9Qq3GuSPs/H0Pt2Ads05yzUlyzQBIj.Rk9QCy', 'm', 0, 'N', NULL, NULL, 1, 1, 0, 0, 0, 0, '', 'beginner', NULL, NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (90, 'Bossi', 'Tib', 'sw@andio.biz', '123456789', 'm', 0, 'Y', NULL, NULL, 1, 1, 0, 137, 1972, 79, NULL, 'advanced', 'endomorph', NULL);
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (103, 'Bos', 'Kakadu', 'sw2@andio.biz', 'blabal', 'm', 0, 'N', NULL, NULL, 1, 0, 0, 0, 1972, 79, NULL, 'intermediate', NULL, "3FirebaseU1d");
INSERT INTO `customer` (`customer_id`, `name`, `firstname`, `email`, `password`, `sex`, `age`, `active`, `date_add`, `date_change`, `data_policy_allowed`, `admin`, `trainer`, `trainer_id`, `birth_year`, `weight`, `goal`, `fitness_level`, `body_type`, `firebase_uid`) VALUES (137, 'Robert', '', NULL, NULL, 'm', NULL, 'N', NULL, NULL, 1, 0, 1, 0, 0, 0, '', 'beginner', NULL, NULL);
/*!40000 ALTER TABLE `customer` ENABLE KEYS */;

View File

@ -0,0 +1,7 @@
ALTER TABLE `customer`
ADD COLUMN `firebase_uid` CHAR(50) NULL DEFAULT NULL AFTER `body_type`;
ALTER TABLE `customer`
ADD UNIQUE INDEX `firebase_uid` (`firebase_uid`);
UPDATE configuration set config_value = "1.0.10", date_change=CURRENT_DATE WHERE config_key = "db_version";

View File

@ -4,6 +4,7 @@ import com.aitrainer.api.model.Customer
import com.aitrainer.api.model.User
import com.aitrainer.api.service.ServiceBeans
import com.aitrainer.api.repository.CustomerRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
@ -16,6 +17,7 @@ import javax.validation.Valid
@RestController
@RequestMapping("/api")
class CustomerController ( private val customerRepository: CustomerRepository ) {
private val logger = LoggerFactory.getLogger(javaClass)
@Autowired
var serviceBeans: ServiceBeans? = null
@ -38,6 +40,13 @@ class CustomerController ( private val customerRepository: CustomerRepository )
}.orElse(ResponseEntity.notFound().build())
}
@Secured
@GetMapping("/customers/firebase/{uid}")
fun getCustomerByFirebaseUid(@PathVariable(value = "uid") firebaseUid: String): ResponseEntity<Customer> {
val customer: Customer? = customerRepository.findByFirebaseUid(firebaseUid)
return if (customer == null) ResponseEntity.notFound().build() else ResponseEntity.ok().body(customer)
}
@Secured
@GetMapping("/customers/real")
@ -53,6 +62,18 @@ class CustomerController ( private val customerRepository: CustomerRepository )
return if (list.isEmpty()) ResponseEntity.notFound().build() else ResponseEntity.ok().body(list)
}
@Secured
@PostMapping("customers/update_firebase_uid/{id}")
fun updateCustomerFirebaseUidById(@PathVariable(value = "id") customerId: Long, @Valid @RequestBody firebaseUid: String)
: ResponseEntity<Customer> {
logger.info("Get customer id: $customerId uid: $firebaseUid")
val returnCustomer: Customer = customerRepository.findById(customerId).orElse(null)
?: return ResponseEntity.notFound().build()
returnCustomer.firebaseUid = firebaseUid;
return ResponseEntity.ok().body(customerRepository.save(returnCustomer))
}
@Secured
@PostMapping("/customers/{id}")
fun updateCustomerById(@PathVariable(value = "id") customerId: Long,
@ -103,6 +124,7 @@ class CustomerController ( private val customerRepository: CustomerRepository )
with (customer) {
email = newUser.username
password = serviceBeans!!.passwordEncoder().encode(newUser.password)
firebaseUid = newUser.firebaseUid
}
val returnCustomer: Customer? = customerRepository.findByEmail(newUser.username).let {

View File

@ -25,6 +25,7 @@ data class Customer (
var goal: String? = null,
var fitnessLevel: String = "beginner",
var bodyType: String? = null,
var firebaseUid: String? = null,
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var customerId: Long = 0

View File

@ -6,7 +6,8 @@ import kotlinx.serialization.json.*
@Serializable
data class User (
var username: String = "",
var password: String = ""
var password: String = "",
var firebaseUid: String = ""
) {
@OptIn(UnstableDefault::class)
fun fromJson(json: String): User {

View File

@ -11,4 +11,6 @@ interface CustomerRepository : JpaRepository<Customer, Long> {
fun findByEmail(email: String?): Customer?
fun findByTrainerId( trainerId: Long ): List<Customer>
fun findByFirebaseUid(firebaseUid: String?): Customer?
}

View File

@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structure has been changed, increment this version number
application.version=1.0.9
application.version=1.0.10
jwt.secret=aitrainer

View File

@ -16,6 +16,6 @@ logging.config=classpath:logback-spring.xml
logging.file=logs
# if the database structure has been changed, increment this version number
application.version=1.0.9
application.version=1.0.10
jwt.secret=aitrainer

View File

@ -42,7 +42,7 @@ class CustomerTests {
@Test
fun testTrainer() {
val id: Long = 137
val customers: List<Customer> = customerRepository.findByTrainerId( id );
val customers: List<Customer> = customerRepository.findByTrainerId( id )
assertEquals(customers.count(), 3)
assertEquals( customers[0].name, "Átlag 13 éves fiú")
}
@ -119,6 +119,7 @@ class CustomerTests {
val customerController = CustomerController(customerRepository)
var response: ResponseEntity<*> = customerController.updateCustomerById(id, customer, HttpHeaders.readOnlyHttpHeaders(HttpHeaders.EMPTY) )
print ("body " + response.body)
var newCustomer: Customer? = response.body as Customer
assertEquals(response.statusCode, HttpStatus.OK)
assertEquals(newCustomer?.weight, 79)
@ -147,21 +148,24 @@ class CustomerTests {
@Test
fun testRegistration() {
val json = "{\"username\":\"bosi@example.com\",\"password\":\"94385\"}"
val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94385\",\"firebaseUid\":\"3Firebase8Uid\"}"
val user: User = User().fromJson(json)
assertEquals(user.username, "bosi@example.com")
assertEquals(user.username, "bosi2@example.com")
val customer = Customer()
with(customer) {
email = user.username
password = user.password
firebaseUid = user.firebaseUid
}
val customerController = CustomerController(customerRepository)
customerController.serviceBeans = serviceBean
var response: ResponseEntity<*> = customerController.registration(json)
print("body " + response.body)
val newCustomer: Customer? = response.body as Customer
assertEquals(response.statusCode, HttpStatus.OK)
assertEquals(newCustomer?.firebaseUid, "3Firebase8Uid")
val json2 = "{\"username\":\"bosi@example.com\",\"password\":\"934345\"}"
val json2 = "{\"username\":\"bosi2@example.com\",\"password\":\"934345\",\"firebaseUid\":\"3Firebase8Uid\"}"
response = customerController.registration(json2)
assertEquals(response.statusCode, HttpStatus.BAD_REQUEST)
@ -170,7 +174,39 @@ class CustomerTests {
}
}
@Test fun testLogin() {
@Test
fun testUpdateFirebaseUid() {
val newCustomer = Customer("Bossanyi2", "Tibor", "", 48, "m")
val savedCustomer: Customer = customerRepository.save(newCustomer)
assertEquals(savedCustomer.age, 48)
insertedId = savedCustomer.customerId
val customerController = CustomerController(customerRepository)
val response: ResponseEntity<*> = customerController.updateCustomerFirebaseUidById(insertedId!!, "3FirebusaeId4")
val newCustomer2: Customer? = response.body as Customer
assertEquals(response.statusCode, HttpStatus.OK)
assertEquals(newCustomer2!!.firebaseUid, "3FirebusaeId4")
assertEquals(newCustomer2.firstname, "Tibor")
assertEquals(newCustomer2.name, "Bossanyi2")
assertEquals(newCustomer2.age, 48)
customerRepository.delete(newCustomer)
}
@Test
fun testGetCustomerByFirebaseUid() {
val uid = "3FirebaseU1d"
val customerController = CustomerController(customerRepository)
val response: ResponseEntity<*> = customerController.getCustomerByFirebaseUid(uid)
assertEquals(response.statusCode, HttpStatus.OK)
val newCustomer: Customer? = response.body as Customer
assertEquals(newCustomer!!.name, "Bos")
assertEquals(newCustomer.email, "sw2@andio.biz")
}
/*@Test fun _testLogin() {
val json = "{\"username\":\"bosi2@example.com\",\"password\":\"94333385\"}"
val user: User = User().fromJson(json)
val customer = Customer()
@ -196,5 +232,5 @@ class CustomerTests {
if ( newCustomer != null) {
customerRepository.delete(newCustomer)
}
}
}*/
}