diff --git a/tests/tests/wichtelbot.message.module.assignment.ts b/tests/tests/wichtelbot.message.module.assignment.ts index 9dc2e75b3baedb2c8c359fb0993c914e3ceb9fa0..4d1fad82aa90c9f2bd47c8ae753514952edbbd87 100644 --- a/tests/tests/wichtelbot.message.module.assignment.ts +++ b/tests/tests/wichtelbot.message.module.assignment.ts @@ -6,6 +6,8 @@ import Database from '../../scripts/wichtelbot/database'; import GiftType from '../../scripts/wichtelbot/types/giftType'; import Member from '../../scripts/wichtelbot/classes/member'; import { RelationshipTestUtility } from '../utility/relationship'; +import { ExclusionData } from '../../scripts/wichtelbot/classes/exclusion'; +import { ExclusionReason } from '../../scripts/wichtelbot/types/exclusionReason'; describe('assignment module', function () @@ -157,6 +159,58 @@ describe('assignment module', } ); + it('can assign members with exclusions', + function () + { + const newMembers: Member[] = []; + + for (let i = 0; i < 4; i++) + { + const newMember = ContactTestUtility.createRandomMemberWithMostCompatibleInformation(); + + newMembers.push(newMember); + database.saveContact(newMember); + database.saveMember(newMember); + } + + const exclusions: ExclusionData[] = [ + { + giverId: newMembers[0].id, + takerId: newMembers[1].id, + reason: ExclusionReason.Wish, + }, + { + giverId: newMembers[0].id, + takerId: newMembers[2].id, + reason: ExclusionReason.Wish, + }, + { + giverId: newMembers[1].id, + takerId: newMembers[2].id, + reason: ExclusionReason.Wish, + }, + { + giverId: newMembers[1].id, + takerId: newMembers[3].id, + reason: ExclusionReason.Wish, + }, + ]; + + database.saveUserExclusions(exclusions); + + const successful = assignmentModule.assign(); + + assert.isTrue(successful); + + const relationships = database.getRelationships(); + + assert.equal(relationships.length, 4); + + RelationshipTestUtility.assertValidity(relationships, newMembers); + RelationshipTestUtility.assertCompatibility(relationships, newMembers, exclusions); + } + ); + it('cannot assign with zero members', function () { diff --git a/tests/utility/relationship.ts b/tests/utility/relationship.ts index 35ba48755736600c8db8f29bd8dc419e52352375..68e6a34d0e9a5fe668dedf75ead643ef7a564fb5 100644 --- a/tests/utility/relationship.ts +++ b/tests/utility/relationship.ts @@ -1,4 +1,6 @@ import { assert } from "chai"; +import { ExclusionData } from "../../scripts/wichtelbot/classes/exclusion"; +import { ExclusionReason } from "../../scripts/wichtelbot/types/exclusionReason"; import GiftType from "../../scripts/wichtelbot/types/giftType"; import Member from "../../scripts/wichtelbot/classes/member"; import { Relationship } from "../../scripts/wichtelbot/classes/relationship"; @@ -39,7 +41,7 @@ export abstract class RelationshipTestUtility /** * Proofs the compatibility of every relationship. */ - public static assertCompatibility (relationships: Relationship[], members: Member[]): void + public static assertCompatibility (relationships: Relationship[], members: Member[], exclusions: ExclusionData[] = []): void { for (const relationship of relationships) { @@ -81,6 +83,16 @@ export abstract class RelationshipTestUtility const isInternationalCompatible = countriesAreTheSame || noneHasAnalogueGiftType || giver.information.internationalAllowed; assert.isTrue(isInternationalCompatible, 'International compatibility check failed'); + + for (const exclusion of exclusions) + { + if (exclusion.reason == ExclusionReason.Wish) + { + const isNoExclusion = exclusion.giverId !== giver.id || exclusion.takerId !== taker.id; + + assert.isTrue(isNoExclusion, 'Exclusion compatibility check failed'); + } + } } } }