-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(helpers): re-organize tests to reflect code structure
Refs #2717
- Loading branch information
Showing
5 changed files
with
705 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import getOperationRaw from '../../src/helpers/get-operation-raw.js'; | ||
|
||
describe('helpers', () => { | ||
describe('getOperationRaw', () => { | ||
test('should return the operation object, given an explicit operationId', () => { | ||
// Given | ||
const spec = { | ||
paths: { | ||
'/one': { | ||
get: { operationId: 'op1' }, | ||
}, | ||
}, | ||
}; | ||
|
||
// When | ||
const op = getOperationRaw(spec, 'op1'); | ||
|
||
// Then | ||
expect(op).toMatchObject({ | ||
operation: spec.paths['/one'].get, | ||
pathName: '/one', | ||
method: 'GET', | ||
}); | ||
}); | ||
|
||
test('should return the operation object, given an explicit operationId with special characters', () => { | ||
// Given | ||
const spec = { | ||
paths: { | ||
'/one': { | ||
get: { operationId: 'A.Very_Special-operationID!' }, | ||
}, | ||
}, | ||
}; | ||
|
||
// When | ||
const op = getOperationRaw(spec, 'A.Very_Special-operationID!'); | ||
|
||
// Then | ||
expect(op).toMatchObject({ | ||
operation: spec.paths['/one'].get, | ||
pathName: '/one', | ||
method: 'GET', | ||
}); | ||
}); | ||
|
||
test('should return null, given an explicit operationId that does not exist', () => { | ||
// Given | ||
const spec = { | ||
paths: { | ||
'/one': { | ||
get: { operationId: 'getOne' }, | ||
}, | ||
}, | ||
}; | ||
|
||
// When | ||
const op = getOperationRaw(spec, 'ThisOperationIdDoesNotExist'); | ||
|
||
// Then | ||
expect(op).toEqual(null); | ||
}); | ||
|
||
test('should return the operationObj, given a generated operationId', () => { | ||
// Given` | ||
const spec = { | ||
paths: { | ||
'/two': { | ||
get: { | ||
description: 'an operation', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// When | ||
const op = getOperationRaw(spec, 'get_two'); | ||
|
||
// Then | ||
expect(op).toMatchObject({ | ||
operation: spec.paths['/two'].get, | ||
pathName: '/two', | ||
method: 'GET', | ||
}); | ||
}); | ||
|
||
test('should return the operationObj, given a generated legacy operationId', () => { | ||
// Given` | ||
const spec = { | ||
paths: { | ||
'/two': { | ||
get: { | ||
description: 'an operation', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// When | ||
const op = getOperationRaw(spec, 'get-/two'); | ||
|
||
// Then | ||
expect(op).toMatchObject({ | ||
operation: spec.paths['/two'].get, | ||
pathName: '/two', | ||
method: 'GET', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import idFromPathMethod from '../../../src/helpers/id-from-path-method/index.js'; | ||
|
||
describe('helpers', () => { | ||
describe('idFromPathMethod', () => { | ||
test('should return get_one as an operationId', () => { | ||
const id = idFromPathMethod('/one', 'get'); | ||
|
||
expect(id).toEqual('get_one'); | ||
}); | ||
|
||
test('should return get_one as an operationId', () => { | ||
const id = idFromPathMethod('/one', 'get'); | ||
|
||
expect(id).toEqual('get_one'); | ||
}); | ||
|
||
test('should handle strange paths/methods correctly when in v2 mode', () => { | ||
const fn = (path, method) => | ||
idFromPathMethod(path, method, { | ||
v2OperationIdCompatibilityMode: true, | ||
}); | ||
|
||
// https://github.com/swagger-api/swagger-js/issues/1269#issue-309070070 | ||
expect(fn('/foo/{bar}/baz', 'get')).toEqual('get_foo_bar_baz'); | ||
expect(fn('/one/{foo}/{bar}', 'get')).toEqual('get_one_foo_bar'); | ||
expect(fn('/one/{bar}/-----{baz}', 'get')).toEqual('get_one_bar_baz'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.