Skip to content

Commit

Permalink
test: uses new test structure in CLI reporter and sanitation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Aug 19, 2019
1 parent a159b48 commit 8feadd5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/sanitation/entire-response-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.expected.bodySchema = '';

transaction.test.message = '';
delete transaction.test.results.body;
delete transaction.test.results.fields.body;
done();
});
2 changes: 1 addition & 1 deletion test/fixtures/sanitation/plain-text-response-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.expected.body = replaceToken(transaction.test.expected.body);

// Remove sensitive data from the Gavel validation result
const bodyResult = transaction.test.results.body;
const bodyResult = transaction.test.results.fields.body;
bodyResult.values.expected = replaceToken(bodyResult.values.expected);
bodyResult.values.actual = replaceToken(bodyResult.values.actual);

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/sanitation/response-body-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.expected.bodySchema = JSON.stringify(bodySchema);

// Removes sensitive data from the Gavel validation result
const bodyResult = transaction.test.results.body;
const bodyResult = transaction.test.results.fields.body;
bodyResult.errors = bodyResult.errors.filter(error => error.location.pointer !== '/token');
bodyResult.values.expected = unfold(bodyResult.values.expected, deleteToken);
bodyResult.values.actual = unfold(bodyResult.values.actual, deleteToken);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/sanitation/response-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hooks.after('Resource > Update Resource', (transaction, done) => {
transaction.test.expected.headers = deleteSensitiveHeader('authorization', transaction.test.expected.headers);

// Remove sensitive data from the Gavel validation result
const headersResult = transaction.test.results.headers;
const headersResult = transaction.test.results.fields.headers;
headersResult.errors = headersResult.errors.filter(error => error.location.pointer.toLowerCase() !== '/authorization');
headersResult.values.expected = deleteSensitiveHeader('authorization', headersResult.values.expected);

Expand Down
12 changes: 6 additions & 6 deletions test/integration/cli/reporters-cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ describe('CLI - Reporters', () => {
});
it('should send results from gavel', () => {
assert.isObject(stepRequest.body);
assert.nestedProperty(stepRequest.body, 'resultData.request');
assert.nestedProperty(stepRequest.body, 'resultData.realResponse');
assert.nestedProperty(stepRequest.body, 'resultData.expectedResponse');
assert.nestedProperty(stepRequest.body, 'resultData.result.body.kind');
assert.nestedProperty(stepRequest.body, 'resultData.result.headers.kind');
assert.nestedProperty(stepRequest.body, 'resultData.result.statusCode.kind');
assert.nestedProperty(stepRequest.body, 'results.request');
assert.nestedProperty(stepRequest.body, 'results.realResponse');
assert.nestedProperty(stepRequest.body, 'results.expectedResponse');
assert.nestedProperty(stepRequest.body, 'results.validationResult.fields.body');
assert.nestedProperty(stepRequest.body, 'results.validationResult.fields.headers');
assert.nestedProperty(stepRequest.body, 'results.validationResult.fields.statusCode');
});
});

Expand Down
14 changes: 8 additions & 6 deletions test/integration/sanitation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ describe('Sanitation of Reported Data', () => {
]));
it('emitted test is failed', () => {
assert.equal(events[2].test.status, 'fail');
assert.include(events[2].test.results.general.results[0].message.toLowerCase(), 'fail');
assert.include(events[2].test.errors[0].message.toLowerCase(), 'fail');
});
it('emitted test data results contain just \'general\' section', () => assert.hasAllKeys(events[2].test.results, ['general']));
it('emitted test data results contain just \'errors\' section', () => assert.containsAllKeys(events[2].test, ['errors']));
it('sensitive data cannot be found anywhere in the emitted test data', () => {
const test = JSON.stringify(events);
assert.notInclude(test, sensitiveKey);
Expand Down Expand Up @@ -492,10 +492,12 @@ describe('Sanitation of Reported Data', () => {
it('emitted test data does not contain request body', () => assert.equal(events[2].test.request.body, ''));
it('emitted test is failed', () => {
assert.equal(events[2].test.status, 'fail');
assert.include(events[2].test.results.general.results[0].message.toLowerCase(), 'fail');
assert.include(events[2].test.errors[0].message.toLowerCase(), 'fail');
});
it('emitted test data results contain all regular sections', () => {
assert.hasAllKeys(events[2].test.results, ['general', 'statusCode', 'headers', 'body']);
assert.containsAllKeys(events[2].test, ['errors']);
assert.hasAllKeys(events[2].test.results, ['valid', 'fields']);
assert.hasAllKeys(events[2].test.results.fields, ['statusCode', 'headers', 'body']);
});
it('sensitive data cannot be found anywhere in the emitted test data', () => {
const test = JSON.stringify(events);
Expand Down Expand Up @@ -532,8 +534,8 @@ describe('Sanitation of Reported Data', () => {
]));
it('emitted test is skipped', () => {
assert.equal(events[2].test.status, 'skip');
assert.hasAllKeys(events[2].test.results, ['general']);
assert.include(events[2].test.results.general.results[0].message.toLowerCase(), 'skip');
assert.containsAllKeys(events[2].test, ['errors']);
assert.include(events[2].test.errors[0].message.toLowerCase(), 'skip');
});
it('sensitive data cannot be found anywhere in the emitted test data', () => {
const test = JSON.stringify(events);
Expand Down

0 comments on commit 8feadd5

Please sign in to comment.