[Reddit] New badge and additional testing (#5166)

* fix: added detection of private subs and aded a test

* test: added test for no subscriber info

* feat: added user-karma badge

* refactor: changed class name for testing

Changed the class name to allow testing the whole service with 'reddit'

* refactor: refactored code for code and output style

* refactor: change how variables are passed to be cleaner

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
Joe Izzard
2020-06-09 03:15:07 +01:00
committed by GitHub
parent 88ad5aac01
commit 36e1d30631
4 changed files with 197 additions and 1 deletions

View File

@@ -0,0 +1,80 @@
'use strict'
const { isMetric } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
t.create('user-karma (valid - link)')
.get('/link/user_simulator.json')
.expectBadge({
label: 'u/user_simulator karma (link)',
message: isMetric,
})
t.create('user-karma (valid - comment')
.get('/comment/user_simulator.json')
.expectBadge({
label: 'u/user_simulator karma (comment)',
message: isMetric,
})
t.create('user-karma (valid - combined)')
.get('/combined/user_simulator.json')
.expectBadge({
label: 'u/user_simulator karma',
message: isMetric,
})
t.create('user-karma (non-existing user)')
.get('/combined/thisuserdoesnotexistandhopefullyneverwill.json')
.expectBadge({
label: 'reddit karma',
message: 'user not found',
})
t.create('user-karma (link - math check)')
.get('/link/user_simulator.json')
.intercept(nock =>
nock('https://www.reddit.com/u')
.get('/user_simulator/about.json')
.reply(200, { kind: 't2', data: { link_karma: 20, comment_karma: 80 } })
)
.expectBadge({
label: 'u/user_simulator karma (link)',
message: '20',
})
t.create('user-karma (comment - math check)')
.get('/comment/user_simulator.json')
.intercept(nock =>
nock('https://www.reddit.com/u')
.get('/user_simulator/about.json')
.reply(200, { kind: 't2', data: { link_karma: 20, comment_karma: 80 } })
)
.expectBadge({
label: 'u/user_simulator karma (comment)',
message: '80',
})
t.create('user-karma (combined - math check)')
.get('/combined/user_simulator.json')
.intercept(nock =>
nock('https://www.reddit.com/u')
.get('/user_simulator/about.json')
.reply(200, { kind: 't2', data: { link_karma: 20, comment_karma: 80 } })
)
.expectBadge({
label: 'u/user_simulator karma',
message: '100',
})
t.create('user-karma (combined - missing data)')
.get('/combined/user_simulator.json')
.intercept(nock =>
nock('https://www.reddit.com/u')
.get('/user_simulator/about.json')
.reply(200, { kind: 't2', data: { link_karma: 20 } })
)
.expectBadge({
label: 'reddit karma',
message: 'invalid response data',
})