Skip to content

Commit

Permalink
fix(core): fix streak count logic to count from 1
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmulligan committed Dec 26, 2017
1 parent 44ebf50 commit c303c81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 6 additions & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { ask, save, getCurrentStreak, ensureDB } = require('../index')
const moment = require('moment')
const path = require('path')
const fs = require('fs-jetpack')
const DB_PATH = path.resolve('./__mocks__/db.json')
const ANSWERS = ['soda pop', '$$$', 'toffee', 'mustaches']

Expand All @@ -24,6 +25,10 @@ beforeEach(done => {
ensureDB(DB_PATH).then(done)
})

afterEach(done => {
fs.removeAsync(DB_PATH).then(done)
})

test('should accept n number prompts', done => {
let TIMES = 3
let count = 0
Expand Down Expand Up @@ -66,5 +71,5 @@ test('should save output to db', done => {
test('should keep track of n days of latest streak', () => {
const db = require('../__mocks__/dummy_db.json')
const streak = getCurrentStreak(db, '20171228')
expect(streak).toEqual(5)
expect(streak).toEqual(4)
})
Empty file modified bin/index.js
100644 → 100755
Empty file.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ const getCurrentStreak = (db = {}, now) => {
const latest = now || getLatestDate(keys)
let streak = 1
let prev = getPrevious(db, latest)
if (prev) {
streak++
}

while (prev) {
streak++
prev = getPrevious(db, prev)
Expand Down

0 comments on commit c303c81

Please sign in to comment.