REDROOM
PHP 8.2.30
Path:
Logout
Edit File
Size: 3.78 KB
Close
/home/byroehnu/easepay.easetack.com/node_modules/adminjs/src/backend/services/action-error-handler/action-error-handler.spec.ts
Text
Base64
import sinon from 'sinon' import { expect } from 'chai' import { ActionContext } from '../../actions/action.interface.js' import BaseResource from '../../adapters/resource/base-resource.js' import { CurrentAdmin } from '../../../current-admin.interface.js' import BaseRecord from '../../adapters/record/base-record.js' import ValidationError from '../../utils/errors/validation-error.js' import ActionErrorHandler from './action-error-handler.js' import ForbiddenError from '../../utils/errors/forbidden-error.js' import { ActionDecorator } from '../../decorators/index.js' describe('ActionErrorHandler', function () { let resource: BaseResource let record: BaseRecord let context: ActionContext let action: ActionDecorator const notice = { message: 'thereWereValidationErrors', type: 'error', } const currentAdmin = {} as CurrentAdmin beforeEach(function () { resource = sinon.createStubInstance(BaseResource) record = sinon.createStubInstance(BaseRecord) as unknown as BaseRecord // translateMessage = sinon.stub().returns(notice.message) action = { name: 'myAction' } as ActionDecorator context = { resource, record, currentAdmin, action } as ActionContext }) afterEach(function () { sinon.restore() }) it('returns record with validation error when ValidationError is thrown', function () { const errors = { fieldWithError: { type: 'required', message: 'Field is required', }, } const error = new ValidationError(errors) expect(ActionErrorHandler(error, context)).to.deep.equal({ record: { baseError: null, errors, params: {}, populated: {}, }, notice, records: [], meta: undefined, }) }) it('returns meta when ValidationError is thrown for the list action', function () { const errors = { fieldWithError: { type: 'required', message: 'Field is required', }, } const error = new ValidationError(errors) action.name = 'list' expect(ActionErrorHandler(error, context)).to.deep.equal({ record: { baseError: null, errors, params: {}, populated: {}, }, notice, records: [], meta: { total: 0, perPage: 0, page: 0, direction: null, sortBy: null, }, }) }) it('throws any undefined error back to the app', function () { const unknownError = new Error() expect(() => { ActionErrorHandler(unknownError, context) }).to.throw(unknownError) }) it('returns record with forbidden error when ForbiddenError is thrown', function () { const errorMessage = 'You cannot perform this action' const error = new ForbiddenError(errorMessage) expect(ActionErrorHandler(error, context)).to.deep.equal({ record: { baseError: { message: errorMessage, type: 'ForbiddenError', }, errors: {}, params: {}, populated: {}, }, records: [], notice: { message: errorMessage, type: 'error', }, meta: undefined, }) }) it('returns meta when ForbiddenError is thrown for the list action', function () { const errorMessage = 'You cannot perform this action' const error = new ForbiddenError(errorMessage) action.name = 'list' expect(ActionErrorHandler(error, context)).to.deep.equal({ record: { baseError: { message: errorMessage, type: 'ForbiddenError', }, errors: {}, params: {}, populated: {}, }, notice: { message: errorMessage, type: 'error', }, records: [], meta: { total: 0, perPage: 0, page: 0, direction: null, sortBy: null, }, }) }) })
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 4
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
.htaccess
127 B
lr--r--r--
2026-03-14 01:49:20
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
action-error-handler.spec.ts
3.78 KB
lrw-r--r--
2026-02-28 00:31:58
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
action-error-handler.ts
2.28 KB
lrw-r--r--
2026-02-28 00:31:58
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
index.ts
74 B
lrw-r--r--
2026-02-28 00:32:28
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).