Skip to content

Commit

Permalink
chore(back): remove admin XP variables endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Jan 6, 2024
1 parent 1e1c75b commit 63c24dd
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 404 deletions.
180 changes: 1 addition & 179 deletions apps/backend-e2e/src/admin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {
AdminActivityDto,
MapDto,
ReportDto,
UserDto,
XpSystemsDto
UserDto
} from '@momentum/backend/dto';
import {
ActivityType,
Expand Down Expand Up @@ -2608,183 +2607,6 @@ describe('Admin', () => {
});
});

describe('admin/xpsys', () => {
let adminToken, modToken, u1Token;

beforeEach(async () => {
[adminToken, modToken, u1Token] = await Promise.all([
db.loginNewUser({ data: { roles: Role.ADMIN } }),
db.loginNewUser({ data: { roles: Role.MODERATOR } }),
db.loginNewUser()
]);

await prisma.xpSystems.deleteMany();
await prisma.xpSystems.create({
data: {
id: 1,
rankXP: {
top10: {
WRPoints: 3000,
rankPercentages: [
1, 0.75, 0.68, 0.61, 0.57, 0.53, 0.505, 0.48, 0.455, 0.43
]
},
groups: {
maxGroups: 4,
groupMinSizes: [10, 45, 125, 250],
groupExponents: [0.5, 0.56, 0.62, 0.68],
groupPointPcts: [0.2, 0.13, 0.07, 0.03],
groupScaleFactors: [1, 1.5, 2, 2.5]
},
formula: { A: 50000, B: 49 }
},

cosXP: {
levels: {
maxLevels: 500,
startingValue: 20000,
staticScaleStart: 101,
linearScaleInterval: 10,
staticScaleInterval: 25,
linearScaleBaseIncrease: 1000,
staticScaleBaseMultiplier: 1.5,
linearScaleIntervalMultiplier: 1,
staticScaleIntervalMultiplier: 0.5
},
completions: {
repeat: {
tierScale: { bonus: 40, linear: 20, staged: 40, stages: 5 }
},
unique: { tierScale: { linear: 2500, staged: 2500 } }
}
}
}
});
});

afterEach(() => db.cleanup('user'));
afterAll(() => db.cleanup('xpSystems'));

describe('GET', () => {
it('should respond with the current XP System variables when the user is an admin', () =>
req.get({
url: 'admin/xpsys',
status: 200,
token: adminToken,
validate: XpSystemsDto
}));

it('should respond with the current XP System variables when the user is a moderator', () =>
req.get({
url: 'admin/xpsys',
status: 200,
token: modToken,
validate: XpSystemsDto
}));

it('should 403 when the user requesting is not an admin', () =>
req.get({
url: 'admin/xpsys',
status: 403,
token: u1Token
}));

it('should 401 when no access token is provided', () =>
req.unauthorizedTest('admin/xpsys', 'get'));
});

describe('PUT', () => {
const body = {
rankXP: {
top10: {
WRPoints: 3000,
rankPercentages: [
1, 0.75, 0.68, 0.61, 0.57, 0.53, 0.505, 0.48, 0.455, 0.43
]
},
groups: {
maxGroups: 4,
groupMinSizes: [10, 45, 125, 250],
groupExponents: [0.5, 0.56, 0.62, 0.68],
groupPointPcts: [0.2, 0.13, 0.07, 0.03],
groupScaleFactors: [1, 1.5, 2, 2.5]
},
formula: { A: 50000, B: 49 }
},

cosXP: {
levels: {
maxLevels: 600,
startingValue: 20000,
staticScaleStart: 101,
linearScaleInterval: 10,
staticScaleInterval: 25,
linearScaleBaseIncrease: 1000,
staticScaleBaseMultiplier: 1.5,
linearScaleIntervalMultiplier: 1,
staticScaleIntervalMultiplier: 0.5
},
completions: {
repeat: {
tierScale: { bonus: 40, linear: 20, staged: 40, stages: 5 }
},
unique: { tierScale: { linear: 2500, staged: 2500 } }
}
}
};

it('should update the XP system variables', async () => {
await req.put({
url: 'admin/xpsys',
status: 204,
body: body,
token: adminToken
});

const res = await req.get({
url: 'admin/xpsys',
status: 200,
token: adminToken,
validate: XpSystemsDto
});

expect(res.body.cosXP.levels.maxLevels).toBe(600);
expect(res.body).toStrictEqual(body as XpSystemsDto);
});

it('should 400 when updating the XP system variables with missing values', async () => {
const incompleteBody = body;
delete incompleteBody.rankXP.top10.rankPercentages;

await req.put({
url: 'admin/xpsys',
status: 400,
body: incompleteBody,
token: adminToken
});
});

it('should 403 when the user requesting is a moderator', () =>
req.put({
url: 'admin/xpsys',
status: 403,
body: body,
token: modToken
}));

it('should 403 when the user requesting is not an admin', () =>
req.put({
url: 'admin/xpsys',
status: 403,
body: body,
token: u1Token
}));

it('should 401 when no access token is provided', () =>
req.unauthorizedTest('admin/xpsys', 'get'));
});
});

