diff --git a/apps/backend-e2e/src/prisma.e2e-spec.ts b/apps/backend-e2e/src/prisma.e2e-spec.ts index d15d6229e..65dae2c01 100644 --- a/apps/backend-e2e/src/prisma.e2e-spec.ts +++ b/apps/backend-e2e/src/prisma.e2e-spec.ts @@ -80,7 +80,7 @@ describe('Prisma Client Extensions', () => { expect(profile.userID).toBe(userID); expect(userStats).toMatchObject({ userID: userID, - level: 1, + level: 0, cosXP: 0n, mapsCompleted: 0, runsSubmitted: 0, diff --git a/apps/backend/src/app/modules/xp-systems/xp-system.service.spec.ts b/apps/backend/src/app/modules/xp-systems/xp-system.service.spec.ts new file mode 100644 index 000000000..df0f18626 --- /dev/null +++ b/apps/backend/src/app/modules/xp-systems/xp-system.service.spec.ts @@ -0,0 +1,45 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { XpSystemsService } from './xp-systems.service'; +import { mockDeep } from 'jest-mock-extended'; +import { PRISMA_MOCK_PROVIDER } from '../../../../test/prisma-mock.const'; + +describe('XpSystemsService', () => { + let service: XpSystemsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [XpSystemsService, PRISMA_MOCK_PROVIDER] + }) + .useMocker(mockDeep) + .compile(); + + service = module.get(XpSystemsService); + await service.onModuleInit(); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); + + describe('getCosmeticXpInLevel', () => { + it('should handle 0', () => { + const xp = service.getCosmeticXpInLevel(0); + expect(xp).toEqual(0); + }); + it('should handle greater than 0', () => { + const xp = service.getCosmeticXpInLevel(1); + expect(xp).toBeGreaterThan(0); + }); + }); + + describe('getCosmeticXpForLevel', () => { + it('should handle 0', () => { + const xp = service.getCosmeticXpForLevel(0); + expect(xp).toEqual(0); + }); + it('should handle greater than 0', () => { + const xp = service.getCosmeticXpForLevel(1); + expect(xp).toBeGreaterThan(0); + }); + }); +}); diff --git a/apps/backend/src/app/modules/xp-systems/xp-systems.service.ts b/apps/backend/src/app/modules/xp-systems/xp-systems.service.ts index 476ba5e94..9c6e2c2a7 100644 --- a/apps/backend/src/app/modules/xp-systems/xp-systems.service.ts +++ b/apps/backend/src/app/modules/xp-systems/xp-systems.service.ts @@ -36,7 +36,7 @@ const DEFAULT_RANK_XP: RankXpParams = { const DEFAULT_COS_XP: CosXpParams = { levels: { maxLevels: 500, - startingValue: 20000, + startingValue: 0, linearScaleBaseIncrease: 1000, linearScaleInterval: 10, linearScaleIntervalMultiplier: 1, @@ -127,7 +127,7 @@ export class XpSystemsService implements OnModuleInit { getCosmeticXpInLevel(level: number): number { const levels = this._cosXpParams.levels; - if (!levels || level < 1 || level > levels.maxLevels) return -1; + if (!levels || level < 0 || level > levels.maxLevels) return -1; if (level < levels.staticScaleStart) { return ( @@ -159,7 +159,7 @@ export class XpSystemsService implements OnModuleInit { getCosmeticXpForLevel(level: number): number { if ( !this._cosXpParams || - level < 1 || + level < 0 || level > this._cosXpParams.levels.maxLevels ) return -1; @@ -299,11 +299,11 @@ export class XpSystemsService implements OnModuleInit { this.xpInLevels = [0]; this.xpForLevels = [0, 0]; - for (let i = 1; i < this._cosXpParams.levels.maxLevels; i++) { + for (let i = 0; i < this._cosXpParams.levels.maxLevels; i++) { this.xpInLevels[i] = this.getCosmeticXpInLevel(i); - if (i > 1) - this.xpForLevels[i] = this.xpForLevels[i - 1] + this.xpInLevels[i - 1]; + if (i > 0) + this.xpForLevels[i] = this.xpForLevels[i - 1] + this.xpInLevels[i]; } } diff --git a/libs/db/src/prisma/schema.prisma b/libs/db/src/prisma/schema.prisma index ea0426310..0c49f0176 100644 --- a/libs/db/src/prisma/schema.prisma +++ b/libs/db/src/prisma/schema.prisma @@ -63,7 +63,7 @@ model UserAuth { model UserStats { totalJumps BigInt @default(0) @db.BigInt totalStrafes BigInt @default(0) @db.BigInt - level Int @default(1) @db.SmallInt + level Int @default(0) @db.SmallInt cosXP BigInt @default(0) @db.BigInt mapsCompleted Int @default(0) runsSubmitted Int @default(0)