Skip to content

Commit

Permalink
chore: Make eslint dance on the test files again
Browse files Browse the repository at this point in the history
  • Loading branch information
michalholasek committed Nov 23, 2017
1 parent 88b8b3f commit c69df06
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 206 deletions.
55 changes: 17 additions & 38 deletions test/fixtures/index.js
@@ -1,65 +1,45 @@
/* eslint-disable
consistent-return,
func-names,
max-len,
no-restricted-syntax,
no-shadow,
one-var,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.

const fs = require('fs');
const path = require('path');
const zoo = require('swagger-zoo');

const zoo = require('swagger-zoo');

const fromSwaggerZoo = function (name) {
for (const feature of zoo.features()) {
if (feature.name === name) { return feature.swagger; }
}
};

function fromSwaggerZoo(name) {
return zoo.features().reduce((result, feature) => {
if (feature.name === name) return Object.assign({}, { value: feature.swagger });
return result;
}, {}).value; // Actual result (feature.swagger)
}

const fromFile = filename => fs.readFileSync(path.join(__dirname, filename)).toString();


const FORMAT_NAMES = {
apiBlueprint: 'API Blueprint',
swagger: 'Swagger'
};


// Fixture factory. Makes sure the fixtures are available both as an iterable
// array as well as name/source mapping.
const fixture = function (apiDescriptions) {
function fixture(apiDescriptions = {}) {
// The fixture is an array
let name,
source;
const fix = ((() => {
const result = [];

for (name of Object.keys(apiDescriptions || {})) {
source = apiDescriptions[name];
result.push({ format: FORMAT_NAMES[name], source });
}

return result;
})());
const fix = Object.keys(apiDescriptions).map(apiDescription => ({
format: FORMAT_NAMES[apiDescription],
source: apiDescriptions[apiDescription]
}));

// At the same time, it is an object so we can access specific format as
// an object property
for (name of Object.keys(apiDescriptions || {})) { source = apiDescriptions[name]; fix[name] = source; }
Object.keys(apiDescriptions).forEach((apiDescription) => {
fix[apiDescription] = apiDescriptions[apiDescription];
});

// And this is handy helper for tests
fix.forEachDescribe = function (fn) {
fix.forEachDescribe = function forEachDescribe(fn) {
return this.forEach(({ format, source }) =>
describe(format, () => fn({ format, source })));
};

return fix;
};

}

// Collection of API description fixtures. To iterate over all available formats
// of specific fixture (e.g. `parserError`), use:
Expand Down Expand Up @@ -213,5 +193,4 @@ const fixtures = {
})
};


module.exports = fixtures;
9 changes: 1 addition & 8 deletions test/schemas/annotation.js
@@ -1,17 +1,10 @@
/* eslint-disable
func-names,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
const createLocationSchema = require('./location');
const createOriginSchema = require('./origin');


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


module.exports = function (options = {}) {
module.exports = function createAnnotationSchema(options = {}) {
// Either filename string or undefined (= doesn't matter)
const { filename } = options;

Expand Down
30 changes: 11 additions & 19 deletions test/schemas/compilation-result.js
@@ -1,28 +1,22 @@
/* eslint-disable
func-names,
no-param-reassign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
const createOriginSchema = require('./origin');
const createPathOriginSchema = require('./path-origin');
const createAnnotationSchema = require('./annotation');

function addMinMax(schema, n) {
const modifiedSchema = Object.assign({}, schema);

const addMinMax = function (schema, n) {
if (n.length === 1) { // [min]
schema.minItems = n[0];
modifiedSchema.minItems = n[0];
} else if (n.length === 2) { // [min, max]
[schema.minItems, schema.maxItems] = Array.from(n);
[modifiedSchema.minItems, modifiedSchema.maxItems] = Array.from(n);
} else { // exact number
schema.minItems = n;
schema.maxItems = n;
modifiedSchema.minItems = n;
modifiedSchema.maxItems = n;
}
return schema;
};

return modifiedSchema;
}

module.exports = function (options = {}) {
module.exports = function createCompilationResultSchema(options = {}) {
// Either filename string or undefined (= doesn't matter)
const { filename } = options;

Expand Down Expand Up @@ -82,14 +76,12 @@ module.exports = function (options = {}) {
const transactionsSchema = addMinMax({
type: 'array',
items: transactionSchema
}
, transactions);
}, transactions);

const annotationsSchema = addMinMax({
type: 'array',
items: createAnnotationSchema({ filename })
}
, annotations);
}, annotations);

return {
type: 'object',
Expand Down
24 changes: 10 additions & 14 deletions test/schemas/location.js
@@ -1,15 +1,11 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
module.exports = () =>
({
module.exports = () => ({
type: 'array',
items: {
type: 'array',
items: {
type: 'array',
items: [
{ type: 'number' },
{ type: 'number' }
],
additionalItems: false
}
})
;
items: [
{ type: 'number' },
{ type: 'number' }
],
additionalItems: false
}
});
7 changes: 1 addition & 6 deletions test/schemas/origin.js
@@ -1,9 +1,4 @@
/* eslint-disable
func-names,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
module.exports = function (options = {}) {
module.exports = function createOriginSchema(options = {}) {
let filenameSchema;
if (options.filename) {
filenameSchema = { type: 'string', enum: [options.filename] };
Expand Down
28 changes: 12 additions & 16 deletions test/schemas/path-origin.js
@@ -1,16 +1,12 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
module.exports = () =>
({
type: 'object',
properties: {
apiName: { type: 'string' },
resourceGroupName: { type: 'string' },
resourceName: { type: 'string' },
actionName: { type: 'string' },
exampleName: { type: 'string' }
},
required: ['apiName', 'resourceGroupName', 'resourceName', 'actionName', 'exampleName'],
additionalProperties: false
})
;
module.exports = () => ({
type: 'object',
properties: {
apiName: { type: 'string' },
resourceGroupName: { type: 'string' },
resourceName: { type: 'string' },
actionName: { type: 'string' },
exampleName: { type: 'string' }
},
required: ['apiName', 'resourceGroupName', 'resourceName', 'actionName', 'exampleName'],
additionalProperties: false
});
34 changes: 14 additions & 20 deletions test/unit/compile-uri/compile-params-test.js
@@ -1,12 +1,6 @@
/* eslint-disable
new-cap,
no-new-require,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
const { assert } = require('chai');

const fury = new require('fury');
const fury = require('fury');

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

Expand All @@ -17,7 +11,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
name: {
default: undefined,
example: undefined,
Expand All @@ -34,7 +28,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
name: {
default: undefined,
example: 'Doe',
Expand All @@ -50,7 +44,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
name: {
default: undefined,
example: 'Doe',
Expand All @@ -67,7 +61,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
name: {
default: 'Unknown',
example: undefined,
Expand All @@ -83,7 +77,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
names: {
default: undefined,
example: [],
Expand All @@ -99,7 +93,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
names: {
default: undefined,
example: ['One', 'Two'],
Expand All @@ -116,7 +110,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
names: {
default: ['Unknown'],
example: [],
Expand All @@ -132,7 +126,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
names: {
default: undefined,
example: ['One', 'Two'],
Expand All @@ -149,7 +143,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
names: {
default: ['Unknown'],
example: [],
Expand All @@ -168,7 +162,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
order: {
default: undefined,
example: 'ascending',
Expand All @@ -187,7 +181,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
order: {
default: undefined,
example: 'decending',
Expand All @@ -197,7 +191,7 @@ describe('compileParams', () => {
});
});

return it('should compile an enum href variable with default', () => {
it('should compile an enum href variable with default', () => {
const hrefVariables = new fury.minim.elements.HrefVariables();
const value = new fury.minim.elements.Element();
value.element = 'enum';
Expand All @@ -207,7 +201,7 @@ describe('compileParams', () => {

const parameters = compileParams(hrefVariables);

return assert.deepEqual(parameters, {
assert.deepEqual(parameters, {
order: {
default: 'decending',
example: 'ascending',
Expand Down

0 comments on commit c69df06

Please sign in to comment.