[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:
80
services/reddit/user-karma.tester.js
Normal file
80
services/reddit/user-karma.tester.js
Normal 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',
|
||||
})
|
||||
Reference in New Issue
Block a user