2020-05-01 21:30:02 +00:00
import { run } from '@ember/runloop' ;
import { module , test } from 'qunit' ;
import { setupTest } from 'ember-qunit' ;
2021-12-28 14:45:20 +00:00
module ( 'Unit | Model | allocation' , function ( hooks ) {
2020-05-01 21:30:02 +00:00
setupTest ( hooks ) ;
2021-12-28 14:45:20 +00:00
hooks . beforeEach ( function ( ) {
2020-05-01 21:30:02 +00:00
this . store = this . owner . lookup ( 'service:store' ) ;
} ) ;
2021-12-28 14:45:20 +00:00
test ( "When the allocation's job version matches the job's version, the task group comes from the job." , function ( assert ) {
2020-05-01 21:30:02 +00:00
const job = run ( ( ) =>
this . store . createRecord ( 'job' , {
name : 'this-job' ,
version : 1 ,
taskGroups : [
{
name : 'from-job' ,
count : 1 ,
task : [ ] ,
} ,
] ,
} )
) ;
const allocation = run ( ( ) =>
this . store . createRecord ( 'allocation' , {
job ,
jobVersion : 1 ,
taskGroupName : 'from-job' ,
allocationTaskGroup : {
name : 'from-allocation' ,
count : 1 ,
task : [ ] ,
} ,
} )
) ;
assert . equal ( allocation . get ( 'taskGroup.name' ) , 'from-job' ) ;
} ) ;
2021-12-28 14:45:20 +00:00
test ( "When the allocation's job version does not match the job's version, the task group comes from the alloc." , function ( assert ) {
2020-05-01 21:30:02 +00:00
const job = run ( ( ) =>
this . store . createRecord ( 'job' , {
name : 'this-job' ,
version : 1 ,
taskGroups : [
{
name : 'from-job' ,
count : 1 ,
task : [ ] ,
} ,
] ,
} )
) ;
const allocation = run ( ( ) =>
this . store . createRecord ( 'allocation' , {
job ,
jobVersion : 2 ,
taskGroupName : 'from-job' ,
allocationTaskGroup : {
name : 'from-allocation' ,
count : 1 ,
task : [ ] ,
} ,
} )
) ;
assert . equal ( allocation . get ( 'taskGroup.name' ) , 'from-allocation' ) ;
} ) ;
2021-12-28 14:45:20 +00:00
test ( "When the allocation's job version does not match the job's version and the allocation has no task group, then task group is null" , async function ( assert ) {
2020-05-01 21:30:02 +00:00
const job = run ( ( ) =>
this . store . createRecord ( 'job' , {
name : 'this-job' ,
version : 1 ,
taskGroups : [
{
name : 'from-job' ,
count : 1 ,
task : [ ] ,
} ,
] ,
} )
) ;
const allocation = run ( ( ) =>
this . store . createRecord ( 'allocation' , {
job ,
jobVersion : 2 ,
taskGroupName : 'from-job' ,
} )
) ;
assert . equal ( allocation . get ( 'taskGroup.name' ) , null ) ;
} ) ;
} ) ;