Skip to content

Commit 2fc73fd

Browse files
committed
chapter 07: initial code to create a test api for the application, the name of the first strategy is abstract test infrastructure class pattern
1 parent dcc445b commit 2fc73fd

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const loggingFacility = require('./loggingFacility');
2+
3+
function configurationManager() {
4+
/**
5+
* @param {string} configName
6+
*/
7+
function isConfigured(configName) {
8+
loggingFacility.log(`checking ${configName}`);
9+
}
10+
11+
return {
12+
isConfigured,
13+
};
14+
}
15+
16+
module.exports = configurationManager;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const configurationManagerFactory = require('./configurationManager');
2+
const loggingFacility = require('./loggingFacility');
3+
4+
describe('isConfigured', () => {
5+
it('logging file check', () => {
6+
const configurationManager = configurationManagerFactory();
7+
configurationManager.isConfigured('');
8+
});
9+
10+
afterEach(() => {
11+
loggingFacility.setLogger(null);
12+
});
13+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const loggingFacility = require('./loggingFacility');
2+
3+
function logAnalyzer() {
4+
/**
5+
* @param {string} fileName
6+
*/
7+
function analyze(fileName) {
8+
if (fileName.length < 8) {
9+
loggingFacility.log(`Filename too short: ${fileName}`);
10+
}
11+
}
12+
13+
return {
14+
analyze,
15+
};
16+
}
17+
18+
module.exports = logAnalyzer;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const logAnalyzerFactory = require('./logAnalyzer');
2+
const loggingFacility = require('./loggingFacility');
3+
4+
describe('analyze', () => {
5+
it('empty file throws exception', () => {
6+
const logAnalyzer = logAnalyzerFactory();
7+
logAnalyzer.analyze('');
8+
});
9+
10+
afterEach(() => {
11+
loggingFacility.setLogger(null);
12+
});
13+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let logger = console.log;
2+
3+
function log(text) {
4+
logger(text);
5+
}
6+
7+
function getLogger() {
8+
return logger;
9+
}
10+
11+
function setLogger(value) {
12+
logger = value;
13+
}
14+
15+
module.exports = {
16+
log,
17+
getLogger,
18+
setLogger,
19+
};

0 commit comments

Comments
 (0)