Skip to content

Commit 9d0ae1b

Browse files
committed
refactor/qg-253: ещё горка мелкой полировки
1 parent 05418f3 commit 9d0ae1b

15 files changed

Lines changed: 48 additions & 42 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Tests - Calendars Integration" type="JUnit" factoryName="JUnit">
3+
<module name="QYoga.app.test"/>
4+
<extension name="coverage">
5+
<pattern>
6+
<option name="PATTERN" value="pro.qyoga.tests.cases.app.therapist.clients.*"/>
7+
<option name="ENABLED" value="true"/>
8+
</pattern>
9+
</extension>
10+
<option name="PACKAGE_NAME" value="pro.qyoga.tests.cases.app.therapist.clients"/>
11+
<option name="MAIN_CLASS_NAME" value=""/>
12+
<option name="METHOD_NAME" value=""/>
13+
<option name="TEST_OBJECT" value="pattern"/>
14+
<patterns>
15+
<pattern
16+
testClass="^(pro\.qyoga\.tests\.cases\.app\.therapist\.appointments).*|(pro\.azhidkov\.tests\.cases\.domain\.timezones).*|(pro\.qyoga\.tests\.cases\.i9ns\.calendars).*|(pro\.qyoga\.tests\.cases\.app\.therapist\.calendars).*$"/>
17+
</patterns>
18+
<method v="2">
19+
<option name="Make" enabled="true"/>
20+
</method>
21+
</configuration>
22+
</component>

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/ergo/hydration/Hydration.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ fun <T : Any> JdbcAggregateOperations.hydrate(
3838
entities: Iterable<T>,
3939
fetchSpec: FetchSpec<T>
4040
): List<T> {
41+
if (fetchSpec.propertyFetchSpecs.isEmpty()) {
42+
return (entities as? List<T>) ?: entities.toList()
43+
}
44+
4145
val refs: Map<KProperty1<*, AggregateReference<*, *>?>, Map<Any, Any>> =
4246
fetchSpec.propertyFetchSpecs.filter {
4347
detectRefType(
@@ -116,4 +120,4 @@ private fun detectRefType(property: KProperty1<*, *>): RefType? = when {
116120

117121
enum class RefType {
118122
SCALAR,
119-
}
123+
}

app/src/main/kotlin/pro/qyoga/app/therapist/appointments/core/schedule/GoogleCalendarSettingsController.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.springframework.http.HttpStatus
44
import org.springframework.security.core.annotation.AuthenticationPrincipal
55
import org.springframework.stereotype.Controller
66
import org.springframework.web.bind.annotation.*
7-
import org.springframework.web.servlet.ModelAndView
87
import pro.qyoga.core.users.auth.dtos.QyogaUserDetails
98
import pro.qyoga.core.users.therapists.ref
109
import pro.qyoga.i9ns.calendars.google.GoogleCalendarsService
@@ -30,9 +29,8 @@ class GoogleCalendarSettingsController(
3029
@PathVariable calendarId: String,
3130
@RequestBody settingsPatch: Map<String, Any>,
3231
@AuthenticationPrincipal therapist: QyogaUserDetails
33-
): ModelAndView {
32+
) {
3433
googleCalendarsService.updateCalendarSettings(therapist.ref, googleAccount, calendarId, settingsPatch)
35-
return getGoogleCalendarSettingsComponent(therapist)
3634
}
3735

3836
companion object {

app/src/main/kotlin/pro/qyoga/app/therapist/appointments/core/schedule/SchedulePageModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ data class SchedulePageModel(
6060

6161
fun of(
6262
date: LocalDate,
63-
getAppointments: GetCalendarAppointmentsRs,
63+
getAppointmentsRs: GetCalendarAppointmentsRs,
6464
appointmentToFocus: UUID? = null
6565
): SchedulePageModel {
66-
val timeMarks = generateTimeMarks(getAppointments.appointments, date)
66+
val timeMarks = generateTimeMarks(getAppointmentsRs.appointments, date)
6767
val weekCalendar = generateDaysAround(date)
68-
return SchedulePageModel(date, timeMarks, weekCalendar, appointmentToFocus, getAppointments.hasErrors)
68+
return SchedulePageModel(date, timeMarks, weekCalendar, appointmentToFocus, getAppointmentsRs.hasErrors)
6969
}
7070

7171
const val FOCUSED_APPOINTMENT = "focusedAppointment"

app/src/main/kotlin/pro/qyoga/i9ns/calendars/google/GoogleCalendarConf.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class GoogleCalendarConf {
2828
Caffeine.newBuilder()
2929
.expireAfterWrite(5, TimeUnit.MINUTES)
3030
.maximumSize(5_000)
31-
.recordStats()
3231
.build()
3332
)
3433

@@ -37,7 +36,6 @@ class GoogleCalendarConf {
3736
Caffeine.newBuilder()
3837
.expireAfterWrite(30, TimeUnit.MINUTES)
3938
.maximumSize(1_000)
40-
.recordStats()
4139
.build()
4240
)
4341

app/src/main/kotlin/pro/qyoga/i9ns/calendars/google/GoogleCalendarsService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ import java.util.function.Supplier
2828

2929
private typealias GoogleCalendarItemsFetchResult = Result<List<GoogleCalendarItem<ZonedDateTime>>>
3030

31-
private val log = LoggerFactory.getLogger(GoogleCalendarsService::class.java)
32-
3331
@Service
3432
class GoogleCalendarsService(
3533
private val googleAccountsDao: GoogleAccountsDao,
3634
private val googleCalendarsDao: GoogleCalendarsDao,
3735
private val googleCalendarsClient: GoogleCalendarsClient,
3836
) : CalendarsService<GoogleCalendarItemId> {
3937

38+
private val log = LoggerFactory.getLogger(GoogleCalendarsService::class.java)
39+
4040
private val executor = Executors.newVirtualThreadPerTaskExecutor()
4141

4242
override val type: CalendarType = GoogleCalendar.Type

app/src/main/resources/db/migration/common/current/V25091101__add_google_calendars.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ CREATE TABLE therapist_google_accounts
22
(
33
id UUID PRIMARY KEY,
44
owner_ref UUID REFERENCES therapists NOT NULL,
5-
email varchar NOT NULL,
6-
refresh_token varchar NOT NULL,
5+
email VARCHAR NOT NULL,
6+
refresh_token VARCHAR NOT NULL,
77

88
UNIQUE (owner_ref, email)
99
);
@@ -13,7 +13,7 @@ CREATE TABLE therapist_google_calendar_settings
1313
id UUID PRIMARY KEY,
1414
owner_ref UUID REFERENCES therapists NOT NULL,
1515
google_account_ref UUID REFERENCES therapist_google_accounts NOT NULL,
16-
calendar_id varchar NOT NULL,
16+
calendar_id VARCHAR NOT NULL,
1717
should_be_shown BOOLEAN NOT NULL,
1818

1919
UNIQUE (owner_ref, google_account_ref, calendar_id)

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/appointments/core/SchedulePageControllerTest.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@ import pro.qyoga.tests.fixture.object_mothers.calendars.google.GoogleCalendarObj
99
import pro.qyoga.tests.fixture.object_mothers.therapists.theTherapistUserDetails
1010
import pro.qyoga.tests.fixture.presets.AppointmentsFixturePresets
1111
import pro.qyoga.tests.fixture.presets.GoogleCalendarsFixturePresets
12-
import pro.qyoga.tests.fixture.test_apis.GoogleCalendarTestApi
13-
import pro.qyoga.tests.fixture.wiremocks.MockGoogleCalendar
14-
import pro.qyoga.tests.fixture.wiremocks.MockGoogleOAuthServer
1512
import pro.qyoga.tests.infra.web.QYogaAppIntegrationBaseKoTest
16-
import pro.qyoga.tests.infra.wiremock.WireMock
1713
import java.time.LocalDate
1814

1915

2016
@DisplayName("Контроллер страницы календаря")
2117
class SchedulePageControllerTest : QYogaAppIntegrationBaseKoTest({
2218

2319
val appointmentsFixturePresets = getBean<AppointmentsFixturePresets>()
24-
val schedulePageController = getBean<SchedulePageController>()
20+
val googleCalendarsFixturePresets = getBean<GoogleCalendarsFixturePresets>()
2521

26-
val googleCalendarsTestApi = getBean<GoogleCalendarTestApi>()
27-
val mockGoogleOAuthServer = MockGoogleOAuthServer(WireMock.wiremock)
28-
val mockGoogleCalendar = MockGoogleCalendar(WireMock.wiremock)
29-
val googleCalendarsFixturePresets =
30-
GoogleCalendarsFixturePresets(mockGoogleOAuthServer, mockGoogleCalendar, googleCalendarsTestApi)
22+
val schedulePageController = getBean<SchedulePageController>()
3123

3224
"при наличии приёма, созданного на базе события ics-календаря" - {
3325
// Сетап

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/appointments/core/SchedulePageTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import java.time.LocalDate
3030
@DisplayName("Страница календаря")
3131
class SchedulePageTest : QYogaAppIntegrationBaseTest() {
3232

33-
private val ICalsCalendarsFixturePresets = getBean<ICalsCalendarsFixturePresets>()
33+
private val iCalsCalendarsFixturePresets = getBean<ICalsCalendarsFixturePresets>()
3434

3535
@Test
3636
fun `должна корректно рендерить пустой календарь за текущую дату`() {
@@ -123,7 +123,7 @@ class SchedulePageTest : QYogaAppIntegrationBaseTest() {
123123
set(field(ICalZonedCalendarItem::duration), AppointmentsObjectMother.fullCardDuration)
124124
}
125125

126-
ICalsCalendarsFixturePresets.createICalCalendarWithSingleEvent(event)
126+
iCalsCalendarsFixturePresets.createICalCalendarWithSingleEvent(event)
127127

128128
// Действие
129129
val document = theTherapist.appointments.getScheduleForDay(today)

app/src/test/kotlin/pro/qyoga/tests/cases/app/therapist/calendars/google/GoogleAuthorizationIntegrationTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.kotest.matchers.shouldBe
55
import org.springframework.core.env.get
66
import pro.qyoga.app.therapist.appointments.core.schedule.SchedulePageController
77
import pro.qyoga.app.therapist.oauth2.GoogleOAuthController
8-
import pro.qyoga.i9ns.calendars.google.GoogleCalendarsService
98
import pro.qyoga.i9ns.calendars.google.model.GoogleCalendar
109
import pro.qyoga.i9ns.calendars.google.views.GoogleCalendarsSettingsView
1110
import pro.qyoga.tests.assertions.shouldBeRedirectToGoogleOAuth
@@ -30,7 +29,6 @@ class GoogleAuthorizationIntegrationTest : QYogaAppIntegrationBaseKoTest({
3029
val therapist by lazy { TherapistClient.loginAsTheTherapist() }
3130
val clientId = context.environment["spring.security.oauth2.client.registration.google.client-id"]!!
3231
val clientSecret = context.environment["spring.security.oauth2.client.registration.google.client-secret"]!!
33-
val googleCalendarsService = getBean<GoogleCalendarsService>()
3432
val googleCalendarsTestApi = getBean<GoogleCalendarTestApi>()
3533

3634
"Spring Security" - {
@@ -96,7 +94,7 @@ class GoogleAuthorizationIntegrationTest : QYogaAppIntegrationBaseKoTest({
9694
}
9795

9896
"обеспечивать возможность дальнейших запросов к Google Calendar" {
99-
val gotCalendars = googleCalendarsService.findGoogleAccountCalendars(THE_THERAPIST_REF)
97+
val gotCalendars = googleCalendarsTestApi.getGoogleCalendarsSettings(THE_THERAPIST_REF)
10098
(gotCalendars.single().content as GoogleCalendarsSettingsView.Calendars).calendars shouldBe calendars
10199
}
102100

@@ -135,7 +133,7 @@ class GoogleAuthorizationIntegrationTest : QYogaAppIntegrationBaseKoTest({
135133
}
136134

137135
"обеспечивать возможность дальнейших запросов к Google Calendar" {
138-
val gotCalendars = googleCalendarsService.findGoogleAccountCalendars(THE_THERAPIST_REF)
136+
val gotCalendars = googleCalendarsTestApi.getGoogleCalendarsSettings(THE_THERAPIST_REF)
139137
(gotCalendars.single().content as GoogleCalendarsSettingsView.Calendars).calendars shouldBe calendars
140138
}
141139

0 commit comments

Comments
 (0)