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

Commit

Permalink
chore: Commence file clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
michalholasek committed Jan 31, 2018
1 parent a8f1be7 commit d1bcbb1
Show file tree
Hide file tree
Showing 64 changed files with 497 additions and 648 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
'comma-dangle': ['error', 'never'],
'consistent-return': 'off',
'func-names': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'off',
'max-len': 'off',
'no-bitwise': 'off',
'no-continue': 'off',
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/blueprint-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
module.exports = {
'./test/fixtures/multiple-examples.apib': {
raw: 'FORMAT: 1A\n\n# Machines API\n\n# Group Machines\n\n# Machines collection [/machines/{id}]\n + Parameters\n - id (number, `1`)\n\n## Get Machines [GET]\n\n- Request (application/json)\n + Parameters\n - id (number, `2`)\n\n- Response 200 (application/json; charset=utf-8)\n\n [\n {\n "type": "bulldozer",\n "name": "willy"\n }\n ]\n\n- Request (application/json)\n + Parameters\n - id (number, `3`)\n\n- Response 200 (application/json; charset=utf-8)\n\n [\n {\n "type": "bulldozer",\n "name": "willy"\n }\n ]\n',
Expand Down
17 changes: 9 additions & 8 deletions test/fixtures/groupless-names.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var hooks = require('hooks');
var before = hooks.before;
var after = hooks.after;
const hooks = require('hooks');

after(' > Machines collection > Get Machines', function(transaction){
transaction['fail'] = 'failed in sandboxed hook';
const before = hooks.before;
const after = hooks.after;

after(' > Machines collection > Get Machines', (transaction) => {
transaction.fail = 'failed in sandboxed hook';
});

before(' > Machines collection > Get Machines', function(transaction){
transaction['fail'] = 'failed in sandboxed hook';
});
before(' > Machines collection > Get Machines', (transaction) => {
transaction.fail = 'failed in sandboxed hook';
});
8 changes: 8 additions & 0 deletions test/fixtures/hooks-log.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{before, after, log} = require 'hooks'

before "Machines > Machines collection > Get Machines", (transaction) ->
log {err: 'Error object!'}
log true

after "Machines > Machines collection > Get Machines", (transaction) ->
log "using hooks.log to debug"
15 changes: 0 additions & 15 deletions test/fixtures/hooks-log.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/fixtures/multifile/multifile_hooks.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{after} = require 'hooks'

after "Name API > /name > GET", (transaction) ->
console.log "after name"

after "Greeting API > /greeting > GET", (transaction) ->
console.log "after greeting"

after "Message API > /message > GET", (transaction) ->
console.log "after message"
15 changes: 0 additions & 15 deletions test/fixtures/multifile/multifile_hooks.js

This file was deleted.

17 changes: 17 additions & 0 deletions test/fixtures/regression-152.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
hooks = require 'hooks'

# New hooks helper function
hooks.beforeEach = (hookFn) ->
hooks.beforeAll (done) ->
for transactionKey, transaction of hooks.transactions or {}
hooks.beforeHooks[transaction.name] ?= []
hooks.beforeHooks[transaction.name].unshift hookFn
done()

hooks.beforeEach (transaction) ->
# add query parameter to each transaction here
paramToAdd = "api-key=23456"
if transaction.fullPath.indexOf('?') > -1
transaction.fullPath += "&" + paramToAdd
else
transaction.fullPath += "?" + paramToAdd
31 changes: 0 additions & 31 deletions test/fixtures/regression-152.js

This file was deleted.

5 changes: 2 additions & 3 deletions test/fixtures/response/empty-body-hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var hooks = require('hooks');
const hooks = require('hooks');


hooks.beforeEachValidation(function (transaction, done) {
hooks.beforeEachValidation((transaction, done) => {
if (transaction.real.body) {
transaction.fail = 'The response body must be empty';
}
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/sandboxed-hook.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
after('Machines > Machines collection > Get Machines', function(transaction){
transaction['fail'] = 'failed in sandboxed hook';
});
after('Machines > Machines collection > Get Machines', (transaction) => {
transaction.fail = 'failed in sandboxed hook';
});
8 changes: 5 additions & 3 deletions test/fixtures/sandboxed-hooks-log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
before("Machines > Machines collection > Get Machines", function (transaction) {
/* eslint-disable no-undef */

before('Machines > Machines collection > Get Machines', () => {
log('shall not print, but be present in logs');
});

after("Machines > Machines collection > Get Machines", function (transaction) {
log("using sandboxed hooks.log");
after('Machines > Machines collection > Get Machines', () => {
log('using sandboxed hooks.log');
});
17 changes: 8 additions & 9 deletions test/fixtures/sanitation/any-content-guard-pattern-matching.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
var hooks = require('hooks');
var assert = require('chai').assert;
var tokenPattern = /([0-9]|[a-f]){24,}/g;
const assert = require('chai').assert;
const hooks = require('hooks');

hooks.beforeEach(function(transaction, done) {
const tokenPattern = /([0-9]|[a-f]){24,}/g;

hooks.beforeEach((transaction, done) => {
transaction.id = transaction.id.replace(tokenPattern, 'CENSORED');
transaction.origin.resourceName = transaction.origin.resourceName.replace(tokenPattern, 'CENSORED');
done();
});

hooks.afterEach(function(transaction, done) {
hooks.afterEach((transaction, done) => {
try {

JSON.stringify(transaction.test, function(key, value) {
JSON.stringify(transaction.test, (key, value) => {
if (typeof value === 'string') {
assert.notMatch(value, tokenPattern);
}
return value;
});

} catch (error) {
transaction.fail = 'Sensitive data would be sent to Dredd reporter';
transaction.test = {
start: transaction.test.start,
end: transaction.test.end,
duration: transaction.test.duration,
startedAt: transaction.test.startedAt,
message: transaction.fail,
message: transaction.fail
};
}
done();
Expand Down
11 changes: 6 additions & 5 deletions test/fixtures/sanitation/any-content-pattern-matching.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var hooks = require('hooks');
var tokenPattern = /([0-9]|[a-f]){24,}/g;
const hooks = require('hooks');

hooks.beforeEach(function(transaction, done) {
const tokenPattern = /([0-9]|[a-f]){24,}/g;

hooks.beforeEach((transaction, done) => {
transaction.id = transaction.id.replace(tokenPattern, 'CENSORED');
transaction.origin.resourceName = transaction.origin.resourceName.replace(tokenPattern, 'CENSORED');
done();
});

hooks.afterEach(function(transaction, done) {
var test = JSON.stringify(transaction.test, function(key, value) {
hooks.afterEach((transaction, done) => {
const test = JSON.stringify(transaction.test, (key, value) => {
if (value.replace) {
return value.replace(tokenPattern, 'CENSORED');
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/sanitation/entire-request-body.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var hooks = require('hooks');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.request.body = '';
done();
});
4 changes: 2 additions & 2 deletions test/fixtures/sanitation/entire-response-body.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var hooks = require('hooks');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.actual.body = '';
transaction.test.expected.body = '';
transaction.test.expected.bodySchema = '';
Expand Down
11 changes: 6 additions & 5 deletions test/fixtures/sanitation/plain-text-response-body.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
var hooks = require('hooks');
var tokenPattern = /([0-9]|[a-f]){24,}/g;
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
var body;
const tokenPattern = /([0-9]|[a-f]){24,}/g;

hooks.after('Resource > Update Resource', (transaction, done) => {
let body;

body = transaction.test.actual.body;
transaction.test.actual.body = body.replace(tokenPattern, '--- CENSORED ---');

body = transaction.test.expected.body;
transaction.test.expected.body = body.replace(tokenPattern, '--- CENSORED ---');

// sanitation of diff in the patch format
// Sanitation of diff in the patch format
delete transaction.test.results.body.results.rawData;
done();
});
6 changes: 3 additions & 3 deletions test/fixtures/sanitation/request-body-attribute.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var hooks = require('hooks');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
var body = JSON.parse(transaction.test.request.body);
hooks.after('Resource > Update Resource', (transaction, done) => {
const body = JSON.parse(transaction.test.request.body);
delete body.token;
transaction.test.request.body = JSON.stringify(body);
done();
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/sanitation/request-headers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var hooks = require('hooks');
var caseless = require('caseless');
const caseless = require('caseless');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
var headers = transaction.test.request.headers;
var name = caseless(headers).has('Authorization');
hooks.after('Resource > Update Resource', (transaction, done) => {
const headers = transaction.test.request.headers;
const name = caseless(headers).has('Authorization');
delete headers[name];
transaction.test.request.headers = headers;
done();
Expand Down
24 changes: 12 additions & 12 deletions test/fixtures/sanitation/response-body-attribute.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var hooks = require('hooks');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
// sanitation of the attribute in body
var body;
hooks.after('Resource > Update Resource', (transaction, done) => {
// Sanitation of the attribute in body
let body;

body = JSON.parse(transaction.test.actual.body);
delete body.token;
Expand All @@ -12,24 +12,24 @@ hooks.after('Resource > Update Resource', function(transaction, done) {
delete body.token;
transaction.test.expected.body = JSON.stringify(body);

// sanitation of the attribute in JSON Schema
var bodySchema = JSON.parse(transaction.test.expected.bodySchema);
// Sanitation of the attribute in JSON Schema
const bodySchema = JSON.parse(transaction.test.expected.bodySchema);
delete bodySchema.properties.token;
transaction.test.expected.bodySchema = JSON.stringify(bodySchema);

// sanitation of the attribute in validation output
var validationOutput = transaction.test.results.body;
// Sanitation of the attribute in validation output
const validationOutput = transaction.test.results.body;

var errors = [];
for (var i = 0; i < validationOutput.results.length; i++) {
const errors = [];
for (let i = 0; i < validationOutput.results.length; i++) {
if (validationOutput.results[i].pointer !== '/token') {
errors.push(validationOutput.results[i]);
}
}
validationOutput.results = errors;

var rawData = [];
for (var i = 0; i < validationOutput.rawData.length; i++) {
const rawData = [];
for (let i = 0; i < validationOutput.rawData.length; i++) {
if (validationOutput.rawData[i].property[0] !== 'token') {
rawData.push(validationOutput.rawData[i]);
}
Expand Down
22 changes: 11 additions & 11 deletions test/fixtures/sanitation/response-headers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var hooks = require('hooks');
var caseless = require('caseless');
const caseless = require('caseless');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
var headers;
var name;
hooks.after('Resource > Update Resource', (transaction, done) => {
let headers;
let name;

headers = transaction.test.actual.headers;
name = caseless(headers).has('authorization');
Expand All @@ -15,19 +15,19 @@ hooks.after('Resource > Update Resource', function(transaction, done) {
delete headers[name];
transaction.test.expected.headers = headers;

// sanitation of the header in validation output
var validationOutput = transaction.test.results.headers;
// Sanitation of the header in validation output
const validationOutput = transaction.test.results.headers;

var errors = [];
for (var i = 0; i < validationOutput.results.length; i++) {
const errors = [];
for (let i = 0; i < validationOutput.results.length; i++) {
if (validationOutput.results[i].pointer.toLowerCase() !== '/authorization') {
errors.push(validationOutput.results[i]);
}
}
validationOutput.results = errors;

var rawData = [];
for (var i = 0; i < validationOutput.rawData.length; i++) {
const rawData = [];
for (let i = 0; i < validationOutput.rawData.length; i++) {
if (validationOutput.rawData[i].property[0].toLowerCase() !== 'authorization') {
rawData.push(validationOutput.rawData[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/sanitation/transaction-erroring-hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var hooks = require('hooks');
const hooks = require('hooks');

hooks.after('Resource > Update Resource', function(transaction, done) {
hooks.after('Resource > Update Resource', (transaction, done) => {
JSON.parse('💥 boom 💥');
done();
});
Loading

0 comments on commit d1bcbb1

Please sign in to comment.