refactor(audit): type-safe enums, expanded coverage, and crash-safe logging
Replace magic strings with AuditAction/AuditStatus enums across all consumers, add logAuditWithCurrentUser() convenience wrapper, extend audit coverage to data import, result export, app update, and ERP credentials operations, and harden crash handlers with try/catch to prevent audit failures from cascading. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
8
tests/fixtures/factory.ts
vendored
8
tests/fixtures/factory.ts
vendored
@@ -419,11 +419,11 @@ export class AuditLogFactory {
|
||||
*
|
||||
* @example
|
||||
* // Successful login audit
|
||||
* const entry = AuditLogFactory.createAuditLog('LOGIN', 'SUCCESS')
|
||||
* const entry = AuditLogFactory.createAuditLog(AuditAction.LOGIN, AuditStatus.SUCCESS)
|
||||
*
|
||||
* @example
|
||||
* // Failed extract audit
|
||||
* const entry = AuditLogFactory.createAuditLog('EXTRACT', 'FAILURE', { resource: 'Order SC123' })
|
||||
* const entry = AuditLogFactory.createAuditLog(AuditAction.EXTRACT, AuditStatus.FAILURE, { resource: 'Order SC123' })
|
||||
*/
|
||||
static createAuditLog(
|
||||
action: AuditAction = AuditAction.LOGIN,
|
||||
@@ -431,13 +431,15 @@ export class AuditLogFactory {
|
||||
overrides?: Partial<AuditEntry>
|
||||
): AuditEntry {
|
||||
return {
|
||||
timestamp: new Date(),
|
||||
timestamp: new Date().toISOString(),
|
||||
action,
|
||||
userId: 'USR-001',
|
||||
username: 'test_user',
|
||||
computerName: 'TEST-PC',
|
||||
appVersion: '1.0.0',
|
||||
resource: 'test-resource',
|
||||
status,
|
||||
metadata: {},
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
2
tests/fixtures/other-factories.test.ts
vendored
2
tests/fixtures/other-factories.test.ts
vendored
@@ -91,7 +91,7 @@ describe('AuditLogFactory', () => {
|
||||
it('creates audit log with default values', () => {
|
||||
const entry = AuditLogFactory.createAuditLog()
|
||||
|
||||
expect(entry.timestamp).toBeInstanceOf(Date)
|
||||
expect(typeof entry.timestamp).toBe('string')
|
||||
expect(entry.action).toBe(AuditAction.LOGIN)
|
||||
expect(entry.status).toBe(AuditStatus.SUCCESS)
|
||||
expect(entry.userId).toBe('USR-001')
|
||||
|
||||
Reference in New Issue
Block a user