@@ -87,4 +87,80 @@ describe("partitionByMethod", () => {
8787 expect ( postMethodNode ?. children ) . toHaveLength ( 1 ) ;
8888 expect ( postMethodNode ?. children ?. [ 0 ] ?. key ) . toBe ( "POST /auth/login" ) ;
8989 } ) ;
90+
91+ test ( "hashObjects를 리턴한다" , ( ) => {
92+ const spec : CanonicalSpec = {
93+ operations : {
94+ "GET /user" : {
95+ key : "GET /user" ,
96+ doc : { tags : [ "user" ] } ,
97+ method : "GET" ,
98+ path : "/user" ,
99+ request : { params : [ ] } ,
100+ responses : { } ,
101+ } ,
102+ "POST /user" : {
103+ key : "POST /user" ,
104+ doc : { tags : [ "user" ] } ,
105+ method : "POST" ,
106+ path : "/user" ,
107+ request : { params : [ ] } ,
108+ responses : { } ,
109+ } ,
110+ } ,
111+ } ;
112+
113+ const result = partitionByMethod ( spec ) ;
114+
115+ expect ( result . hashObjects ) . toBeDefined ( ) ;
116+ expect ( result . hashObjects ) . toHaveLength ( 2 ) ;
117+ } ) ;
118+
119+ test ( "리프노드에는 value가 포함되지 않는다" , ( ) => {
120+ const spec : CanonicalSpec = {
121+ operations : {
122+ "GET /user" : {
123+ key : "GET /user" ,
124+ doc : { tags : [ "user" ] } ,
125+ method : "GET" ,
126+ path : "/user" ,
127+ request : { params : [ ] } ,
128+ responses : { } ,
129+ } ,
130+ } ,
131+ } ;
132+
133+ const result = partitionByMethod ( spec ) ;
134+ const leafNode = result . root . children ?. [ 0 ] ?. children ?. [ 0 ] ;
135+
136+ expect ( leafNode ?. type ) . toBe ( "leaf" ) ;
137+ expect ( leafNode ?. hash ) . toBeDefined ( ) ;
138+ expect ( leafNode ?. value ) . toBeUndefined ( ) ;
139+ } ) ;
140+
141+ test ( "hashObjects에 리프노드에 대한 CanonicalOperation 이 매핑된다" , ( ) => {
142+ const operation = {
143+ key : "GET /user" as const ,
144+ doc : { tags : [ "user" ] } ,
145+ method : "GET" as const ,
146+ path : "/user" ,
147+ request : { params : [ ] } ,
148+ responses : { } ,
149+ } ;
150+
151+ const spec : CanonicalSpec = {
152+ operations : {
153+ "GET /user" : operation ,
154+ } ,
155+ } ;
156+
157+ const result = partitionByMethod ( spec ) ;
158+ const leafNode = result . root . children ?. [ 0 ] ?. children ?. [ 0 ] ;
159+ const hashObject = result . hashObjects . find (
160+ ( ho ) => ho . hash === leafNode ?. hash ,
161+ ) ;
162+
163+ expect ( hashObject ) . toBeDefined ( ) ;
164+ expect ( hashObject ?. data ) . toEqual ( operation ) ;
165+ } ) ;
90166} ) ;
0 commit comments