This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dom Harrington
committed
Aug 16, 2017
1 parent
bfd28a2
commit d954b6b
Showing
6 changed files
with
112 additions
and
8 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,23 @@ | ||
const React = require('react'); | ||
const { shallow } = require('enzyme'); | ||
const Doc = require('../src/Doc'); | ||
|
||
const oas = require('./fixtures/petstore/oas'); | ||
|
||
test('should output a div', () => { | ||
const doc = shallow( | ||
<Doc | ||
doc={{ | ||
title: 'Title', | ||
slug: 'slug', | ||
type: 'endpoint', | ||
swagger: { path: '/pet/{petId}' }, | ||
api: { method: 'get' }, | ||
}} | ||
oas={oas} | ||
setLanguage={() => {}} | ||
/>, | ||
); | ||
|
||
expect(doc.find('.hub-reference').length).toBe(1); | ||
}); |
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
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,61 @@ | ||
const Oas = require('../../src/lib/Oas'); | ||
|
||
describe('hasAuth()', () => { | ||
test('should return true if there is a top level security object', () => { | ||
expect(new Oas({ security: [{ 'security-scheme': [] }] }).hasAuth()).toBe(true); | ||
expect(new Oas({ security: [{ 'security-scheme': ['scope'] }] }).hasAuth()).toBe(true); | ||
}); | ||
|
||
test('should return true if a path has security', () => { | ||
expect(new Oas({ | ||
paths: { | ||
'/path': { | ||
get: { | ||
security: [{ 'security-scheme': [] }], | ||
}, | ||
}, | ||
}, | ||
}).hasAuth('/path', 'get')).toBe(true); | ||
}); | ||
|
||
test('should return false if there is no top level security object', () => { | ||
expect(new Oas({}).hasAuth()).toBe(false); | ||
expect(new Oas({ security: [] }).hasAuth()).toBe(false); | ||
}); | ||
|
||
test('should return false if the path has no security', () => { | ||
expect(new Oas({ | ||
paths: { | ||
'/path': { | ||
get: {}, | ||
}, | ||
}, | ||
}).hasAuth('/path', 'get')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getPathOperation()', () => { | ||
test('should return a stub if there is no operation', () => { | ||
expect(new Oas({}).getPathOperation({ | ||
swagger: { path: '/path' }, | ||
api: { method: 'get' }, | ||
})).toEqual({ parameters: [] }); | ||
}); | ||
|
||
test('should return the operation if there is one', () => { | ||
const operation = { a: 1 }; | ||
expect(new Oas({ | ||
paths: { | ||
'/path': { | ||
get: operation, | ||
}, | ||
}, | ||
}).getPathOperation({ swagger: { path: '/path' }, api: { method: 'get' } })).toBe(operation); | ||
}); | ||
}); | ||
|
||
test('should be able to access properties on oas', () => { | ||
expect(new Oas({ | ||
info: { version: '1.0' }, | ||
}).info.version).toBe('1.0'); | ||
}); |
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
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
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,20 @@ | ||
const getPathOperation = require('./get-path-operation'); | ||
|
||
class Oas { | ||
constructor(oas) { | ||
Object.assign(this, oas); | ||
} | ||
|
||
hasAuth(path, method) { | ||
const operation = getPathOperation(this, { swagger: { path }, api: { method } }); | ||
|
||
const security = operation.security || this.security; | ||
return !!(security && security.length); | ||
} | ||
|
||
getPathOperation(doc) { | ||
return getPathOperation(this, doc); | ||
} | ||
} | ||
|
||
module.exports = Oas; |