github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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: [
    14        new ServerError([{ detail: 'DB Max Connections' }], 'Server Error'),
    15        'run tests',
    16      ],
    17      out: 'DB Max Connections',
    18    },
    19    {
    20      name: 'Multiple Errors',
    21      in: [
    22        new ServerError(
    23          [{ detail: 'DB Max Connections' }, { detail: 'Service timeout' }],
    24          'Server Error'
    25        ),
    26        'run tests',
    27      ],
    28      out: 'DB Max Connections\n\nService timeout',
    29    },
    30    {
    31      name: 'Malformed Error (not from Ember Data which should always have an errors list)',
    32      in: [new Error('Go boom'), 'handle custom error messages'],
    33      out: 'Unknown Error',
    34    },
    35  ];
    36  
    37  module('Unit | Util | messageFromAdapterError', function () {
    38    testCases.forEach((testCase) => {
    39      test(testCase.name, function (assert) {
    40        assert.equal(
    41          messageFromAdapterError.apply(null, testCase.in),
    42          testCase.out,
    43          `[${testCase.in.join(', ')}] => ${testCase.out}`
    44        );
    45      });
    46    });
    47  });