describe('admin/activities', () => {
describe('GET', () => {
let admin, adminToken, mod, u1, u1Token;
Expand Down
36 changes: 1 addition & 35 deletions apps/backend/src/app/modules/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Param,
Patch,
Post,
Put,
Query,
UseGuards
} from '@nestjs/common';
Expand All @@ -28,7 +27,6 @@ import { RolesGuard } from '../auth/roles.guard';
import { NonGameAuthGuard } from '../auth/jwt/game.guard';
import { LoggedInUser, Roles } from '@momentum/backend/decorators';
import { Role as RolesEnum } from '@momentum/constants';
import { XpSystemsService } from '../xp-systems/xp-systems.service';
import { MapsService } from '../maps/maps.service';
import { UsersService } from '../users/users.service';
import {
Expand All @@ -46,9 +44,7 @@ import {
ReportDto,
UpdateMapAdminDto,
UpdateReportDto,
UpdateXpSystemsDto,
UserDto,
XpSystemsDto
UserDto
} from '@momentum/backend/dto';
import { ParseIntSafePipe } from '@momentum/backend/pipes';
import { AdminActivityService } from './admin-activity.service';
Expand All @@ -62,7 +58,6 @@ import { AdminActivityService } from './admin-activity.service';
export class AdminController {
constructor(
private readonly adminService: AdminService,
private readonly xpSystems: XpSystemsService,
private readonly mapsService: MapsService,
private readonly usersService: UsersService,
private readonly adminActivityService: AdminActivityService
Expand Down Expand Up @@ -270,35 +265,6 @@ export class AdminController {
return this.adminService.updateReport(userID, reportID, body);
}

@Get('/xpsys')
@Roles(RolesEnum.ADMIN, RolesEnum.MODERATOR)
@ApiOperation({ description: 'Retrives the current XP system variables' })
@ApiOkResponse({
type: XpSystemsDto,
description: 'The current XP system variables'
})
getXPSystems() {
return this.xpSystems.get();
}

@Put('/xpsys')
@Roles(RolesEnum.ADMIN)
@ApiOperation({
description: 'Creates or Updates the current XP System variables'
})
@HttpCode(HttpStatus.NO_CONTENT)
@ApiNoContentResponse({
description: 'The XP System variables were updated successfully'
})
@ApiBody({
type: UpdateXpSystemsDto,
description: 'The XP System variables to set',
required: true
})
updateXPSystems(@Body() body: UpdateXpSystemsDto) {
return this.xpSystems.update(body);
}

@Get('/activities')
@Roles(RolesEnum.ADMIN, RolesEnum.MODERATOR)
@ApiOperation({
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/app/modules/admin/admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { AdminController } from './admin.controller';
import { AdminService } from './admin.service';
import { DbModule } from '../database/db.module';
import { MapsModule } from '../maps/maps.module';
import { XpSystemsModule } from '../xp-systems/xp-systems.module';
import { UsersModule } from '../users/users.module';
import { AdminActivityService } from './admin-activity.service';

@Module({
imports: [
DbModule.forRoot(),
forwardRef(() => MapsModule),
forwardRef(() => XpSystemsModule),
forwardRef(() => UsersModule)
],
controllers: [AdminController],
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/app/modules/xp-systems/xp-systems.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Module } from '@nestjs/common';
import { XpSystemsService } from './xp-systems.service';
import { DbModule } from '../database/db.module';

@Module({
imports: [DbModule.forRoot()],
providers: [XpSystemsService],
exports: [XpSystemsService]
})
Expand Down
1 change: 0 additions & 1 deletion libs/backend/dto/src/dtos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ export * from './user/notification.dto';
export * from './user/user-maps-summary.dto';
export * from './user/socials.dto';
export * from './user/admin-activity-dto';
export * from './xp-systems/xp-systems.dto';
Loading

0 comments on commit 63c24dd

Please sign in to comment.