40
40
import in .koreatech .koin .domain .bus .repository .ExpressBusCacheRepository ;
41
41
import in .koreatech .koin .domain .version .model .Version ;
42
42
import in .koreatech .koin .domain .version .repository .VersionRepository ;
43
+ import in .koreatech .koin .domain .version .service .VersionService ;
43
44
import in .koreatech .koin .support .JsonAssertions ;
44
45
import io .restassured .RestAssured ;
45
46
import io .restassured .response .ExtractableResponse ;
@@ -59,6 +60,9 @@ class BusApiTest extends AcceptanceTest {
59
60
@ Autowired
60
61
private ExpressBusCacheRepository expressBusCacheRepository ;
61
62
63
+ @ Autowired
64
+ private VersionService versionService ;
65
+
62
66
private final Instant UPDATED_AT = ZonedDateTime .parse (
63
67
"2024-02-21 18:00:00 KST" ,
64
68
ofPattern ("yyyy-MM-dd " + "HH:mm:ss z" )
@@ -137,11 +141,11 @@ void getNextShuttleBusRemainTime() {
137
141
softly -> {
138
142
softly .assertThat (response .body ().jsonPath ().getString ("bus_type" ))
139
143
.isEqualTo (busType .name ().toLowerCase ());
140
- softly .assertThat ((Long ) response .body ().jsonPath ().get ("now_bus.bus_number" )).isNull ();
144
+ softly .assertThat ((Long )response .body ().jsonPath ().get ("now_bus.bus_number" )).isNull ();
141
145
softly .assertThat (response .body ().jsonPath ().getLong ("now_bus.remain_time" )).isEqualTo (
142
146
BusRemainTime .from (arrivalTime ).getRemainSeconds (clock ));
143
- softly .assertThat ((Long ) response .body ().jsonPath ().get ("next_bus.bus_number" )).isNull ();
144
- softly .assertThat ((Long ) response .body ().jsonPath ().get ("next_bus.remain_time" )).isNull ();
147
+ softly .assertThat ((Long )response .body ().jsonPath ().get ("next_bus.bus_number" )).isNull ();
148
+ softly .assertThat ((Long )response .body ().jsonPath ().get ("next_bus.remain_time" )).isNull ();
145
149
}
146
150
);
147
151
}
@@ -200,8 +204,8 @@ void getNextCityBusRemainTimeRedis() {
200
204
softly -> {
201
205
softly .assertThat (response .body ().jsonPath ().getString ("bus_type" ))
202
206
.isEqualTo (busType .name ().toLowerCase ());
203
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("now_bus.bus_number" )).isEqualTo (busNumber );
204
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("now_bus.remain_time" ))
207
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("now_bus.bus_number" )).isEqualTo (busNumber );
208
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("now_bus.remain_time" ))
205
209
.isEqualTo (
206
210
BusRemainTime .of (remainTime , version .getUpdatedAt ().toLocalTime ()).getRemainSeconds (clock ));
207
211
softly .assertThat (response .body ().jsonPath ().getObject ("next_bus.bus_number" , Long .class )).isNull ();
@@ -303,12 +307,12 @@ void getNextCityBusRemainTimeOpenApi() {
303
307
softly -> {
304
308
softly .assertThat (response .body ().jsonPath ().getString ("bus_type" ))
305
309
.isEqualTo (busType .name ().toLowerCase ());
306
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("now_bus.bus_number" )).isEqualTo (400 );
307
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("now_bus.remain_time" ))
310
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("now_bus.bus_number" )).isEqualTo (400 );
311
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("now_bus.remain_time" ))
308
312
.isEqualTo (
309
313
BusRemainTime .of (600L , version .getUpdatedAt ().toLocalTime ()).getRemainSeconds (clock ));
310
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("next_bus.bus_number" )).isEqualTo (405 );
311
- softly .assertThat ((Long ) response .body ().jsonPath ().getLong ("next_bus.remain_time" ))
314
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("next_bus.bus_number" )).isEqualTo (405 );
315
+ softly .assertThat ((Long )response .body ().jsonPath ().getLong ("next_bus.remain_time" ))
312
316
.isEqualTo (
313
317
BusRemainTime .of (800L , version .getUpdatedAt ().toLocalTime ()).getRemainSeconds (clock ));
314
318
}
@@ -470,4 +474,60 @@ void getShuttleBusTimetable() {
470
474
]
471
475
""" );
472
476
}
477
+
478
+ @ Test
479
+ @ DisplayName ("셔틀버스 시간표를 조회한다(업데이트 시각 포함)." )
480
+ void getShuttleBusTimetableWithUpdatedAt () {
481
+ when (dateTimeProvider .getNow ()).thenReturn (Optional .of (UPDATED_AT ));
482
+
483
+ Version version = Version .builder ()
484
+ .version ("20240_1712920946" )
485
+ .type ("shuttle_bus_timetable" )
486
+ .build ();
487
+ versionRepository .save (version );
488
+
489
+ BusType busType = BusType .from ("shuttle" );
490
+ String direction = "from" ;
491
+ String region = "천안" ;
492
+
493
+ ExtractableResponse <Response > response = RestAssured
494
+ .given ()
495
+ .when ()
496
+ .param ("bus_type" , busType .name ().toLowerCase ())
497
+ .param ("direction" , direction )
498
+ .param ("region" , region )
499
+ .get ("/bus/timetable/v2" )
500
+ .then ()
501
+ .statusCode (HttpStatus .OK .value ())
502
+ .extract ();
503
+
504
+ JsonAssertions .assertThat (response .asPrettyString ())
505
+ .isEqualTo (String .format ("""
506
+ {
507
+ "bus_timetable": [
508
+ {
509
+ "route_name": "주중",
510
+ "arrival_info": [
511
+ {
512
+ "nodeName": "한기대",
513
+ "arrivalTime": "18:10"
514
+ },
515
+ {
516
+ "nodeName": "신계초,운전리,연춘리",
517
+ "arrivalTime": "정차"
518
+ },
519
+ {
520
+ "nodeName": "천안역(학화호두과자)",
521
+ "arrivalTime": "18:50"
522
+ },{
523
+ "nodeName": "터미널(신세계 앞 횡단보도)",
524
+ "arrivalTime": "18:55"
525
+ }
526
+ ]
527
+ }
528
+ ],
529
+ "updated_at": %s
530
+ }
531
+ """ , version .getUpdatedAt ()));
532
+ }
473
533
}
0 commit comments