@@ -7,7 +7,7 @@ import type { HostElapsedTimeMetric } from './metric/host-elapsed-time.metric';
77
88jest . mock ( '../../clickhouse/query-builder/time-series.query-builder' ) ;
99
10- describe ( 'RankRepository ' , ( ) => {
10+ describe ( 'RankRepository의 ' , ( ) => {
1111 let repository : RankRepository ;
1212 let clickhouse : Clickhouse ;
1313
@@ -34,129 +34,129 @@ describe('RankRepository', () => {
3434 jest . clearAllMocks ( ) ;
3535 } ) ;
3636
37- describe ( 'RankRepository의 ' , ( ) => {
38- describe ( 'findSuccessRateOrderByCount()는' , ( ) => {
39- const mockQueryResult = {
40- query : 'SELECT host, is_error FROM http_log GROUP BY host ORDER BY is_error_rate' ,
41- params : { } ,
42- } ;
37+ describe ( 'findSuccessRateOrderByCount()는 ' , ( ) => {
38+ const mockDate = '2024-11-25' ;
39+ const mockQueryResult = {
40+ query : 'SELECT host, is_error FROM http_log GROUP BY host ORDER BY is_error_rate' ,
41+ params : { } ,
42+ } ;
4343
44- const mockResults = [
45- { host : 'test1.com' , is_error_rate : 10 } ,
46- { host : 'test2.com' , is_error_rate : 20 } ,
47- ] ;
44+ const mockResults = [
45+ { host : 'test1.com' , is_error_rate : 10 } ,
46+ { host : 'test2.com' , is_error_rate : 20 } ,
47+ ] ;
4848
49- beforeEach ( ( ) => {
50- ( TimeSeriesQueryBuilder as jest . Mock ) . mockImplementation ( ( ) => ( {
51- metrics : jest . fn ( ) . mockReturnThis ( ) ,
52- from : jest . fn ( ) . mockReturnThis ( ) ,
53- groupBy : jest . fn ( ) . mockReturnThis ( ) ,
54- orderBy : jest . fn ( ) . mockReturnThis ( ) ,
55- build : jest . fn ( ) . mockReturnValue ( mockQueryResult ) ,
56- } ) ) ;
57- } ) ;
49+ beforeEach ( ( ) => {
50+ ( TimeSeriesQueryBuilder as jest . Mock ) . mockImplementation ( ( ) => ( {
51+ metrics : jest . fn ( ) . mockReturnThis ( ) ,
52+ from : jest . fn ( ) . mockReturnThis ( ) ,
53+ filter : jest . fn ( ) . mockReturnThis ( ) ,
54+ groupBy : jest . fn ( ) . mockReturnThis ( ) ,
55+ orderBy : jest . fn ( ) . mockReturnThis ( ) ,
56+ build : jest . fn ( ) . mockReturnValue ( mockQueryResult ) ,
57+ } ) ) ;
58+ } ) ;
5859
59- it ( 'TimeSeriesQueryBuilder를 사용하여 쿼리를 생성해야 한다' , async ( ) => {
60- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
60+ it ( 'TimeSeriesQueryBuilder를 사용하여 쿼리를 생성해야 한다' , async ( ) => {
61+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
6162
62- await repository . findSuccessRateOrderByCount ( ) ;
63+ await repository . findSuccessRateOrderByCount ( mockDate ) ;
6364
64- expect ( TimeSeriesQueryBuilder ) . toHaveBeenCalled ( ) ;
65- } ) ;
65+ expect ( TimeSeriesQueryBuilder ) . toHaveBeenCalled ( ) ;
66+ } ) ;
6667
67- it ( '생성된 쿼리로 Clickhouse를 호출해야 한다' , async ( ) => {
68- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
68+ it ( '생성된 쿼리로 Clickhouse를 호출해야 한다' , async ( ) => {
69+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
6970
70- await repository . findSuccessRateOrderByCount ( ) ;
71+ await repository . findSuccessRateOrderByCount ( mockDate ) ;
7172
72- expect ( clickhouse . query ) . toHaveBeenCalledWith (
73- mockQueryResult . query ,
74- mockQueryResult . params ,
75- ) ;
76- } ) ;
73+ expect ( clickhouse . query ) . toHaveBeenCalledWith (
74+ mockQueryResult . query ,
75+ mockQueryResult . params ,
76+ ) ;
77+ } ) ;
7778
78- it ( '조회 결과는 HostErrorRateMetric 객체 타입을 가져야한다' , async ( ) => {
79- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
79+ it ( '조회 결과는 HostErrorRateMetric 객체 타입을 가져야한다' , async ( ) => {
80+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
8081
81- const results = await repository . findSuccessRateOrderByCount ( ) ;
82+ const results = await repository . findSuccessRateOrderByCount ( mockDate ) ;
8283
83- expect ( results ) . toHaveLength ( mockResults . length ) ;
84- results . forEach ( ( result , index ) => {
85- expect ( typeof result . host ) . toBe ( 'string' ) ;
86- expect ( typeof result . is_error_rate ) . toBe ( 'number' ) ;
87- expect ( result . host ) . toBe ( mockResults [ index ] . host ) ;
88- expect ( result . is_error_rate ) . toBe ( mockResults [ index ] . is_error_rate ) ;
89- } ) ;
84+ expect ( results ) . toHaveLength ( mockResults . length ) ;
85+ results . forEach ( ( result , index ) => {
86+ expect ( typeof result . host ) . toBe ( 'string' ) ;
87+ expect ( typeof result . is_error_rate ) . toBe ( 'number' ) ;
88+ expect ( result . host ) . toBe ( mockResults [ index ] . host ) ;
89+ expect ( result . is_error_rate ) . toBe ( mockResults [ index ] . is_error_rate ) ;
9090 } ) ;
91+ } ) ;
9192
92- it ( 'Clickhouse 쿼리 실패 시 에러를 전파해야 한다' , async ( ) => {
93- const error = new Error ( 'Clickhouse query failed' ) ;
94- mockClickhouse . query . mockRejectedValue ( error ) ;
93+ it ( 'Clickhouse 쿼리 실패 시 에러를 전파해야 한다' , async ( ) => {
94+ const error = new Error ( 'Clickhouse query failed' ) ;
95+ mockClickhouse . query . mockRejectedValue ( error ) ;
9596
96- await expect ( repository . findSuccessRateOrderByCount ( ) ) . rejects . toThrow ( error ) ;
97- } ) ;
97+ await expect ( repository . findSuccessRateOrderByCount ( mockDate ) ) . rejects . toThrow ( error ) ;
9898 } ) ;
99+ } ) ;
99100
100- describe ( 'findCountOrderByCount()는' , ( ) => {
101- const mockQueryResult = {
102- query : 'SELECT host, count() as count FROM http_log GROUP BY host ORDER BY count' ,
103- params : { } ,
104- } ;
101+ describe ( 'findCountOrderByCount()는' , ( ) => {
102+ const mockQueryResult = {
103+ query : 'SELECT host, count() as count FROM http_log GROUP BY host ORDER BY count' ,
104+ params : { } ,
105+ } ;
105106
106- const mockResults = [
107- { host : 'test1.com' , count : 9999 } ,
108- { host : 'test2.com' , count : 9898 } ,
109- ] ;
107+ const mockResults = [
108+ { host : 'test1.com' , count : 9999 } ,
109+ { host : 'test2.com' , count : 9898 } ,
110+ ] ;
110111
111- beforeEach ( ( ) => {
112- ( TimeSeriesQueryBuilder as jest . Mock ) . mockImplementation ( ( ) => ( {
113- metrics : jest . fn ( ) . mockReturnThis ( ) ,
114- from : jest . fn ( ) . mockReturnThis ( ) ,
115- groupBy : jest . fn ( ) . mockReturnThis ( ) ,
116- orderBy : jest . fn ( ) . mockReturnThis ( ) ,
117- build : jest . fn ( ) . mockReturnValue ( mockQueryResult ) ,
118- } ) ) ;
119- } ) ;
112+ beforeEach ( ( ) => {
113+ ( TimeSeriesQueryBuilder as jest . Mock ) . mockImplementation ( ( ) => ( {
114+ metrics : jest . fn ( ) . mockReturnThis ( ) ,
115+ from : jest . fn ( ) . mockReturnThis ( ) ,
116+ groupBy : jest . fn ( ) . mockReturnThis ( ) ,
117+ orderBy : jest . fn ( ) . mockReturnThis ( ) ,
118+ build : jest . fn ( ) . mockReturnValue ( mockQueryResult ) ,
119+ } ) ) ;
120+ } ) ;
120121
121- it ( 'TimeSeriesQueryBuilder를 사용하여 쿼리를 생성해야 한다' , async ( ) => {
122- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
122+ it ( 'TimeSeriesQueryBuilder를 사용하여 쿼리를 생성해야 한다' , async ( ) => {
123+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
123124
124- await repository . findCountOrderByCount ( ) ;
125+ await repository . findCountOrderByCount ( ) ;
125126
126- expect ( TimeSeriesQueryBuilder ) . toHaveBeenCalled ( ) ;
127- } ) ;
127+ expect ( TimeSeriesQueryBuilder ) . toHaveBeenCalled ( ) ;
128+ } ) ;
128129
129- it ( '생성된 쿼리로 Clickhouse를 호출해야 한다' , async ( ) => {
130- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
130+ it ( '생성된 쿼리로 Clickhouse를 호출해야 한다' , async ( ) => {
131+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
131132
132- await repository . findCountOrderByCount ( ) ;
133+ await repository . findCountOrderByCount ( ) ;
133134
134- expect ( clickhouse . query ) . toHaveBeenCalledWith (
135- mockQueryResult . query ,
136- mockQueryResult . params ,
137- ) ;
138- } ) ;
135+ expect ( clickhouse . query ) . toHaveBeenCalledWith (
136+ mockQueryResult . query ,
137+ mockQueryResult . params ,
138+ ) ;
139+ } ) ;
139140
140- it ( '조회 결과는 HostCountMetric 객체 타입을 가져야한다' , async ( ) => {
141- mockClickhouse . query . mockResolvedValue ( mockResults ) ;
141+ it ( '조회 결과는 HostCountMetric 객체 타입을 가져야한다' , async ( ) => {
142+ mockClickhouse . query . mockResolvedValue ( mockResults ) ;
142143
143- const results = await repository . findCountOrderByCount ( ) ;
144+ const results = await repository . findCountOrderByCount ( ) ;
144145
145- expect ( results ) . toHaveLength ( mockResults . length ) ;
146- results . forEach ( ( result , index ) => {
147- expect ( typeof result . host ) . toBe ( 'string' ) ;
148- expect ( typeof result . count ) . toBe ( 'number' ) ;
149- expect ( result . host ) . toBe ( mockResults [ index ] . host ) ;
150- expect ( result . count ) . toBe ( mockResults [ index ] . count ) ;
151- } ) ;
146+ expect ( results ) . toHaveLength ( mockResults . length ) ;
147+ results . forEach ( ( result , index ) => {
148+ expect ( typeof result . host ) . toBe ( 'string' ) ;
149+ expect ( typeof result . count ) . toBe ( 'number' ) ;
150+ expect ( result . host ) . toBe ( mockResults [ index ] . host ) ;
151+ expect ( result . count ) . toBe ( mockResults [ index ] . count ) ;
152152 } ) ;
153+ } ) ;
153154
154- it ( 'Clickhouse 쿼리 실패 시 에러를 전파해야 한다' , async ( ) => {
155- const error = new Error ( 'Clickhouse query failed' ) ;
156- mockClickhouse . query . mockRejectedValue ( error ) ;
155+ it ( 'Clickhouse 쿼리 실패 시 에러를 전파해야 한다' , async ( ) => {
156+ const error = new Error ( 'Clickhouse query failed' ) ;
157+ mockClickhouse . query . mockRejectedValue ( error ) ;
157158
158- await expect ( repository . findCountOrderByCount ( ) ) . rejects . toThrow ( error ) ;
159- } ) ;
159+ await expect ( repository . findCountOrderByCount ( ) ) . rejects . toThrow ( error ) ;
160160 } ) ;
161161 } ) ;
162162
0 commit comments