Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from programble/fix-initial
Browse files Browse the repository at this point in the history
Fix apply command with empty journal & test
  • Loading branch information
causal-agent committed Sep 21, 2015
2 parents 34c82cb + db069f6 commit 4d870b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/command/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function apply(config: Config) {

let previousEntry = journal.then(es => R.last(es));
let newEntries = Promise.join(previousEntry, apply, (prev, es) =>
R.filter(e => e.timestamp > prev.timestamp, es)
prev ? R.filter(e => e.timestamp > prev.timestamp, es) : apply
);

return newEntries
Expand Down
27 changes: 27 additions & 0 deletions test/command/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,31 @@ describe('Command apply', () => {
assert.equal(formatSpy.callCount, 1)
);
});

describe('with empty journal', () => {
before(resetSpies);

before(() => {
readJournalStub.restore();
readJournalStub = sinon.stub(runner, 'readJournal', () =>
Promise.resolve([])
);

applyAllStub.restore();
applyAllStub = sinon.stub(
runner,
'applyAll',
(n: string, c: Config, j: string, ms: files.Migration[]) =>
Promise.resolve(R.map(migrationToEntry, ms))
);
});

it('succeeds', () =>
apply(loadObject({commands: {apply: {pending: true}}}))
);

it('calls formatJournalEntry for new entries', () =>
assert.equal(formatSpy.callCount, 3)
);
});
});

0 comments on commit 4d870b8

Please sign in to comment.