mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-18 17:21:13 +01:00
* WIP updating config-ui engine to use api service and form class * updates form-field component to support false values for radio types * updates api-error-message util to log out error in dev env * fixes issues in custom messages create and edit workflows * fixes issues in api service * updates capabilities handling * updates to custom messages form * removes store from custom messages tests * removes store as dependency from config-ui engine * removes commented out code in messages route * updates orderedKeys to displayFields in messages page component * removes unneccesary method var from message create-and-edit component * removes comment about model in message details page
63 lines
2.3 KiB
JavaScript
63 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import apiErrorMessage from 'vault/utils/api-error-message';
|
|
import ENV from 'vault/config/environment';
|
|
import sinon from 'sinon';
|
|
|
|
module('Unit | Util | api-error-message', function (hooks) {
|
|
hooks.beforeEach(function () {
|
|
this.apiError = {
|
|
errors: ['first error', 'second error'],
|
|
message: 'there were some errors',
|
|
};
|
|
this.getErrorContext = () => ({ response: new Response(JSON.stringify(this.apiError)) });
|
|
});
|
|
|
|
test('it should return errors from ErrorContext', async function (assert) {
|
|
const message = await apiErrorMessage(this.getErrorContext());
|
|
assert.strictEqual(message, 'first error, second error');
|
|
});
|
|
|
|
test('it should return message from ErrorContext when errors are empty', async function (assert) {
|
|
this.apiError.errors = [];
|
|
const message = await apiErrorMessage(this.getErrorContext());
|
|
assert.strictEqual(message, 'there were some errors');
|
|
});
|
|
|
|
test('it should return fallback message for ErrorContext without errors or message', async function (assert) {
|
|
this.apiError = {};
|
|
const message = await apiErrorMessage(this.getErrorContext());
|
|
assert.strictEqual(message, 'An error occurred, please try again');
|
|
});
|
|
|
|
test('it should return message from Error', async function (assert) {
|
|
const error = new Error('some js type error');
|
|
const message = await apiErrorMessage(error);
|
|
assert.strictEqual(message, error.message);
|
|
});
|
|
|
|
test('it should return default fallback', async function (assert) {
|
|
const message = await apiErrorMessage('some random error');
|
|
assert.strictEqual(message, 'An error occurred, please try again');
|
|
});
|
|
|
|
test('it should return custom fallback message', async function (assert) {
|
|
const fallback = 'Everything is broken, sorry';
|
|
const message = await apiErrorMessage('some random error', fallback);
|
|
assert.strictEqual(message, fallback);
|
|
});
|
|
|
|
test('it should log out error in development environment', async function (assert) {
|
|
const consoleStub = sinon.stub(console, 'error');
|
|
sinon.stub(ENV, 'environment').value('development');
|
|
const error = new Error('some js type error');
|
|
await apiErrorMessage(error);
|
|
assert.true(consoleStub.calledWith('API Error:', error));
|
|
sinon.restore();
|
|
});
|
|
});
|