Write more model tests
This commit is contained in:
parent
bcde7699bb
commit
97b26a3007
@ -119,11 +119,15 @@ class Team extends Model {
|
|||||||
* updates the API's data
|
* updates the API's data
|
||||||
*/
|
*/
|
||||||
async to_api() {
|
async to_api() {
|
||||||
const User = this.models.get('auth:User')
|
let user
|
||||||
|
try {
|
||||||
|
const User = this.models.get('auth:User')
|
||||||
|
user = await User.findById(this.user_id)
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user_id: this.user_id,
|
user_id: this.user_id,
|
||||||
user_display: (await User.findById(this.user_id))?.uid || 'Unknown User',
|
user_display: user?.uid || 'Unknown User',
|
||||||
team_name: this.team_name,
|
team_name: this.team_name,
|
||||||
team_num: this.team_num,
|
team_num: this.team_num,
|
||||||
}
|
}
|
||||||
|
26
test/backend/models_Team.spec.js
Normal file
26
test/backend/models_Team.spec.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const { expect } = require('chai')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
const Team = require('../../app/models/Team.model')
|
||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
describe('the team model', function() {
|
||||||
|
it('should extend Model', function() {
|
||||||
|
expect(new Team).to.be.an.instanceOf(Model)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should format teams for the API', async function() {
|
||||||
|
const team = new Team({
|
||||||
|
user_id: '45c',
|
||||||
|
team_name: 'A test team name',
|
||||||
|
team_num: 44,
|
||||||
|
player_ids: ['abc', '123'],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await team.to_api()).to.be.eql({
|
||||||
|
user_id: '45c',
|
||||||
|
user_display: 'Unknown User',
|
||||||
|
team_name: 'A test team name',
|
||||||
|
team_num: 44,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
35
test/backend/models_WeeklyPlayerStat.spec.js
Normal file
35
test/backend/models_WeeklyPlayerStat.spec.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
const { expect } = require('chai')
|
||||||
|
const sinon = require('sinon')
|
||||||
|
const WeeklyPlayerStat = require('../../app/models/WeeklyPlayerStat.model')
|
||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
describe('the weekly player stat model', function() {
|
||||||
|
it('should extend Model', function() {
|
||||||
|
expect(new WeeklyPlayerStat).to.be.an.instanceOf(Model)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should format stats for the API', async function() {
|
||||||
|
const stat = new WeeklyPlayerStat({
|
||||||
|
player_id: 1,
|
||||||
|
week_num: 1,
|
||||||
|
patch_player_id: 1,
|
||||||
|
fantasy_points: 3,
|
||||||
|
|
||||||
|
passing_attempts: 4,
|
||||||
|
passing_completions: 2,
|
||||||
|
passing_yards: 50,
|
||||||
|
fumbles: 2,
|
||||||
|
kick_returns: 1,
|
||||||
|
sacks: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await stat.to_api()).to.be.eql({
|
||||||
|
'Passing Attempts': 4,
|
||||||
|
'Passing Completions': 2,
|
||||||
|
'Passing Yards': 50,
|
||||||
|
'Fumbles': 2,
|
||||||
|
'Kick Returns': 1,
|
||||||
|
'Sacks': 0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user