Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
refactor: use camelCase for filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek authored and kylef committed Feb 25, 2019
1 parent d1744f8 commit 4d9c765
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 42 deletions.
8 changes: 4 additions & 4 deletions lib/compile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const detectTransactionExampleNumbers = require('./detect-transaction-example-numbers');
const compileUri = require('./compile-uri');
const getTransactionName = require('./transaction-name');
const detectTransactionExampleNumbers = require('./detectTransactionExampleNumbers');
const compileUri = require('./compileURI');
const compileTransactionName = require('./compileTransactionName');


function findRelevantTransactions(mediaType, apiElements) {
Expand Down Expand Up @@ -157,7 +157,7 @@ function compileTransaction(mediaType, filename, httpTransactionElement, example

if (!request) { return { transaction: null, annotations }; }

const name = getTransactionName(origin);
const name = compileTransactionName(origin);
const response = compileResponse(httpTransactionElement.response);

const transaction = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function index(origin) {
module.exports = function compileTransactionName(origin) {
const segments = [];
if (origin.apiName) { segments.push(origin.apiName); }
if (origin.resourceGroupName) { segments.push(origin.resourceGroupName); }
Expand Down
File renamed without changes.
9 changes: 5 additions & 4 deletions lib/compile-uri/index.js → lib/compileURI/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const compileParams = require('./compile-params');
const validateParams = require('./validate-params');
const expandUriTemplate = require('./expand-uri-template');
const compileParams = require('./compileParams');
const validateParams = require('./validateParams');
const expandUriTemplate = require('./expandURItemplate');

module.exports = function index(httpRequestElement) {

module.exports = function compileURI(httpRequestElement) {
const annotations = [];
const cascade = [
httpRequestElement.parents.find('resource'),
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions test/integration/compile-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const proxyquire = require('proxyquire').noPreserveCache();

const createAnnotationSchema = require('../schemas/annotation');
const createCompileResultSchema = require('../schemas/compile-result');
const createAnnotationSchema = require('../schemas/createAnnotationSchema');
const createCompileResultSchema = require('../schemas/createCompileResultSchema');

const { assert, fixtures } = require('../support');
const compile = require('../../lib/compile');
Expand Down Expand Up @@ -147,8 +147,8 @@ describe('compile() · all API description formats', () => {
fixtures('ordinary').forEachDescribe(({ mediaType, apiElements }) => {
const message = '... dummy warning message ...';
const stubbedCompile = proxyquire('../../lib/compile', {
'./compile-uri': proxyquire('../../lib/compile-uri', {
'./expand-uri-template': () => ({ uri: '/honey?beekeeper=Honza', errors: [], warnings: [message] }),
'./compileURI': proxyquire('../../lib/compileURI', {
'./expandURItemplate': () => ({ uri: '/honey?beekeeper=Honza', errors: [], warnings: [message] }),
}),
});
const compileResult = stubbedCompile(mediaType, apiElements);
Expand Down Expand Up @@ -208,8 +208,8 @@ describe('compile() · all API description formats', () => {
fixtures('ordinary').forEachDescribe(({ mediaType, apiElements }) => {
const message = '... dummy warning message ...';
const stubbedCompile = proxyquire('../../lib/compile', {
'./compile-uri': proxyquire('../../lib/compile-uri', {
'./validate-params': () => ({ errors: [], warnings: [message] }),
'./compileURI': proxyquire('../../lib/compileURI', {
'./validateParams': () => ({ errors: [], warnings: [message] }),
}),
});
const compileResult = stubbedCompile(mediaType, apiElements);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire').noPreserveCache();

const createAnnotationSchema = require('../schemas/annotation');
const createCompileResultSchema = require('../schemas/compile-result');
const detectTransactionExampleNumbers = require('../../lib/detect-transaction-example-numbers');
const createAnnotationSchema = require('../schemas/createAnnotationSchema');
const createCompileResultSchema = require('../schemas/createCompileResultSchema');
const detectTransactionExampleNumbers = require('../../lib/detectTransactionExampleNumbers');

const { assert, fixtures } = require('../support');
const compile = require('../../lib/compile');
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('compile() · API Blueprint', () => {
describe('with multiple transaction examples', () => {
const detectTransactionExampleNumbersStub = sinon.spy(detectTransactionExampleNumbers);
const stubbedCompile = proxyquire('../../lib/compile', {
'./detect-transaction-example-numbers': detectTransactionExampleNumbersStub,
'./detectTransactionExampleNumbers': detectTransactionExampleNumbersStub,
});
const { mediaType, apiElements } = fixtures('multiple-transaction-examples').apib;
const compileResult = stubbedCompile(mediaType, apiElements);
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('compile() · API Blueprint', () => {
describe('without multiple transaction examples', () => {
const detectTransactionExampleNumbersStub = sinon.spy(detectTransactionExampleNumbers);
const stubbedCompile = proxyquire('../../lib/compile', {
'./detect-transaction-example-numbers': detectTransactionExampleNumbersStub,
'./detectTransactionExampleNumbers': detectTransactionExampleNumbersStub,
});
const { mediaType, apiElements } = fixtures('one-transaction-example').apib;
const compileResult = stubbedCompile(mediaType, apiElements);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire');

const createAnnotationSchema = require('../schemas/annotation');
const createCompileResultSchema = require('../schemas/compile-result');
const detectTransactionExampleNumbers = require('../../lib/detect-transaction-example-numbers');
const createAnnotationSchema = require('../schemas/createAnnotationSchema');
const createCompileResultSchema = require('../schemas/createCompileResultSchema');
const detectTransactionExampleNumbers = require('../../lib/detectTransactionExampleNumbers');

const { assert, fixtures } = require('../support');
const compile = require('../../lib/compile');
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('compile() · OpenAPI 2', () => {
const filename = 'apiDescription.json';
const detectTransactionExampleNumbersStub = sinon.spy(detectTransactionExampleNumbers);
const stubbedCompile = proxyquire('../../lib/compile', {
'./detect-transaction-example-numbers': detectTransactionExampleNumbersStub,
'./detectTransactionExampleNumbers': detectTransactionExampleNumbersStub,
});
const { mediaType, apiElements } = fixtures('multiple-responses').openapi2;
const compileResult = stubbedCompile(mediaType, apiElements, filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const createCompileResultSchema = require('../schemas/compile-result');
const createCompileResultSchema = require('../schemas/createCompileResultSchema');

const { assert, fixtures } = require('../support');
const compile = require('../../lib/compile');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const proxyquire = require('proxyquire').noPreserveCache();

const createCompileResultSchema = require('../schemas/compile-result');
const createAnnotationSchema = require('../schemas/annotation');
const createCompileResultSchema = require('../schemas/createCompileResultSchema');
const createAnnotationSchema = require('../schemas/createAnnotationSchema');
const dreddTransactions = require('../../lib/index');

const { assert, fixtures } = require('../support');


describe('Dredd Transactions', () => {
describe('when compilation throws an exception', () => {
const error = new Error('... dummy message ...');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const createLocationSchema = require('./location');
const createOriginSchema = require('./origin');
const createLocationSchema = require('./createLocationSchema');
const createOriginSchema = require('./createOriginSchema');

const TYPES = ['error', 'warning'];
const COMPONENTS = ['apiDescriptionParser', 'parametersValidation', 'uriTemplateExpansion'];


module.exports = function createAnnotationSchema(options = {}) {
// Either filename string or undefined (= doesn't matter)
const { filename } = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const createOriginSchema = require('./origin');
const createAnnotationSchema = require('./annotation');
const createOriginSchema = require('./createOriginSchema');
const createAnnotationSchema = require('./createAnnotationSchema');


function addMinMax(schema, n) {
const modifiedSchema = Object.assign({}, schema);
Expand All @@ -15,6 +16,7 @@ function addMinMax(schema, n) {
return modifiedSchema;
}


module.exports = function createCompileResultSchema(options = {}) {
// Either filename string or undefined (= doesn't matter)
const { filename } = options;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { assert } = require('chai');

const getTransactionName = require('../../../lib/transaction-name');
const compileTransactionName = require('../../lib/compileTransactionName');

describe('getTransactionName()', () => {
it('is a function', () => assert.isFunction(getTransactionName));

describe('compileTransactionName()', () => {
it('is a function', () => assert.isFunction(compileTransactionName));

it('joins all parts of the origin object', () => {
const name = getTransactionName({
const name = compileTransactionName({
apiName: 'a',
resourceGroupName: 'b',
resourceName: 'c',
Expand All @@ -17,7 +18,7 @@ describe('getTransactionName()', () => {
});

it('joins just the parts of the origin object, which are available', () => {
const name = getTransactionName({
const name = compileTransactionName({
apiName: null,
resourceGroupName: 'a',
resourceName: undefined,
Expand All @@ -28,7 +29,7 @@ describe('getTransactionName()', () => {
});

it('returns no separators if the origin object contains just one part', () => {
const name = getTransactionName({
const name = compileTransactionName({
apiName: null,
resourceGroupName: 'a',
resourceName: undefined,
Expand All @@ -39,7 +40,7 @@ describe('getTransactionName()', () => {
});

it('does not mind if any part of the origin object already contains the separator', () => {
const name = getTransactionName({
const name = compileTransactionName({
apiName: 'a',
resourceGroupName: 'b',
resourceName: 'c',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { assert } = require('chai');
const fury = require('fury');

const compileParams = require('../../../lib/compile-uri/compile-params');
const compileParams = require('../../../lib/compileURI/compileParams');


describe('compileParams()', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { assert } = require('chai');

const expandUriTemplate = require('../../../lib/compile-uri/expand-uri-template');
const expandUriTemplate = require('../../../lib/compileURI/expandURItemplate');


describe('expandUriTemplate()', () => {
let data = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { assert } = require('chai');

const validateParams = require('../../../lib/compile-uri/validate-params');
const validateParams = require('../../../lib/compileURI/validateParams');


describe('validateParams()', () => {
it('should return an object', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const detectTransactionExampleNumbers = require('../../lib/detect-transaction-example-numbers');
const detectTransactionExampleNumbers = require('../../lib/detectTransactionExampleNumbers');
const parse = require('../../lib/parse');

const { assert } = require('../support');
Expand Down

0 comments on commit 4d9c765

Please sign in to comment.