Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

adds functionality to check for linked ilms and offerings. #3112

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions addon/models/learner-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,34 @@ export default class LearnerGroup extends Model {
}
return uniqueValues(modifiedGroups);
}

get hasOfferings() {
return !!this._offerings?.length;
}

@use descendantsOfferings = new ResolveFlatMapBy(() => [this.allDescendants, 'offerings']);

get hasOfferingsInGroupOrSubgroups() {
if (this.hasOfferings) {
return true;
}
return !!this.descendantsOfferings?.length;
}

get hasIlmSessions() {
return !!this._ilmSessions?.length;
}

@use descendantsIlmSessions = new ResolveFlatMapBy(() => [this.allDescendants, 'ilmSessions']);

get hasIlmSessionsInGroupOrSubgroups() {
if (this.hasIlmSessions) {
return true;
}
return !!this.descendantsIlmSessions?.length;
}

get hasOfferingsOrIlmSessionsInGroupOrSubgroups() {
return this.hasOfferingsInGroupOrSubgroups || this.hasIlmSessionsInGroupOrSubgroups;
}
}
146 changes: 146 additions & 0 deletions tests/unit/models/learner-group-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,4 +820,150 @@ module('Unit | Model | LearnerGroup', function (hooks) {
const hasNeeds = await waitForResource(learnerGroup, 'hasSubgroupsInNeedOfAccommodation');
assert.ok(hasNeeds);
});

test('has offerings', async function (assert) {
const store = this.owner.lookup('service:store');
const learnerGroup = store.createRecord('learner-group');
await waitForResource(learnerGroup, '_offerings');
assert.notOk(learnerGroup.hasOfferings);
const offering = store.createRecord('offering');
learnerGroup.set('offerings', [offering]);
await waitForResource(learnerGroup, '_offerings');
assert.ok(learnerGroup.hasOfferings);
learnerGroup.set('offerings', []);
await waitForResource(learnerGroup, '_offerings');
assert.notOk(learnerGroup.hasOfferings);
});

test('has Ilm sessions', async function (assert) {
const store = this.owner.lookup('service:store');
const learnerGroup = store.createRecord('learner-group');
await waitForResource(learnerGroup, '_ilmSessions');
assert.notOk(learnerGroup.hasIlmSessions);
const ilmSession = store.createRecord('ilm-session');
learnerGroup.set('ilmSessions', [ilmSession]);
await waitForResource(learnerGroup, '_ilmSessions');
assert.ok(learnerGroup.hasIlmSessions);
learnerGroup.set('ilmSessions', []);
await waitForResource(learnerGroup, '_ilmSessions');
assert.notOk(learnerGroup.hasIlmSessions);
});

test('has offerings in group or subgroups', async function (assert) {
const store = this.owner.lookup('service:store');
const learnerGroup = store.createRecord('learner-group');
const subgroup = store.createRecord('learner-group', { parent: learnerGroup });
const offering = store.createRecord('offering');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
assert.notOk(learnerGroup.hasOfferingsInGroupOrSubgroups);
learnerGroup.set('offerings', [offering]);
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
assert.ok(learnerGroup.hasOfferingsInGroupOrSubgroups);
learnerGroup.set('offerings', []);
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
assert.notOk(learnerGroup.hasOfferingsInGroupOrSubgroups);
subgroup.set('offerings', [offering]);
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
assert.ok(learnerGroup.hasOfferingsInGroupOrSubgroups);
subgroup.set('offerings', []);
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
assert.notOk(learnerGroup.hasOfferingsInGroupOrSubgroups);
});

test('has ilm sessions in group or subgroups', async function (assert) {
const store = this.owner.lookup('service:store');
const learnerGroup = store.createRecord('learner-group');
const subgroup = store.createRecord('learner-group', { parent: learnerGroup });
const ilmSession = store.createRecord('ilm-session');
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasIlmSessionsInGroupOrSubgroups);
learnerGroup.set('ilmSessions', [ilmSession]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasIlmSessionsInGroupOrSubgroups);
learnerGroup.set('ilmSessions', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasIlmSessionsInGroupOrSubgroups);
subgroup.set('ilmSessions', [ilmSession]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasIlmSessionsInGroupOrSubgroups);
subgroup.set('ilmSessions', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasIlmSessionsInGroupOrSubgroups);
});

test('has offerings or ilm sessions in group or subgroups', async function (assert) {
const store = this.owner.lookup('service:store');
const learnerGroup = store.createRecord('learner-group');
const subgroup = store.createRecord('learner-group', { parent: learnerGroup });
const ilmSession = store.createRecord('ilm-session');
const offering = store.createRecord('offering');
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
learnerGroup.set('offerings', [offering]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
learnerGroup.set('offerings', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
subgroup.set('offerings', [offering]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
subgroup.set('offerings', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
learnerGroup.set('ilmSessions', [ilmSession]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
learnerGroup.set('ilmSessions', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
subgroup.set('ilmSessions', [ilmSession]);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.ok(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
subgroup.set('ilmSessions', []);
await waitForResource(learnerGroup, '_ilmSessions');
await waitForResource(learnerGroup, '_offerings');
await waitForResource(learnerGroup, 'descendantsOfferings');
await waitForResource(learnerGroup, 'descendantsIlmSessions');
assert.notOk(learnerGroup.hasOfferingsOrIlmSessionsInGroupOrSubgroups);
});
});