Finish additional tests for the backend
This commit is contained in:
parent
30edb2563e
commit
bf5d8b18b5
@ -130,8 +130,11 @@ class Player extends Model {
|
|||||||
* @returns Promise<object>
|
* @returns Promise<object>
|
||||||
*/
|
*/
|
||||||
async to_api(with_stats = false) {
|
async to_api(with_stats = false) {
|
||||||
const current_week = await this.sports_data.current_play_week()
|
let stat
|
||||||
const stat = with_stats ? await this.points_for_week(current_week) : undefined
|
try {
|
||||||
|
const current_week = await this.sports_data.current_play_week()
|
||||||
|
stat = with_stats ? await this.points_for_week(current_week) : undefined
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@ -40,13 +40,6 @@ const index = {
|
|||||||
* or middleware that are applied in order.
|
* or middleware that are applied in order.
|
||||||
*/
|
*/
|
||||||
get: {
|
get: {
|
||||||
// handlers should be a list of either controller:: or middleware:: references
|
|
||||||
// e.g. middleware::HomeLogger
|
|
||||||
// e.g. controller::Home.welcome
|
|
||||||
'/': [
|
|
||||||
'controller::Home.welcome'
|
|
||||||
],
|
|
||||||
|
|
||||||
// Get information about the user's team
|
// Get information about the user's team
|
||||||
'/my-team': ['controller::Teams.get_my_team'],
|
'/my-team': ['controller::Teams.get_my_team'],
|
||||||
|
|
||||||
|
26
test/backend/routing_routers_api.spec.js
Normal file
26
test/backend/routing_routers_api.spec.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const { expect } = require('chai')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
|
||||||
|
describe('the API routes', function() {
|
||||||
|
it('should define the correct public API', function() {
|
||||||
|
const config = require('../../app/routing/routers/api.routes')
|
||||||
|
expect(config).to.be.eql({
|
||||||
|
prefix: '/api/v1',
|
||||||
|
middleware: [ 'auth:UserOnly', 'InjectUserTeam' ],
|
||||||
|
get: {
|
||||||
|
'/my-team': ['controller::Teams.get_my_team'],
|
||||||
|
'/my-team/players': ['controller::Teams.get_my_team_players'],
|
||||||
|
'/my-team/lineup': ['controller::Teams.get_my_team_current_lineup'],
|
||||||
|
'/draft-board/available': ['controller::DraftBoard.get_available_players'],
|
||||||
|
'/matchups': ['controller::Scores.get_weekly_scores'],
|
||||||
|
'/league-standings': ['controller::Scores.get_league_standings'],
|
||||||
|
'/status': ['controller::Home.get_status'],
|
||||||
|
},
|
||||||
|
post: {
|
||||||
|
'/my-team': ['controller::Teams.save_my_team'],
|
||||||
|
'/my-team/lineup': ['controller::Teams.save_my_team_lineup'],
|
||||||
|
'/draft-board/draft-player': ['controller::DraftBoard.draft_player_to_team'],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
66
test/backend/services_sports_data.spec.js
Normal file
66
test/backend/services_sports_data.spec.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
const { expect } = require('chai')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
const SportsData = require('../../app/services/sports_data.service')
|
||||||
|
|
||||||
|
const get_inst = () => {
|
||||||
|
const inst = new SportsData()
|
||||||
|
const configs = {
|
||||||
|
get(key) {
|
||||||
|
return ({
|
||||||
|
'server.sports_data.season': '2020REG',
|
||||||
|
'server.sports_data.api_key': 'fakekey',
|
||||||
|
})[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inst.configs = configs
|
||||||
|
return inst
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('the sports data service', function() {
|
||||||
|
it('should be a functional class instance', function() {
|
||||||
|
expect(get_inst()).to.be.an.instanceOf(SportsData)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should properly format API URLs', function() {
|
||||||
|
const inst = get_inst()
|
||||||
|
|
||||||
|
let url = ''
|
||||||
|
|
||||||
|
url = 'https://api.sportsdata.io/v3/nfl/scores/json/some-path/1?key=fakekey'
|
||||||
|
expect(inst.url('some-path/1')).to.be.equal(url)
|
||||||
|
|
||||||
|
url = 'https://api.sportsdata.io/v3/nfl/scores/json/some-path/other-path?key=fakekey'
|
||||||
|
expect(inst.url('some-path/other-path')).to.be.equal(url)
|
||||||
|
|
||||||
|
url = 'https://api.sportsdata.io/v3/nfl/fubar/json/some-path/another?key=fakekey'
|
||||||
|
expect(inst.url('some-path/another', 'fubar')).to.be.equal(url)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should call the correct sportsdata.io endpoints', async function() {
|
||||||
|
const inst = get_inst()
|
||||||
|
|
||||||
|
const test_endpoint = async (method, endpoint, base, args = []) => {
|
||||||
|
inst.get_request = sinon.spy()
|
||||||
|
|
||||||
|
await inst[method](...args)
|
||||||
|
|
||||||
|
expect(inst.get_request.calledOnce).to.be.true
|
||||||
|
expect(inst.get_request.getCall(0).args[0]).to.be.equal(endpoint)
|
||||||
|
expect(inst.get_request.getCall(0).args[1]).to.be.equal(base)
|
||||||
|
}
|
||||||
|
|
||||||
|
await test_endpoint('get_week_player_stats', 'PlayerGameProjectionStatsByWeek/2020REG/1', 'projections', [1])
|
||||||
|
await test_endpoint('get_active_teams', 'Teams')
|
||||||
|
await test_endpoint('get_team_players', 'Players/MYTEAM', undefined, ['MYTEAM'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should have methods for is_draft_stage and current_play_week', function() {
|
||||||
|
const inst = get_inst()
|
||||||
|
|
||||||
|
expect(inst.is_draft_stage).to.be.a('function')
|
||||||
|
expect(inst.is_draft_stage.length).to.be.equal(0)
|
||||||
|
expect(inst.current_play_week).to.be.a('function')
|
||||||
|
expect(inst.current_play_week.length).to.be.equal(0)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user