Skip to content

Commit

Permalink
refactor(api): add TYPES constants for Eligibility model
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored and laura-bergoens committed Feb 6, 2025
1 parent ae7be42 commit 13907dd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
13 changes: 7 additions & 6 deletions api/db/seeds/data/team-prescription/build-quests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ATTESTATIONS } from '../../../../src/profile/domain/constants.js';
import { REWARD_TYPES } from '../../../../src/quest/domain/constants.js';
import { TYPES } from '../../../../src/quest/domain/models/Eligibility.js';
import { COMPARISON } from '../../../../src/quest/domain/models/Quest.js';
import { Assessment, CampaignParticipationStatuses, Membership } from '../../../../src/shared/domain/models/index.js';
import { temporaryStorage } from '../../../../src/shared/infrastructure/key-value-storages/index.js';
Expand Down Expand Up @@ -157,22 +158,22 @@ const buildSixthGradeQuests = (
) => {
const firstQuestRequirement = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
type: 'SCO',
},
comparison: COMPARISON.ALL,
},
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
isManagingStudents: true,
tags: [AEFE_TAG.name],
},
comparison: COMPARISON.ONE_OF,
},
{
type: 'campaignParticipations',
type: TYPES.CAMPAIGN_PARTICIPATIONS,
data: {
targetProfileIds: [firstTargetProfile.id],
},
Expand All @@ -198,22 +199,22 @@ const buildSixthGradeQuests = (

const secondQuestEligibilityRequirements = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
type: 'SCO',
},
comparison: COMPARISON.ALL,
},
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
isManagingStudents: true,
tags: [AEFE_TAG.name],
},
comparison: COMPARISON.ONE_OF,
},
{
type: 'campaignParticipations',
type: TYPES.CAMPAIGN_PARTICIPATIONS,
data: {
targetProfileIds: [secondTargetProfile.id, thirdTargetProfile.id],
},
Expand Down
6 changes: 6 additions & 0 deletions api/src/quest/domain/models/Eligibility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export const TYPES = {
ORGANIZATION_LEARNER: 'organizationLearner',
ORGANIZATION: 'organization',
CAMPAIGN_PARTICIPATIONS: 'campaignParticipations',
};

export class Eligibility {
#campaignParticipations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { COMPARISON } from '../../../../../src/quest/domain/models/Quest.js';
import { usecases } from '../../../../../src/quest/domain/usecases/index.js';
import { KnowledgeElement } from '../../../../../src/shared/domain/models/index.js';
import { databaseBuilder, expect, knex } from '../../../../test-helper.js';
import { TYPES } from "../../../../../src/quest/domain/models/Eligibility.js";
const { INVALIDATED, VALIDATED } = KnowledgeElement.StatusType;

const userId = 1234;
Expand Down Expand Up @@ -54,7 +55,7 @@ const setupContext = async (
const quest = databaseBuilder.factory.buildQuest({
eligibilityRequirements: [
{
type: 'organization',
type: TYPES.ORGANIZATION,
comparison: COMPARISON.ALL,
data: {
type: questOrganization,
Expand Down Expand Up @@ -152,7 +153,7 @@ describe('Quest | Integration | Domain | Usecases | RewardUser', function () {
rewardId,
eligibilityRequirements: [
{
type: 'organization',
type: TYPES.ORGANIZATION,
comparison: COMPARISON.ALL,
data: {
type: questOrganization,
Expand All @@ -173,7 +174,7 @@ describe('Quest | Integration | Domain | Usecases | RewardUser', function () {
rewardId,
eligibilityRequirements: [
{
type: 'organization',
type: TYPES.ORGANIZATION,
comparison: COMPARISON.ALL,
data: {
type: questOrganization,
Expand Down
16 changes: 8 additions & 8 deletions api/tests/quest/unit/domain/models/Quest_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Eligibility } from '../../../../../src/quest/domain/models/Eligibility.js';
import { Eligibility, TYPES } from '../../../../../src/quest/domain/models/Eligibility.js';
import { Quest } from '../../../../../src/quest/domain/models/Quest.js';
import { COMPARISON } from '../../../../../src/quest/domain/models/Quest.js';
import { Success } from '../../../../../src/quest/domain/models/Success.js';
Expand All @@ -15,7 +15,7 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {
// given
const eligibilityRequirements = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
type: 'SCO',
},
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {
before(function () {
const eligibilityRequirements = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
tags: ['AGRICULTURE', 'AEFE'],
},
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {
before(function () {
const eligibilityRequirements = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
isManagingStudents: true,
tags: ['AEFE'],
Expand Down Expand Up @@ -126,29 +126,29 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {

const eligibilityRequirements = [
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
type: 'SCO',
},
comparison: COMPARISON.ALL,
},
{
type: 'organization',
type: TYPES.ORGANIZATION,
data: {
isManagingStudents: true,
tags: ['AEFE'],
},
comparison: COMPARISON.ONE_OF,
},
{
type: 'organizationLearner',
type: TYPES.ORGANIZATION_LEARNER,
data: {
MEFCode: '10010012110',
},
comparison: COMPARISON.ALL,
},
{
type: 'campaignParticipations',
type: TYPES.CAMPAIGN_PARTICIPATIONS,
data: {
targetProfileIds: [eligibleTargetProfileId],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Eligibility } from '../../../../../src/quest/domain/models/Eligibility.js';
import { Eligibility, TYPES } from '../../../../../src/quest/domain/models/Eligibility.js';
import { Quest } from '../../../../../src/quest/domain/models/Quest.js';
import { getQuestResultsForCampaignParticipation } from '../../../../../src/quest/domain/usecases/get-quest-results-for-campaign-participation.js';
import { expect, sinon } from '../../../../test-helper.js';
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('Quest | Unit | Domain | Usecases | getQuestResultsForCampaignParticipa
new Quest({
id: 10,
eligibilityRequirements: [
{ type: 'campaignParticipations', data: { targetProfileIds: [wrongTargetProfileId] } },
{ type: TYPES.CAMPAIGN_PARTICIPATIONS, data: { targetProfileIds: [wrongTargetProfileId] } },
],
successRequirements: [],
rewardType: 'attestations',
Expand Down

0 comments on commit 13907dd

Please sign in to comment.