Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jxl9/ach tracking tests #223

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a285a1a
implement achievements tracking logic
jasmineee-li Apr 28, 2024
4ba5767
Merge branch 'master' into jxl9/achievements-tracking
neketka Apr 28, 2024
47ce5db
Fix achievement service import
neketka Apr 28, 2024
8a509c0
Add cascading delete to achievement tracker
neketka Apr 28, 2024
e82d43b
implement event lists from org
neketka Apr 29, 2024
f41dccd
Made achievement admin frontend
neketka Apr 29, 2024
d781b21
Bug fixes
neketka Apr 29, 2024
22864a3
fixed bugs, still need to pass tests
jasmineee-li Apr 29, 2024
c6b4a9d
Merge branch 'jxl9/achievements-tracking' into nikita/admin-and-data-…
neketka Apr 29, 2024
c89abec
Fix event trackers
neketka Apr 29, 2024
92680c3
Fix flutter build
neketka Apr 29, 2024
071bb8c
Finish achievement tracking
neketka Apr 29, 2024
d920c37
Fix emit order
neketka Apr 29, 2024
5ec6cb5
Fix other emit error
neketka Apr 29, 2024
f31fab2
Fix build errors
neketka Apr 30, 2024
797a559
Connected achievements to backend
neketka Apr 30, 2024
7e4b9fe
Fix inconsistencies
neketka Apr 30, 2024
2ab00ee
Complete integration
neketka Apr 30, 2024
49524af
Remove hardcoded complete
neketka Apr 30, 2024
351156f
Comment failing tests
neketka Apr 30, 2024
7b12a81
Attempt to fix tests
neketka Apr 30, 2024
3cf8e31
Fix more e2e failures
neketka Apr 30, 2024
9518e6a
Add exception for e2e tests in client service
neketka Apr 30, 2024
796f15f
Added extra logging
neketka Apr 30, 2024
11cdb0c
Fix incorrect nextChallenge
neketka Apr 30, 2024
51eeb31
Fix tests
neketka Apr 30, 2024
8782785
Fix nulls in test
neketka Apr 30, 2024
65e9796
Set progress limit
neketka Apr 30, 2024
dc21d2c
Merge branch 'master' into nikita/admin-and-data-fixes
neketka Apr 30, 2024
dbd0f40
Add manager rule for achievements
neketka Apr 30, 2024
a2c8538
Achivement trackers are made for all
neketka Apr 30, 2024
9ea5d39
Clarified prisma query
neketka Apr 30, 2024
1b12b5c
Merge branch 'master' into jxl9/ach-tracking-tests
jasmineee-li May 1, 2024
ce8c44b
Ran updateapi, ran tracker tests (successfully pass)
jasmineee-li May 1, 2024
01495f3
Add achievement tracking tests
jasmineee-li May 6, 2024
4b29753
Fix code style
jasmineee-li May 6, 2024
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
214 changes: 204 additions & 10 deletions server/src/achievement/achievement.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AchievementDto, AchievementTrackerDto } from './achievement.dto';
import { AppAbility, CaslAbilityFactory } from '../casl/casl-ability.factory';
import { ChallengeDto, ChallengeLocationDto } from '../challenge/challenge.dto';
import { AchievementTypeDto } from './achievement.dto';
import { GroupGateway } from '../group/group.gateway';

describe('AchievementModule E2E', () => {
let app: INestApplication;
Expand All @@ -36,12 +37,17 @@ describe('AchievementModule E2E', () => {
let eventService: EventService;
let user: User;
let tracker: AchievementTracker;
let event: EventBase;
let exJourney: EventBase;
let exJourney1: EventBase;
let exJourney2: EventBase;
let exChallenge1: EventBase;
let exChallenge2: EventBase;
let organizationService: OrganizationService;
let abilityFactory: CaslAbilityFactory;
let fullAbility: AppAbility;
let orgUsage: OrganizationSpecialUsage;
let challengeService: ChallengeService;
let groupGateway: GroupGateway;

/** beforeAll runs before anything else. It adds new users and prerequisites.
* afterAll runs after all the tests. It removes lingering values in the database.
Expand Down Expand Up @@ -80,6 +86,7 @@ describe('AchievementModule E2E', () => {
organizationService = module.get<OrganizationService>(OrganizationService);
abilityFactory = module.get<CaslAbilityFactory>(CaslAbilityFactory);
fullAbility = abilityFactory.createFull();
groupGateway = moduleRef.get<GroupGateway>(GroupGateway);

user = await userService.register(
'[email protected]',
Expand All @@ -99,7 +106,6 @@ describe('AchievementModule E2E', () => {
where: { id: user.id },
include: { memberOf: true },
});

// tracker = await achievementService.getAchievementsByIdsForAbility(fullAbility, )
console.log = log;
});
Expand Down Expand Up @@ -204,17 +210,205 @@ describe('AchievementModule E2E', () => {
});

describe('Testing achievement tracker', () => {
it('should update tracker progress when a challenge is completed', async () => {
// Assuming a challenge completion would update an existing tracker
const initialProgress = tracker.progress;
// it('should update tracker progress when a challenge is completed', async () => {
// // Assuming a challenge completion would update an existing tracker
// const initialProgress = tracker.progress;
// await challengeService.completeChallenge(user);

// const updatedTracker = await prisma.achievementTracker.findUnique({
// where: { id: tracker.id },
// });
// if (updatedTracker) {
// expect(updatedTracker.progress).toBeGreaterThan(initialProgress);
// }

// console.log("initial progress: " + initialProgress);
// console.log("updated progress: " + updatedTracker?.progress);
// });

// it('should mark tracker as complete when achievement criteria are met', async () => {
// // Complete a challenge that gives the final point needed
// const orgUsage = OrganizationSpecialUsage;
// const orgId = (
// await organizationService.getDefaultOrganization(orgUsage.DEVICE_LOGIN)
// ).id;

// exJourney1 = await organizationService.makeDefaultEvent(orgId);
// const achChalJourDto: AchievementDto = {
// id: "",
// eventId: exJourney1.id,
// name: 'achChalJourDto',
// description: 'ach dto',
// requiredPoints: 1,
// imageUrl: 'update test',
// locationType: ChallengeLocationDto.ARTS_QUAD,
// achievementType: AchievementTypeDto.TOTAL_CHALLENGES_OR_JOURNEYS,
// initialOrganizationId: orgId,
// };

// const achChalJour = await prisma.achievement.findFirstOrThrow({
// where: { name: 'achChalJourDto' },
// });

// const trackerChalJour = await achievementService.createAchievementTracker(
// user,
// achChalJour.id,
// );

// await groupGateway.setCurrentEvent(user, { eventId: tracker.id });
// await challengeService.completeChallenge(user);

// const completedTracker = await prisma.achievementTracker.findUnique({
// where: { id: tracker.id },
// });
// expect(completedTracker).not.toBeNull();
// expect(completedTracker!.dateComplete).not.toBeNull();
// });

it('should test ach tracker on dif achievement types; update tracker with progress; and mark tracker as complete when achievement criteria are met', async () => {
const orgUsage = OrganizationSpecialUsage;
const orgId = (
await organizationService.getDefaultOrganization(orgUsage.DEVICE_LOGIN)
).id;

exJourney1 = await organizationService.makeDefaultEvent(orgId);
exJourney2 = await organizationService.makeDefaultEvent(orgId);
exChallenge1 = await organizationService.makeDefaultEvent(orgId);
exChallenge2 = await organizationService.makeDefaultEvent(orgId);
const achChalJourDto: AchievementDto = {
id: '',
eventId: exJourney1.id,
name: 'achChalJourDto',
description: 'ach dto',
requiredPoints: 1,
imageUrl: 'update test',
locationType: ChallengeLocationDto.ARTS_QUAD,
achievementType: AchievementTypeDto.TOTAL_CHALLENGES_OR_JOURNEYS,
initialOrganizationId: orgId,
};
const achChalDto: AchievementDto = {
id: '',
eventId: exChallenge1.id,
name: 'achChalDto',
description: 'ach dto',
requiredPoints: 1,
imageUrl: 'update test',
locationType: ChallengeLocationDto.ARTS_QUAD,
achievementType: AchievementTypeDto.TOTAL_CHALLENGES,
initialOrganizationId: orgId,
};

const achPtsDto: AchievementDto = {
id: '',
eventId: exChallenge2.id,
name: 'achPtsDto',
description: 'ach dto',
requiredPoints: 10,
imageUrl: 'update test',
locationType: ChallengeLocationDto.ARTS_QUAD,
achievementType: AchievementTypeDto.TOTAL_POINTS,
initialOrganizationId: orgId,
};

const achJourDto: AchievementDto = {
id: '',
eventId: exJourney2.id,
name: 'achJourDto',
description: 'ach dto',
requiredPoints: 1,
imageUrl: 'update test',
locationType: ChallengeLocationDto.ARTS_QUAD,
achievementType: AchievementTypeDto.TOTAL_JOURNEYS,
initialOrganizationId: orgId,
};

await achievementService.upsertAchievementFromDto(
fullAbility,
achChalDto,
);
await achievementService.upsertAchievementFromDto(
fullAbility,
achChalJourDto,
);
await achievementService.upsertAchievementFromDto(
fullAbility,
achJourDto,
);
await achievementService.upsertAchievementFromDto(fullAbility, achPtsDto);

const achChal = await prisma.achievement.findFirstOrThrow({
where: { name: 'achChalDto' },
});
const achChalJour = await prisma.achievement.findFirstOrThrow({
where: { name: 'achChalJourDto' },
});
const achJour = await prisma.achievement.findFirstOrThrow({
where: { name: 'achJourDto' },
});
const achPts = await prisma.achievement.findFirstOrThrow({
where: { name: 'achPtsDto' },
});

const trackerChal = await achievementService.createAchievementTracker(
user,
achChal.id,
);
const trackerChalJour = await achievementService.createAchievementTracker(
user,
achChalJour.id,
);
const trackerJour = await achievementService.createAchievementTracker(
user,
achJour.id,
);
const trackerPts = await achievementService.createAchievementTracker(
user,
achPts.id,
);

await groupGateway.setCurrentEvent(user, { eventId: exChallenge1.id });
await challengeService.completeChallenge(user);

const updatedTracker = await prisma.achievementTracker.findUnique({
where: { id: tracker.id },
const newTrackerChal = await prisma.achievementTracker.findFirstOrThrow({
where: { id: trackerChal.id },
});
if (updatedTracker) {
expect(updatedTracker.progress).toBeGreaterThan(initialProgress);
}

expect(newTrackerChal.progress).toBeGreaterThan(0);
expect(newTrackerChal.dateComplete).not.toBeNull();

expect(trackerChalJour.progress).toBe(0);
expect(trackerJour.progress).toBe(0);
expect(trackerPts.progress).toBe(0);

await groupGateway.setCurrentEvent(user, { eventId: exJourney1.id });
await challengeService.completeChallenge(user);

const newTrackerChalJour =
await prisma.achievementTracker.findFirstOrThrow({
where: { id: trackerChalJour.id },
});
expect(newTrackerChalJour.progress).toBeGreaterThan(0);
expect(newTrackerChalJour.dateComplete).not.toBeNull();

// const completedTracker = await prisma.achievementTracker.findUnique({
// where: { id: trackerChal.id },
// });
// const completedTrackerJour = await prisma.achievementTracker.findUnique({
// where: { id: trackerChalJour.id },
// });
// const completedTrackerJour2 = await prisma.achievementTracker.findUnique({
// where: { id: trackerJour.id },
// });
// const completedTrackerPts = await prisma.achievementTracker.findUnique({
// where: { id: trackerPts.id },
// });

// expect(completedTracker?.progress).toBeGreaterThan(0);
// expect(completedTrackerJour?.progress).toBeGreaterThan(0);
// expect(completedTrackerJour2?.progress).toBeGreaterThan(0);
// expect(completedTrackerPts?.progress).toBeGreaterThan(0);

// achievem
});
});
/*
Expand Down
2 changes: 1 addition & 1 deletion server/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class OrganizationService {
}

return await this.prisma.challenge.create({
data: {
data: {
...defaultChallengeData,
linkedEventId: evId,
eventIndex: index,
Expand Down
Loading