Skip to content

Commit

Permalink
fix(backend): fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Nov 18, 2024
1 parent ba5fae5 commit 1373594
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const UsagerDocsControllerSecurityTests: AppTestHttpClientSecurityTestDef
{
roles: ["simple", "responsable", "admin"],
validExpectedResponseStatus: HttpStatus.BAD_REQUEST, // filesystem document does not exists in tests
invalidStructureIdExpectedResponseStatus: HttpStatus.BAD_REQUEST,
}
),
}),
Expand All @@ -45,6 +46,7 @@ export const UsagerDocsControllerSecurityTests: AppTestHttpClientSecurityTestDef
roles: ["simple", "responsable", "admin"],
validStructureIds: [1],
validExpectedResponseStatus: HttpStatus.OK, // filesystem document does not exists in tests
invalidStructureIdExpectedResponseStatus: HttpStatus.BAD_REQUEST,
}
),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { CurrentUsager } from "../../auth/decorators/current-usager.decorator";
import { CurrentUser } from "../../auth/decorators/current-user.decorator";
import { UsagerAccessGuard } from "../../auth/guards/usager-access.guard";

import { UserStructureAuthenticated } from "../../_common/model";
import {
USER_STRUCTURE_ROLE_ALL,
UserStructureAuthenticated,
} from "../../_common/model";
import {
UserStructureResume,
UsagerNote,
Expand All @@ -36,13 +39,15 @@ import { CurrentUsagerNote } from "../../auth/decorators/current-usager-note.dec
import { AppUserGuard, UsagerNoteAccessGuard } from "../../auth/guards";
import { PageResultsDto, PageMetaDto, PageOptionsDto } from "../dto/pagination";
import { ObjectLiteral } from "typeorm";
import { AllowUserStructureRoles } from "../../auth/decorators";

@ApiTags("usagers-notes")
@ApiBearerAuth()
@Controller("usagers-notes")
@UseGuards(AuthGuard("jwt"), AppUserGuard)
export class UsagerNotesController {
@Post("search/:usagerRef/:archived")
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@UseGuards(UsagerAccessGuard)
public async getUsagerNotes(
@CurrentUser() currentUser: UserStructureAuthenticated,
Expand Down Expand Up @@ -75,8 +80,9 @@ export class UsagerNotesController {
return new PageResultsDto(entities, pageMetaDto);
}

@Post(":usagerRef")
@UseGuards(UsagerAccessGuard)
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@Post(":usagerRef")
public async createNote(
@Body() createNoteDto: CreateNoteDto,
@CurrentUser() currentUser: UserStructureAuthenticated,
Expand All @@ -98,6 +104,7 @@ export class UsagerNotesController {
}

@Delete(":usagerRef/:noteUUID")
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@UseGuards(UsagerAccessGuard, UsagerNoteAccessGuard)
public async deleteNote(
@CurrentUser() currentUser: UserStructureAuthenticated,
Expand Down Expand Up @@ -131,6 +138,7 @@ export class UsagerNotesController {
}

@Put(":usagerRef/pin/:noteUUID")
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@UseGuards(UsagerAccessGuard, UsagerNoteAccessGuard)
public async pinNote(
@CurrentUser() _currentUser: UserStructureAuthenticated,
Expand Down Expand Up @@ -164,6 +172,7 @@ export class UsagerNotesController {
}

@Get("count/:usagerRef")
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@UseGuards(UsagerAccessGuard)
public async countNotes(
@CurrentUser() _currentUser: UserStructureAuthenticated,
Expand All @@ -177,6 +186,7 @@ export class UsagerNotesController {
}

@Put(":usagerRef/archive/:noteUUID")
@AllowUserStructureRoles(...USER_STRUCTURE_ROLE_ALL)
@UseGuards(UsagerAccessGuard, UsagerNoteAccessGuard)
public async archiveNote(
@CurrentUser() currentUser: UserStructureAuthenticated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class UsagersController {
if (search?.lastInteractionDate) {
const deadlines = getUsagerDeadlines();
const date = deadlines[search.lastInteractionDate].value;
console.log({ date, deadlines });

query.andWhere(
` ("lastInteraction"->>'dateInteraction')::timestamp >= :date`,
{
Expand Down

0 comments on commit 1373594

Please sign in to comment.