From 83f9b0576bd717aa990d9ede16e09d1e728f65ed Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 11 Sep 2024 10:27:13 +0200 Subject: [PATCH] feat(orga): add isScoAndManagingStudents and isGarIdentityProvider getter in organization model --- orga/app/models/organization.js | 8 +++ orga/tests/unit/models/organization-test.js | 67 +++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 orga/tests/unit/models/organization-test.js diff --git a/orga/app/models/organization.js b/orga/app/models/organization.js index 10048a6ca84..589ca61fb09 100644 --- a/orga/app/models/organization.js +++ b/orga/app/models/organization.js @@ -18,6 +18,10 @@ export default class Organization extends Model { @hasMany('group', { async: true, inverse: null }) groups; @hasMany('division', { async: true, inverse: null }) divisions; + get isGarIdentityProvider() { + return this.isScoAndManagingStudents && this.identityProviderForCampaigns === 'GAR'; + } + get isPro() { return this.type === 'PRO'; } @@ -26,6 +30,10 @@ export default class Organization extends Model { return this.type === 'SCO'; } + get isScoAndManagingStudents() { + return this.isSco && this.isManagingStudents; + } + get isSco1d() { return this.type === 'SCO-1D'; } diff --git a/orga/tests/unit/models/organization-test.js b/orga/tests/unit/models/organization-test.js new file mode 100644 index 00000000000..3ce137c5cdc --- /dev/null +++ b/orga/tests/unit/models/organization-test.js @@ -0,0 +1,67 @@ +import { setupTest } from 'ember-qunit'; +import { module, test } from 'qunit'; + +module('Unit | Model | organization', function (hooks) { + setupTest(hooks); + + module('#isScoAndManagingStudents', function () { + test("it returns true when organization has 'SCO' type and isManagingStudents at true", function (assert) { + // given + const store = this.owner.lookup('service:store'); + + // when + const organization = store.createRecord('organization', { + isManagingStudents: true, + type: 'SCO', + }); + + // then + assert.true(organization.isScoAndManagingStudents); + }); + + test("it returns false when organization does not have 'SCO' type or isManagingStudents at true", function (assert) { + // given + const store = this.owner.lookup('service:store'); + + // when + const organization = store.createRecord('organization', { + isManagingStudents: false, + type: 'PRO', + }); + + // then + assert.false(organization.isScoAndManagingStudents); + }); + }); + module('#isGarIdentityProvider', function () { + test("it returns true when organization isScoAndManagingStudents and identityProviderForCampaigns 'GAR'", function (assert) { + // given + const store = this.owner.lookup('service:store'); + + // when + const organization = store.createRecord('organization', { + isManagingStudents: true, + type: 'SCO', + identityProviderForCampaigns: 'GAR', + }); + + // then + assert.true(organization.isGarIdentityProvider); + }); + + test("it returns false when organization does not have isScoAndManagingStudents or identityProviderForCampaigns 'GAR'", function (assert) { + // given + const store = this.owner.lookup('service:store'); + + // when + const organization = store.createRecord('organization', { + isManagingStudents: true, + type: 'SCO', + identityProviderForCampaigns: 'TEST', + }); + + // then + assert.false(organization.isGarIdentityProvider); + }); + }); +});