Skip to content

Instantly share code, notes, and snippets.

@martinsson
Last active April 15, 2018 22:26
Show Gist options
  • Save martinsson/d5d5d0839a6d6c9eeca704e56ccbdac8 to your computer and use it in GitHub Desktop.
Save martinsson/d5d5d0839a6d6c9eeca704e56ccbdac8 to your computer and use it in GitHub Desktop.
Hidden testable code 4
// This function needs only one test
function hardToTest() {
let data = requestExternalServer()
let lang = persistence.get(data.id))
let langToUpdate = makeLangToUpdate(lang)
return persistence.update(data.id, langToUpdate)
}
// This functionc can be thouroughly tested
function makeLangToUpdate(versionLangs, lang) {
let langToUpdate = {};
versionsLangs.map((versionLang) => {
let restPath = versionLang.entity.toRestPath();
lang.dates.langsDates.map(datePayload => {
if (restPath === datePayload.langRestPath) {
langToUpdate[restPath] = langToUpdate[restPath] || {};
langToUpdate[restPath].dates = datePayload.payload.dates;
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment