Skip to content

Commit

Permalink
Test coverage for the messageFromAdapterError util
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Jan 28, 2021
1 parent dbf826d commit 5dfa556
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ui/tests/unit/utils/message-from-adapter-error-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { module, test } from 'qunit';
import { ServerError, ForbiddenError } from '@ember-data/adapter/error';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';

const testCases = [
{
name: 'Forbidden Error',
in: [new ForbiddenError([], "Can't do that"), 'run tests'],
out: 'Your ACL token does not grant permission to run tests.',
},
{
name: 'Generic Error',
in: [new ServerError([{ detail: 'DB Max Connections' }], 'Server Error'), 'run tests'],
out: 'DB Max Connections',
},
{
name: 'Multiple Errors',
in: [
new ServerError(
[{ detail: 'DB Max Connections' }, { detail: 'Service timeout' }],
'Server Error'
),
'run tests',
],
out: 'DB Max Connections\n\nService timeout',
},
{
name: 'Malformed Error (not from Ember Data which should always have an errors list)',
in: [new Error('Go boom'), 'handle custom error messages'],
out: 'Unknown Error',
},
];

module('Unit | Util | messageFromAdapterError', function() {
testCases.forEach(testCase => {
test(testCase.name, function(assert) {
assert.equal(
messageFromAdapterError.apply(null, testCase.in),
testCase.out,
`[${testCase.in.join(', ')}] => ${testCase.out}`
);
});
});
});

0 comments on commit 5dfa556

Please sign in to comment.