Skip to content

Commit

Permalink
Adding test cases to cover issue maximodleon#77
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Oct 17, 2018
1 parent fbd0bf6 commit dbebd5d
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
extends: 'standard',
plugins: ['prettier'],
plugins: ['prettier', 'mocha'],
rules: {
'prettier/prettier': 'error'
'prettier/prettier': 'error',
'mocha/no-exclusive-tests': 'error'
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
*.swp
*.pdf
test.js
.nyc_output
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Telegram bot to get information for different things (gas prices, movies, etc..)",
"main": "app.js",
"scripts": {
"test": "echo \"Error: need to add some tests!\" && exit 0",
"test": "mocha --recursive",
"report": "nyc mocha --recursive",
"start": "node app.js",
"watch": "nodemon app.js",
"lint": "standard",
Expand All @@ -29,9 +30,12 @@
"axios": "0.18.0",
"cron": "1.4.1",
"dotenv": "6.0.0",
"eslint-plugin-mocha": "^5.2.0",
"memoizee": "0.4.13",
"mocha": "^5.2.0",
"mustache": "2.3.0",
"npm": "6.3.0",
"nyc": "^13.1.0",
"pdf2table": "0.0.2",
"puppeteer": "1.6.0",
"telegraf": "3.21.2",
Expand Down
150 changes: 150 additions & 0 deletions test/helpers/testDatesHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/* eslint-env mocha */
const assert = require('assert')
const datesHelper = require('../../helpers/dates-helper')

const days = {
0: {
english: 'Sunday',
spanish: 'Domingo'
},
1: {
english: 'Monday',
spanish: 'Lunes'
},
2: {
english: 'Tuesday',
spanish: 'Martes'
},
3: {
english: 'Wednesday',
spanish: 'Miércoles'
},
4: {
english: 'Thursday',
spanish: 'Jueves'
},
5: {
english: 'Friday',
spanish: 'Viernes'
},
6: {
english: 'Saturday',
spanish: 'Sábado'
}
}

const months = {
0: {
english: 'January',
spanish: 'Enero'
},
1: {
english: 'February',
spanish: 'Febreo'
},
2: {
english: 'March',
spanish: 'Marzo'
},
3: {
english: 'April',
spanish: 'Abril'
},
4: {
english: 'May',
spanish: 'Mayo'
},
5: {
english: 'June',
spanish: 'Junio'
},
6: {
english: 'July',
spanish: 'Julio'
},
7: {
english: 'August',
spanish: 'Agosto'
},
8: {
english: 'September',
spanish: 'Septimebre'
},
9: {
english: 'October',
spanish: 'Octubre'
},
10: {
english: 'November',
spanish: 'Noviembre'
},
11: {
english: 'December',
spanish: 'Diciembre'
}
}

const hours = {
0: '12',
1: '01',
2: '02',
3: '03',
4: '04',
5: '05',
6: '06',
7: '07',
8: '08',
9: '09',
10: '10',
11: '11',
12: '12',
13: '01',
14: '02',
15: '03',
16: '04',
17: '05',
18: '06',
19: '07',
20: '08',
21: '09',
22: '10',
23: '11'
}

describe('Brower helper', () => {
it('should be able to match days of week correctly', () => {
for (let day in days) {
assert.strictEqual(
datesHelper.getDayString(
new Date(`${days[day].english} Oct ${14 + Number(day)} 2018`).getDay()
),
days[day].spanish
)
}
})

it('should be able to match months correctly', () => {
for (let month in months) {
assert.strictEqual(
datesHelper.getMonthString(
new Date(`${months[month].english} 14 2018`).getMonth()
),
months[month].spanish
)
}
})

it('should be able to convert from 24 hour format correctly', () => {
for (let hour in hours) {
assert.strictEqual(datesHelper.getHour(Number(hour)), hours[hour])
}
})

it('should be able to convert minutes correctly', () => {
assert.strictEqual(datesHelper.getMinutes(0), '00')
assert.strictEqual(datesHelper.getMinutes(1), '01')
assert.strictEqual(datesHelper.getMinutes(10), '10')
assert.strictEqual(datesHelper.getMinutes(20), '20')
assert.strictEqual(datesHelper.getMinutes(59), '59')
})
})

0 comments on commit dbebd5d

Please sign in to comment.