forked from claudiajs/claudia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging-wrap-spec.js
50 lines (50 loc) · 1.86 KB
/
logging-wrap-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const underTest = require('../src/util/logging-wrap'),
aws = require('aws-sdk');
describe('loggingWrap', () => {
'use strict';
let target, logger, originalMethods;
beforeEach(() => {
target = jasmine.createSpyObj('target', ['f1', 'f2']);
originalMethods = {};
Object.keys(target).forEach(key => {
originalMethods[key] = target[key];
});
logger = jasmine.createSpy('logger');
});
describe('call reporting', () => {
it('logs the start of each call to a log with a logName prefix', () => {
const result = underTest(target, { log: logger, logName: 'Service1' });
result.f1('a', 'b', { c: true });
expect(logger).toHaveBeenCalledWith('Service1.f1', ['a', 'b', { c: true }]);
});
it('proxies calls to underlying functions', () => {
const result = underTest(target, { log: logger, logName: 'Service1' });
result.f1('a', 'b', { c: true });
expect(originalMethods.f1).toHaveBeenCalledWith('a', 'b', { c: true });
});
it('does not explode when options are not provided', () => {
const result = underTest(target);
result.f1('a', 'b', { c: true });
expect(originalMethods.f1).toHaveBeenCalled();
});
it('does not explode when log is not provided', () => {
const result = underTest(target, {});
result.f1('a', 'b', { c: true });
expect(originalMethods.f1).toHaveBeenCalled();
});
it('uses blank logname if it is not provided', () => {
const result = underTest(target, { log: logger });
result.f1('a', 'b', { c: true });
expect(logger).toHaveBeenCalledWith('f1', ['a', 'b', { c: true }]);
});
});
it('wraps API objects', done => {
const sts = underTest(new aws.STS(), { log: logger, logName: 'sts' });
sts.getCallerIdentity().promise()
.then(callerIdentity => {
expect(callerIdentity.Account).not.toBeUndefined();
expect(logger).toHaveBeenCalledWith('sts.getCallerIdentity', []);
})
.then(done, done.fail);
});
});