Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Add test for overridding existing markdown file
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsJonQ committed Jul 12, 2017
1 parent 4254ac3 commit 9b9df5f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/generate.js
Expand Up @@ -9,14 +9,14 @@ const defaultDir = './posts';
export const savePost = (dir = defaultDir) => postData => {
if (!postData) return false;

const { content, fileName } = postData;
const filePath = `${dir}/${fileName}`;
const { markdown, props } = postData;
const filePath = `${dir}/${props.fileName}`;

return new Promise((resolve, reject) => {
mkdir(dir, err => {
if (err && reject) return reject(err);
fs.writeFileSync(filePath, content);
resolve(filePath);
fs.writeFileSync(filePath, markdown);
resolve(props);
});
});
};
Expand All @@ -28,10 +28,10 @@ export const generate = (dir = defaultDir) => (posts = []) => {
const props = mapDataToProps(post);
if (!isValidPost(props)) return;

const content = generatePost(props);
const markdown = generatePost(props);
const postData = {
fileName: props.fileName,
content,
props,
markdown,
};

saveQueue.push(savePost(dir)(postData));
Expand Down
33 changes: 33 additions & 0 deletions src/tests/generate.spec.js
Expand Up @@ -26,4 +26,37 @@ describe('generate', () => {
done(err);
});
});

it('should overwrite existing .md post', done => {
generate(dir)(posts)
.then(() => {
// Regenerate, but with new post
const newTitle = 'NEWTITLE. OMG!!!';
const newPost = Object.assign({}, data, {
html_title: newTitle,
});

generate(dir)([newPost])
.then(postData => {
const postProps = mapDataToProps(newPost);
const post = readPost(dir)(postProps);

expect(post).to.exist;
expect(post).to.be.a('string');

expect(post).to.contain(postProps.front_matter.title);
expect(post).to.contain(postProps.front_matter.description);
expect(post).to.contain(postProps.content);
expect(post).to.contain(newTitle);

done();
})
.catch(err => {
done(err);
});
})
.catch(err => {
done(err);
});
});
});

0 comments on commit 9b9df5f

Please sign in to comment.