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