-
Notifications
You must be signed in to change notification settings - Fork 10
fix(logs): fixed total count for success and changed events names #3865
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class ManualMigration1756117243336 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration properly handles the event name changes with proper rollback capability. Consider adding a verification query after the update to ensure the migration succeeded and log the number of affected rows for operational visibility. |
||
UPDATE "app_log" | ||
SET action = CASE | ||
WHEN action = 'DOWNLOAD_IMPORT_GUIDE' THEN 'IMPORT_DOWNLOAD_GUIDE' | ||
WHEN action = 'DOWNLOAD_IMPORT_TEMPLATE' THEN 'IMPORT_TEMPLATE_DOWNLOAD' | ||
ELSE action | ||
END | ||
WHERE action IN ('DOWNLOAD_IMPORT_GUIDE', 'DOWNLOAD_IMPORT_TEMPLATE'); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
UPDATE "app_log" | ||
SET action = CASE | ||
WHEN action = 'IMPORT_DOWNLOAD_GUIDE' THEN 'DOWNLOAD_IMPORT_GUIDE' | ||
WHEN action = 'IMPORT_TEMPLATE_DOWNLOAD' THEN 'DOWNLOAD_IMPORT_TEMPLATE' | ||
ELSE action | ||
END | ||
WHERE action IN ('IMPORT_DOWNLOAD_GUIDE', 'IMPORT_TEMPLATE_DOWNLOAD'); | ||
`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { FailedUsagerImportLogContext } from "./../../../modules/app-logs/app-log-context.types"; | ||
import { HttpStatus } from "@nestjs/common"; | ||
|
||
import { pathExists } from "fs-extra"; | ||
|
@@ -18,7 +17,7 @@ import { ImportController } from "./import.controller"; | |
import { UsagerHistoryStateService } from "../../services/usagerHistoryState.service"; | ||
import { UsagersModule } from "../../usagers.module"; | ||
import { AppLogsService } from "../../../modules/app-logs/app-logs.service"; | ||
import { AppLog } from "../../../_common/model"; | ||
import { appLogsRepository } from "../../../database"; | ||
|
||
const importFilesDir = resolve( | ||
__dirname, | ||
|
@@ -27,26 +26,15 @@ const importFilesDir = resolve( | |
|
||
describe("Import Controller", () => { | ||
let controller: ImportController; | ||
let appLogService: AppLogsService; | ||
|
||
let context: AppTestContext; | ||
let authInfo: TestUserStructure; | ||
beforeAll(async () => { | ||
appLogService = { | ||
create: jest.fn(), | ||
}; | ||
context = await AppTestHelper.bootstrapTestApp( | ||
{ | ||
controllers: [ImportController], | ||
imports: [UsersModule, StructuresModule, UsagersModule], | ||
providers: [ | ||
UsagersService, | ||
UsagerHistoryStateService, | ||
{ | ||
provide: AppLogsService, | ||
useValue: appLogService, | ||
}, | ||
], | ||
providers: [UsagersService, UsagerHistoryStateService, AppLogsService], | ||
}, | ||
{ initApp: true } | ||
); | ||
|
@@ -58,8 +46,8 @@ describe("Import Controller", () => { | |
controller = context.module.get<ImportController>(ImportController); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
beforeEach(async () => { | ||
await appLogsRepository.clear(); | ||
}); | ||
|
||
afterAll(async () => { | ||
|
@@ -71,20 +59,6 @@ describe("Import Controller", () => { | |
}); | ||
|
||
it(`❌ Import d'un fichier Incorrect`, async () => { | ||
const expectedLogContextEntree: FailedUsagerImportLogContext = { | ||
nombreActifs: 0, | ||
nombreErreurs: 5, | ||
nombreTotal: 2, | ||
}; | ||
|
||
const expectedLog: AppLog = { | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
role: authInfo.role, | ||
context: expectedLogContextEntree, | ||
action: "IMPORT_USAGERS_FAILED", | ||
}; | ||
|
||
const importFilePath = resolve(importFilesDir, "import_ko_1.xlsx"); | ||
|
||
expect(await pathExists(importFilePath)).toBeTruthy(); | ||
|
@@ -98,9 +72,21 @@ describe("Import Controller", () => { | |
context, | ||
}); | ||
|
||
expect(appLogService.create).toHaveBeenCalledWith(expectedLog); | ||
|
||
expect(response.status).toBe(HttpStatus.BAD_REQUEST); | ||
|
||
const logs = await appLogsRepository.find({ | ||
where: { | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
}, | ||
}); | ||
expect(logs.length).toBe(1); | ||
expect(logs[0].action).toBe("IMPORT_USAGERS_FAILED"); | ||
expect(logs[0].context).toEqual({ | ||
nombreActifs: 0, | ||
nombreErreurs: 5, | ||
nombreTotal: 2, | ||
}); | ||
}); | ||
|
||
it(`✅ Import d'un fichier Valide 1️⃣`, async () => { | ||
|
@@ -116,16 +102,6 @@ describe("Import Controller", () => { | |
attachments: { file: importFilePath }, | ||
context, | ||
}); | ||
expect(appLogService.create).toHaveBeenCalledWith({ | ||
action: "IMPORT_USAGERS_SUCCESS", | ||
context: { | ||
nombreActifs: 19, | ||
nombreTotal: 0, | ||
}, | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
role: authInfo.role, | ||
}); | ||
expect(response.status).toBe(HttpStatus.OK); | ||
expect(JSON.parse(response.text)).toEqual({ | ||
importMode: "confirm", | ||
|
@@ -136,11 +112,23 @@ describe("Import Controller", () => { | |
totalCount: 0, | ||
}, | ||
}); | ||
|
||
const logs = await appLogsRepository.find({ | ||
where: { | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
}, | ||
}); | ||
expect(logs.length).toBe(1); | ||
expect(logs[0].action).toBe("IMPORT_USAGERS_SUCCESS"); | ||
pYassine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(logs[0].context).toEqual({ | ||
nombreActifs: 19, | ||
nombreTotal: 19, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The updated assertion |
||
}); | ||
}); | ||
|
||
it(`✅ Import d'un fichier Valide 2️⃣`, async () => { | ||
const importFilePath = resolve(importFilesDir, "import_ok_2.xlsx"); | ||
|
||
expect(await pathExists(importFilePath)).toBeTruthy(); | ||
|
||
const headers: { [name: string]: string } = {}; | ||
|
@@ -151,16 +139,6 @@ describe("Import Controller", () => { | |
attachments: { file: importFilePath }, | ||
context, | ||
}); | ||
expect(appLogService.create).toHaveBeenCalledWith({ | ||
action: "IMPORT_USAGERS_SUCCESS", | ||
context: { | ||
nombreActifs: 2, | ||
nombreTotal: 0, | ||
}, | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
role: authInfo.role, | ||
}); | ||
expect(response.status).toBe(HttpStatus.OK); | ||
expect(JSON.parse(response.text)).toEqual({ | ||
importMode: "confirm", | ||
|
@@ -171,5 +149,18 @@ describe("Import Controller", () => { | |
totalCount: 0, | ||
}, | ||
}); | ||
|
||
const logs = await appLogsRepository.find({ | ||
where: { | ||
userId: authInfo.id, | ||
structureId: authInfo.structureId, | ||
}, | ||
}); | ||
expect(logs.length).toBe(1); | ||
expect(logs[0].action).toBe("IMPORT_USAGERS_SUCCESS"); | ||
expect(logs[0].context).toEqual({ | ||
nombreActifs: 2, | ||
nombreTotal: 4, | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.