мой тестовый пример:
Код: Выделить всё
def "should return error when email already exists in company"() {
given: "A register driver request"
def requestBody = [
driverId: 12345L,
country: Country.DK,
firstName: "John",
lastName: "Doe",
companyId: "company123",
email: "john.doe@example.com",
countryCallingCode: "1",
phoneNumber: "1234567890",
isActive: true
]
def email = requestBody.email
def companyId = requestBody.companyId
and: "Insert a driver with the same email into the database"
driverRepository.save(DriverEntity.builder()
.id("uniqueId1")
.companyId(companyId)
.driverId("67890")
.country(Country.DK)
.firstName("Jane")
.lastName("Doe")
.email(email)
.countryCallingCode("1")
.phoneNumber("0987654321")
.build())
when: "The register driver endpoint is called"
def response = webTestClient.post()
.uri("/drivers")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.bodyValue(requestBody)
.exchange()
then: "The response indicates a bad request due to duplicate email"
response.expectStatus().isEqualTo(422)
.expectBody()
.jsonPath("\$.error").isEqualTo("EMAIL_ALREADY_EXISTS")
.jsonPath("\$.description").isEqualTo("Email [${email}] already exists in company [${companyId}]")
}
Код: Выделить всё
Expected :Email [john.doe@example.com] already exists in company [company123]
Actual :Email [john.doe@example.com] already exists in company [company123]
Код: Выделить всё
"Driver ID [12345] already exists in company [company123]"
Есть ли решение этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/788 ... in-strings
Мобильная версия