@@ -19,12 +19,18 @@ import (
1919 "testing"
2020
2121 "github.com/getkin/kin-openapi/openapi3"
22+ "github.com/mongodb/openapi/tools/cli/internal/apiversion"
2223 "github.com/mongodb/openapi/tools/cli/internal/pointer"
2324 "github.com/stretchr/testify/assert"
2425 "github.com/stretchr/testify/require"
2526)
2627
2728func TestIsOperationHiddenForEnv (t * testing.T ) {
29+ previewVersion , err := apiversion .New (apiversion .WithVersion (apiversion .PreviewStabilityLevel ))
30+ require .NoError (t , err )
31+ upcomingVersion , err := apiversion .New (apiversion .WithVersion ("2024-08-05.upcoming" ))
32+ require .NoError (t , err )
33+
2834 tests := []struct {
2935 name string
3036 operation * openapi3.Operation
@@ -101,6 +107,98 @@ func TestIsOperationHiddenForEnv(t *testing.T) {
101107 },
102108 wantHidden : false ,
103109 },
110+ {
111+ name : "Operation with targetVersion = preview and stable response content" ,
112+ operation : & openapi3.Operation {
113+ Extensions : map [string ]any {},
114+ Responses : openapi3 .NewResponses (openapi3 .WithName ("200" , & openapi3.Response {
115+ Description : pointer .Get ("Success" ),
116+ Content : map [string ]* openapi3.MediaType {
117+ "application/vnd.atlas.2024-08-05+json" : {
118+ Schema : & openapi3.SchemaRef {
119+ Extensions : map [string ]any {
120+ "envs" : "prod" ,
121+ },
122+ },
123+ },
124+ },
125+ })),
126+ },
127+ metadata : & Metadata {
128+ targetEnv : "prod" ,
129+ targetVersion : previewVersion ,
130+ },
131+ wantHidden : true ,
132+ },
133+ {
134+ name : "Operation with targetVersion = preview and preview response content" ,
135+ operation : & openapi3.Operation {
136+ Extensions : map [string ]any {},
137+ Responses : openapi3 .NewResponses (openapi3 .WithName ("200" , & openapi3.Response {
138+ Description : pointer .Get ("Success" ),
139+ Content : map [string ]* openapi3.MediaType {
140+ "application/vnd.atlas.preview+json" : {
141+ Schema : & openapi3.SchemaRef {
142+ Extensions : map [string ]any {
143+ "envs" : "dev" ,
144+ },
145+ },
146+ },
147+ },
148+ })),
149+ },
150+ metadata : & Metadata {
151+ targetEnv : "prod" ,
152+ targetVersion : previewVersion ,
153+ },
154+ wantHidden : false ,
155+ },
156+ {
157+ name : "Operation with targetVersion = upcoming and stable response content" ,
158+ operation : & openapi3.Operation {
159+ Extensions : map [string ]any {},
160+ Responses : openapi3 .NewResponses (openapi3 .WithName ("200" , & openapi3.Response {
161+ Description : pointer .Get ("Success" ),
162+ Content : map [string ]* openapi3.MediaType {
163+ "application/vnd.atlas.2024-08-05+json" : {
164+ Schema : & openapi3.SchemaRef {
165+ Extensions : map [string ]any {
166+ "envs" : "prod" ,
167+ },
168+ },
169+ },
170+ },
171+ })),
172+ },
173+ metadata : & Metadata {
174+ targetEnv : "prod" ,
175+ targetVersion : upcomingVersion ,
176+ },
177+ wantHidden : true ,
178+ },
179+ {
180+ name : "Operation with targetVersion = upcoming and upcoming response content" ,
181+ operation : & openapi3.Operation {
182+ Extensions : map [string ]any {},
183+ Responses : openapi3 .NewResponses (openapi3 .WithName ("200" , & openapi3.Response {
184+ Description : pointer .Get ("Success" ),
185+ Content : map [string ]* openapi3.MediaType {
186+ "application/vnd.atlas.2024-08-05.upcoming+json" : {
187+ Schema : & openapi3.SchemaRef {
188+ Extensions : map [string ]any {
189+ "envs" : "dev" ,
190+ },
191+ },
192+ },
193+ },
194+ })),
195+ },
196+ metadata : & Metadata {
197+ targetEnv : "prod" ,
198+ targetVersion : upcomingVersion ,
199+ },
200+ wantHidden : false ,
201+ },
104202 }
105203
106204 for _ , tt := range tests {
0 commit comments