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

Fix apply command with empty journal & test #4

Merged
merged 2 commits into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
);
});
});