forked from comixed/comixed
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the clear task audit log feature [comixed#424]
* Added a new state to the backend-status module. * Added a toolbar to the audit log list page to clear the log.
- Loading branch information
Showing
27 changed files
with
843 additions
and
213 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
comixed-frontend/src/app/backend-status/actions/clear-task-audit-log.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { createAction } from '@ngrx/store'; | ||
|
||
export const clearTaskAuditLog = createAction( | ||
'[ClearTaskAuditLog] Clear the log' | ||
); | ||
|
||
export const taskAuditLogCleared = createAction( | ||
'[ClearTaskAuditLog] The log was cleared' | ||
); | ||
|
||
export const cleartaskAuditLogFailed = createAction( | ||
'[ClearTaskAuditLog] Failed to clear the log' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
comixed-frontend/src/app/backend-status/effects/clear-task-audit-log.effects.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Observable, of, throwError } from 'rxjs'; | ||
|
||
import { ClearTaskAuditLogEffects } from './clear-task-audit-log.effects'; | ||
import { TaskAuditLogService } from 'app/backend-status/services/task-audit-log.service'; | ||
import { AlertService, ApiResponse } from 'app/core'; | ||
import { CoreModule } from 'app/core/core.module'; | ||
import { | ||
clearTaskAuditLog, | ||
cleartaskAuditLogFailed, | ||
taskAuditLogCleared | ||
} from 'app/backend-status/actions/clear-task-audit-log.actions'; | ||
import { hot } from 'jasmine-marbles'; | ||
import { LoggerModule } from '@angular-ru/logger'; | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
describe('ClearTaskAuditLogEffects', () => { | ||
let actions$: Observable<any>; | ||
let effects: ClearTaskAuditLogEffects; | ||
let taskAuditLogService: jasmine.SpyObj<TaskAuditLogService>; | ||
let alertService: AlertService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [CoreModule, LoggerModule.forRoot(), TranslateModule.forRoot()], | ||
providers: [ | ||
ClearTaskAuditLogEffects, | ||
provideMockActions(() => actions$), | ||
{ | ||
provide: TaskAuditLogService, | ||
useValue: { | ||
clearAuditLog: jasmine.createSpy( | ||
'TaskAuditLogService.clearAuditLog()' | ||
) | ||
} | ||
} | ||
] | ||
}); | ||
|
||
effects = TestBed.get<ClearTaskAuditLogEffects>(ClearTaskAuditLogEffects); | ||
taskAuditLogService = TestBed.get(TaskAuditLogService); | ||
alertService = TestBed.get(AlertService); | ||
spyOn(alertService, 'info'); | ||
spyOn(alertService, 'error'); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(effects).toBeTruthy(); | ||
}); | ||
|
||
describe('clearing the audit log', () => { | ||
it('fires an action on success', () => { | ||
const serviceResponse = { success: true } as ApiResponse<void>; | ||
const action = clearTaskAuditLog(); | ||
const outcome = taskAuditLogCleared(); | ||
|
||
actions$ = hot('-a', { a: action }); | ||
taskAuditLogService.clearAuditLog.and.returnValue(of(serviceResponse)); | ||
|
||
const expected = hot('-b', { b: outcome }); | ||
expect(effects.clearTaskAuditLog$).toBeObservable(expected); | ||
expect(alertService.info).toHaveBeenCalledWith(jasmine.any(String)); | ||
}); | ||
|
||
it('fires an action on failure', () => { | ||
const serviceResponse = { success: false } as ApiResponse<void>; | ||
const action = clearTaskAuditLog(); | ||
const outcome = cleartaskAuditLogFailed(); | ||
|
||
actions$ = hot('-a', { a: action }); | ||
taskAuditLogService.clearAuditLog.and.returnValue(of(serviceResponse)); | ||
|
||
const expected = hot('-b', { b: outcome }); | ||
expect(effects.clearTaskAuditLog$).toBeObservable(expected); | ||
expect(alertService.error).toHaveBeenCalledWith(jasmine.any(String)); | ||
}); | ||
|
||
it('fires an action on service failure', () => { | ||
const serviceResponse = new HttpErrorResponse({}); | ||
const action = clearTaskAuditLog(); | ||
const outcome = cleartaskAuditLogFailed(); | ||
|
||
actions$ = hot('-a', { a: action }); | ||
taskAuditLogService.clearAuditLog.and.returnValue( | ||
throwError(serviceResponse) | ||
); | ||
|
||
const expected = hot('-b', { b: outcome }); | ||
expect(effects.clearTaskAuditLog$).toBeObservable(expected); | ||
expect(alertService.error).toHaveBeenCalledWith(jasmine.any(String)); | ||
}); | ||
|
||
it('fires an action on general failure', () => { | ||
const action = clearTaskAuditLog(); | ||
const outcome = cleartaskAuditLogFailed(); | ||
|
||
actions$ = hot('-a', { a: action }); | ||
taskAuditLogService.clearAuditLog.and.throwError('expected'); | ||
|
||
const expected = hot('-(b|)', { b: outcome }); | ||
expect(effects.clearTaskAuditLog$).toBeObservable(expected); | ||
expect(alertService.error).toHaveBeenCalledWith(jasmine.any(String)); | ||
}); | ||
}); | ||
}); |
94 changes: 94 additions & 0 deletions
94
comixed-frontend/src/app/backend-status/effects/clear-task-audit-log.effects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { Actions, createEffect, ofType } from '@ngrx/effects'; | ||
import { | ||
clearTaskAuditLog, | ||
cleartaskAuditLogFailed, | ||
taskAuditLogCleared | ||
} from 'app/backend-status/actions/clear-task-audit-log.actions'; | ||
import { catchError, map, switchMap, tap } from 'rxjs/operators'; | ||
import { LoggerService } from '@angular-ru/logger'; | ||
import { TaskAuditLogService } from 'app/backend-status/services/task-audit-log.service'; | ||
import { AlertService, ApiResponse } from 'app/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { of } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class ClearTaskAuditLogEffects { | ||
constructor( | ||
private logger: LoggerService, | ||
private actions$: Actions, | ||
private taskAuditLogService: TaskAuditLogService, | ||
private alertService: AlertService, | ||
private translateService: TranslateService | ||
) {} | ||
|
||
clearTaskAuditLog$ = createEffect(() => { | ||
return this.actions$.pipe( | ||
ofType(clearTaskAuditLog), | ||
tap(() => this.logger.debug('effect: clear audit log')), | ||
switchMap(() => | ||
this.taskAuditLogService.clearAuditLog().pipe( | ||
tap(response => this.logger.debug('received response:', response)), | ||
tap((response: ApiResponse<void>) => | ||
response.success | ||
? this.alertService.info( | ||
this.translateService.instant( | ||
'tasks.audit-log.effects.clear-audit-log.success.detail' | ||
) | ||
) | ||
: this.alertService.error( | ||
this.translateService.instant( | ||
'tasks.audit-log.effects.clear-audit-log.success.detail' | ||
) | ||
) | ||
), | ||
map((response: ApiResponse<void>) => | ||
response.success ? taskAuditLogCleared() : cleartaskAuditLogFailed() | ||
), | ||
catchError(error => { | ||
this.logger.error( | ||
'service failure clearing the task audit log:', | ||
error | ||
); | ||
this.alertService.error( | ||
this.translateService.instant( | ||
'tasks.audit-log.effects.clear-audit-log.success.detail' | ||
) | ||
); | ||
return of(cleartaskAuditLogFailed()); | ||
}) | ||
) | ||
), | ||
catchError(error => { | ||
this.logger.error( | ||
'service failure clearing the task audit log:', | ||
error | ||
); | ||
this.alertService.error( | ||
this.translateService.instant( | ||
'general-message.error.general-service-failure' | ||
) | ||
); | ||
return of(cleartaskAuditLogFailed()); | ||
}) | ||
); | ||
}); | ||
} |
Oops, something went wrong.