Skip to content

Commit

Permalink
chapter 05: copy logAnalyzer.js, errors and fakes from the folder of …
Browse files Browse the repository at this point in the history
…chapter 04 in order to continue with the book
  • Loading branch information
devcorpio committed Jan 12, 2019
1 parent c1db82d commit adc1345
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chapter_05-isolation-frameworks/errors/ArgumentError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ArgumentError extends Error {}

module.exports = ArgumentError;
21 changes: 21 additions & 0 deletions chapter_05-isolation-frameworks/fakes/fakeWebService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function fakeWebService() {
let lastError;

/**
* @param {string} message
*/
function logError(message) {
lastError = message;
}

function getLastError() {
return lastError;
}

return {
logError,
getLastError,
};
}

module.exports = fakeWebService;
53 changes: 53 additions & 0 deletions chapter_05-isolation-frameworks/logAnalyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const ArgumentError = require('./errors/ArgumentError');

function logAnalyzer(extensionManager, webService) {
/**
* @type {boolean}
*/
let wasLastFileNameValid;

/**
* @return {boolean}
*/
function getWasLastFileNameValid() {
return wasLastFileNameValid;
}

/**
* @param {string} fileName
* @return {Promise}
*/
async function isValidLogFileName(fileName) {
wasLastFileNameValid = false;

if (fileName === '') {
throw new ArgumentError('filename has to be provided');
}

const result = await extensionManager.isValid(fileName);

if (!result) {
return false;
}

wasLastFileNameValid = true;
return true;
}

/**
* @param {string} fileName
*/
function analyze(fileName) {
if (fileName.length < 8) {
webService.logError(`Filename too short: ${fileName}`);
}
}

return {
getWasLastFileNameValid,
isValidLogFileName,
analyze,
};
}

module.exports = logAnalyzer;

0 comments on commit adc1345

Please sign in to comment.