From 5da47fc0b0d76fcb5fb0cc9e800c002d7779abdf Mon Sep 17 00:00:00 2001 From: Wellyson Freitas Date: Fri, 26 Jul 2024 20:18:24 +0200 Subject: [PATCH] Improve tests --- .../database/persistence/mapper/DoctorMapper.kt | 8 ++++---- .../it/RegisterDoctorIntegrationTest.kt | 16 +++------------- .../it/RegisterPatientIntegrationTest.kt | 15 ++++++--------- src/test/resources/features/Doctor.feature | 14 +++++++------- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/main/kotlin/com/fiap/healthmed/driver/database/persistence/mapper/DoctorMapper.kt b/src/main/kotlin/com/fiap/healthmed/driver/database/persistence/mapper/DoctorMapper.kt index 7ceb8c1..9ae87f3 100644 --- a/src/main/kotlin/com/fiap/healthmed/driver/database/persistence/mapper/DoctorMapper.kt +++ b/src/main/kotlin/com/fiap/healthmed/driver/database/persistence/mapper/DoctorMapper.kt @@ -42,13 +42,13 @@ interface DoctorMapper { } fun convertAvailable(availableTimes: AvailableTimes): String { - val mapper = ObjectMapper().registerModule(JavaTimeModule()); - return mapper.writeValueAsString(availableTimes); + val mapper = ObjectMapper().registerModule(JavaTimeModule()) + return mapper.writeValueAsString(availableTimes) } fun convertAvailable(availableTimes: String): AvailableTimes { - val mapper = ObjectMapper().registerModule(JavaTimeModule()); - return mapper.readValue(availableTimes, AvailableTimes::class.java); + val mapper = ObjectMapper().registerModule(JavaTimeModule()) + return mapper.readValue(availableTimes, AvailableTimes::class.java) } } diff --git a/src/test/kotlin/com/fiap/healthmed/it/RegisterDoctorIntegrationTest.kt b/src/test/kotlin/com/fiap/healthmed/it/RegisterDoctorIntegrationTest.kt index 12a2e23..40d3297 100644 --- a/src/test/kotlin/com/fiap/healthmed/it/RegisterDoctorIntegrationTest.kt +++ b/src/test/kotlin/com/fiap/healthmed/it/RegisterDoctorIntegrationTest.kt @@ -11,7 +11,6 @@ import io.restassured.RestAssured.given import io.restassured.http.ContentType import io.restassured.response.Response import org.assertj.core.api.Assertions.assertThat -import org.hamcrest.CoreMatchers.equalTo import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpStatus @@ -59,17 +58,8 @@ class RegisterDoctorIntegrationTest: IntegrationTest() { response .then() .statusCode(HttpStatus.OK.value()) - .body( - "crm", equalTo(doctorRequest.crm), - "document", equalTo(doctorRequest.document), - "specialty", equalTo(doctorRequest.specialty), - "name", equalTo(doctorRequest.name), - "email", equalTo(doctorRequest.email), - "phoneNumber", equalTo(doctorRequest.phoneNumber), - "serviceZipCode", equalTo(doctorRequest.serviceZipCode), - "serviceAddress", equalTo(doctorRequest.serviceAddress), - "availableTimes", equalTo(doctorRequest.availableTimes.toDomain()), - "appointmentPrice", equalTo(doctorRequest.appointmentPrice), - ) + .extract() + .`as`(Doctor::class.java) + .also { assertThat(it).isEqualTo(doctorRequest.toDomain()) } } } diff --git a/src/test/kotlin/com/fiap/healthmed/it/RegisterPatientIntegrationTest.kt b/src/test/kotlin/com/fiap/healthmed/it/RegisterPatientIntegrationTest.kt index 108d7fa..ee84fa4 100644 --- a/src/test/kotlin/com/fiap/healthmed/it/RegisterPatientIntegrationTest.kt +++ b/src/test/kotlin/com/fiap/healthmed/it/RegisterPatientIntegrationTest.kt @@ -3,6 +3,7 @@ package com.fiap.healthmed.it import com.fiap.healthmed.adapter.gateway.PatientGateway import com.fiap.healthmed.domain.Patient import com.fiap.healthmed.driver.web.request.PatientRequest +import com.fiap.healthmed.driver.web.request.toDomain import io.cucumber.java.en.Given import io.cucumber.java.en.Then import io.cucumber.java.en.When @@ -10,7 +11,6 @@ import io.restassured.RestAssured.given import io.restassured.http.ContentType import io.restassured.response.Response import org.assertj.core.api.Assertions.assertThat -import org.hamcrest.CoreMatchers.equalTo import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpStatus @@ -54,13 +54,10 @@ class RegisterPatientIntegrationTest: IntegrationTest() { response .then() .statusCode(HttpStatus.OK.value()) - .body( - "document", equalTo(patientRequest.document), - "name", equalTo(patientRequest.name), - "email", equalTo(patientRequest.email), - "phoneNumber", equalTo(patientRequest.phoneNumber), - "zipCode", equalTo(patientRequest.zipCode), - "address", equalTo(patientRequest.address), - ) + .extract() + .`as`(Patient::class.java) + .also { + assertThat(it).isEqualTo(patientRequest.toDomain()) + } } } diff --git a/src/test/resources/features/Doctor.feature b/src/test/resources/features/Doctor.feature index 4209280..cc7681f 100644 --- a/src/test/resources/features/Doctor.feature +++ b/src/test/resources/features/Doctor.feature @@ -1,7 +1,7 @@ -#Feature: Doctor -# -# @database -# Scenario: Registering doctor -# Given valid data for doctor -# When request to register doctor -# Then doctor should be registered +Feature: Doctor + + @database + Scenario: Registering doctor + Given valid data for doctor + When request to register doctor + Then doctor should be registered