github.com/hernad/nomad@v1.6.112/ui/tests/unit/utils/message-from-adapter-error-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { module, test } from 'qunit'; 7 import { ServerError, ForbiddenError } from '@ember-data/adapter/error'; 8 import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; 9 10 const testCases = [ 11 { 12 name: 'Forbidden Error', 13 in: [new ForbiddenError([], "Can't do that"), 'run tests'], 14 out: 'Your ACL token does not grant permission to run tests.', 15 }, 16 { 17 name: 'Generic Error', 18 in: [ 19 new ServerError([{ detail: 'DB Max Connections' }], 'Server Error'), 20 'run tests', 21 ], 22 out: 'DB Max Connections', 23 }, 24 { 25 name: 'Multiple Errors', 26 in: [ 27 new ServerError( 28 [{ detail: 'DB Max Connections' }, { detail: 'Service timeout' }], 29 'Server Error' 30 ), 31 'run tests', 32 ], 33 out: 'DB Max Connections\n\nService timeout', 34 }, 35 { 36 name: 'Malformed Error (not from Ember Data which should always have an errors list)', 37 in: [new Error('Go boom'), 'handle custom error messages'], 38 out: 'Unknown Error', 39 }, 40 ]; 41 42 module('Unit | Util | messageFromAdapterError', function () { 43 testCases.forEach((testCase) => { 44 test(testCase.name, function (assert) { 45 assert.equal( 46 messageFromAdapterError.apply(null, testCase.in), 47 testCase.out, 48 `[${testCase.in.join(', ')}] => ${testCase.out}` 49 ); 50 }); 51 }); 52 });