Skip to content

Commit 8317abd

Browse files
committed
MOAR tests
1 parent bb09a59 commit 8317abd

File tree

1 file changed

+95
-7
lines changed

1 file changed

+95
-7
lines changed

test/helpers.js

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ describe('helpers', function () {
124124

125125
describe('normalizeSwagger', function () {
126126
describe('operationId', function () {
127-
it('should create unique operationIds when explicit operationIds are duplicates', function () {
128-
const spec = {spec: {
127+
it('should create unique operationIds when explicit operationIds are duplicates, and preserve originals', function () {
128+
const input = {spec: {
129129
paths: {
130130
'/foo': {
131131
get: {
@@ -136,17 +136,27 @@ describe('helpers', function () {
136136
get: {
137137
operationId: 'test'
138138
}
139+
},
140+
'/baz': {
141+
get: {
142+
operationId: 'test'
143+
}
139144
}
140145
}
141146
}}
142147

143-
const id = normalizeSwagger(spec)
144-
const id1 = id.spec.paths['/foo'].get.operationId
145-
const id2 = id.spec.paths['/bar'].get.operationId
148+
const res = normalizeSwagger(input)
149+
const fooRes = res.spec.paths['/foo'].get
150+
const barRes = res.spec.paths['/bar'].get
151+
const bazRes = res.spec.paths['/baz'].get
146152

147153
// Then
148-
expect(id1).toEqual('test1')
149-
expect(id2).toEqual('test2')
154+
expect(fooRes.operationId).toEqual('test1')
155+
expect(barRes.operationId).toEqual('test2')
156+
expect(bazRes.operationId).toEqual('test3')
157+
expect(fooRes.__originalOperationId).toEqual('test')
158+
expect(barRes.__originalOperationId).toEqual('test')
159+
expect(bazRes.__originalOperationId).toEqual('test')
150160
})
151161

152162
it('should add the normalized operation id to the spec, if a non-normalized id exists', function () {
@@ -169,6 +179,84 @@ describe('helpers', function () {
169179
expect(id).toEqual('something_with_spaces')
170180
})
171181

182+
it('should add __originalOperationId for non-duplicate, normal operationIds', function () {
183+
// Given
184+
const input = {spec: {
185+
paths: {
186+
'/foo': {
187+
get: {
188+
operationId: 'fooOperation'
189+
}
190+
},
191+
'/bar': {
192+
get: {
193+
operationId: 'barOperation'
194+
}
195+
},
196+
'/baz': {
197+
get: {
198+
operationId: 'bazOperation'
199+
}
200+
},
201+
}
202+
}}
203+
204+
// When
205+
const result = normalizeSwagger(input)
206+
const fooOperation = input.spec.paths['/foo'].get
207+
const barOperation = input.spec.paths['/bar'].get
208+
const bazOperation = input.spec.paths['/baz'].get
209+
210+
// Then
211+
expect(fooOperation.operationId).toEqual('fooOperation')
212+
expect(fooOperation.__originalOperationId).toEqual('fooOperation')
213+
214+
expect(barOperation.operationId).toEqual('barOperation')
215+
expect(barOperation.__originalOperationId).toEqual('barOperation')
216+
217+
expect(bazOperation.operationId).toEqual('bazOperation')
218+
expect(bazOperation.__originalOperationId).toEqual('bazOperation')
219+
})
220+
221+
it('should add __originalOperationId for non-duplicate, abnormal operationIds', function () {
222+
// Given
223+
const input = {spec: {
224+
paths: {
225+
'/foo': {
226+
get: {
227+
operationId: 'foo!Operation'
228+
}
229+
},
230+
'/bar': {
231+
get: {
232+
operationId: 'bar!Operation'
233+
}
234+
},
235+
'/baz': {
236+
get: {
237+
operationId: 'baz!Operation'
238+
}
239+
},
240+
}
241+
}}
242+
243+
// When
244+
const result = normalizeSwagger(input)
245+
const fooOperation = input.spec.paths['/foo'].get
246+
const barOperation = input.spec.paths['/bar'].get
247+
const bazOperation = input.spec.paths['/baz'].get
248+
249+
// Then
250+
expect(fooOperation.operationId).toEqual('foo_Operation')
251+
expect(fooOperation.__originalOperationId).toEqual('foo!Operation')
252+
253+
expect(barOperation.operationId).toEqual('bar_Operation')
254+
expect(barOperation.__originalOperationId).toEqual('bar!Operation')
255+
256+
expect(bazOperation.operationId).toEqual('baz_Operation')
257+
expect(bazOperation.__originalOperationId).toEqual('baz!Operation')
258+
})
259+
172260
it('should add the original operation id to the spec, if a non-normalized id exists', function () {
173261
// Given
174262
const spec = {spec: {

0 commit comments

Comments
 (0)