parent
9d03679063
commit
84f75aecd0
@ -0,0 +1,9 @@
|
||||
const Scope = require('flitter-orm/src/model/Scope')
|
||||
|
||||
class ActiveScope extends Scope {
|
||||
async filter(to_filter) {
|
||||
return to_filter.equal('is_active', true)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ActiveScope
|
@ -0,0 +1,38 @@
|
||||
|
||||
// boot the framework for use in testing
|
||||
const framework$ = (function() {
|
||||
class FrameworkLoader {
|
||||
listeners = []
|
||||
booted = false
|
||||
|
||||
subscribe(handler) {
|
||||
if ( !this.booted ) this.listeners.push(handler)
|
||||
else handler()
|
||||
}
|
||||
|
||||
boot() {
|
||||
const units = require('../../Units.flitter')
|
||||
delete units.App
|
||||
const { FlitterApp, RunLevelErrorHandler } = require('libflitter')
|
||||
this.flitter = new FlitterApp(units)
|
||||
this.rleh = new RunLevelErrorHandler()
|
||||
|
||||
this.flitter.up().then(() => {
|
||||
this.booted = true
|
||||
for ( const listener of this.listeners ) {
|
||||
try {
|
||||
listener()
|
||||
} catch (e) {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
stop() {
|
||||
return this.flitter.down()
|
||||
}
|
||||
}
|
||||
|
||||
return new FrameworkLoader()
|
||||
})()
|
||||
|
||||
module.exports = exports = framework$
|
@ -0,0 +1,43 @@
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const Player = require('../../app/models/Player.model')
|
||||
const { Model } = require('flitter-orm')
|
||||
|
||||
describe('the player model', function() {
|
||||
it('should extend Model', function() {
|
||||
expect(new Player).to.be.an.instanceOf(Model)
|
||||
})
|
||||
|
||||
it('should format players for the API', async function() {
|
||||
const player = new Player({
|
||||
patch_data: {
|
||||
patch_team_id: 4,
|
||||
patch_team_name: 'Test team',
|
||||
patch_team_key: 'TTM',
|
||||
},
|
||||
player_number: 34,
|
||||
first_name: 'Test',
|
||||
last_name: 'Player',
|
||||
full_name: 'A Test Player',
|
||||
position: 'QB',
|
||||
fantasy_position: 'QB',
|
||||
height: '6\'4"',
|
||||
weight: 250,
|
||||
birthday: '2020-11-11',
|
||||
experience: 0,
|
||||
experience_string: 'rookie',
|
||||
age: 21,
|
||||
photo_url: 'http://image.com/img.png',
|
||||
})
|
||||
|
||||
expect(await player.to_api()).to.be.eql({
|
||||
id: undefined,
|
||||
number: 34,
|
||||
name: 'A Test Player',
|
||||
position: 'QB',
|
||||
team_name: 'Test team',
|
||||
image: 'http://image.com/img.png',
|
||||
stats: {},
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in new issue