github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/ui-v2/tests/unit/utils/http/acl/is-valid-server-error-test.js (about) 1 import createIsValidServerError from 'consul-ui/utils/http/acl/is-valid-server-error'; 2 import { module, test } from 'qunit'; 3 4 module('Unit | Utility | http/acl/is valid server error'); 5 const createEmberDataError = function(response) { 6 return { 7 errors: [ 8 { 9 detail: response, 10 }, 11 ], 12 }; 13 }; 14 test('it returns a function', function(assert) { 15 const isValidServerError = createIsValidServerError(); 16 assert.ok(typeof isValidServerError === 'function'); 17 }); 18 test("it returns false if there is no 'correctly' formatted error", function(assert) { 19 const isValidServerError = createIsValidServerError(); 20 assert.notOk(isValidServerError()); 21 assert.notOk(isValidServerError({})); 22 assert.notOk(isValidServerError({ errors: {} })); 23 assert.notOk(isValidServerError({ errors: [{}] })); 24 assert.notOk(isValidServerError({ errors: [{ notDetail: '' }] })); 25 }); 26 // don't go too crazy with these, just enough for sanity check, we are essentially testing indexOf 27 test("it returns false if the response doesn't contain the exact error response", function(assert) { 28 const isValidServerError = createIsValidServerError(); 29 [ 30 "pc error making call: rpc: can't find method ACL", 31 "rpc error making call: rpc: can't find method", 32 "rpc rror making call: rpc: can't find method ACL", 33 ].forEach(function(response) { 34 const e = createEmberDataError(response); 35 assert.notOk(isValidServerError(e)); 36 }); 37 }); 38 test('it returns true if the response contains the exact error response', function(assert) { 39 const isValidServerError = createIsValidServerError(); 40 [ 41 "rpc error making call: rpc: can't find method ACL", 42 " rpc error making call: rpc: can't find method ACL", 43 "rpc error making call: rpc: rpc error making call: rpc: rpc error making call: rpc: can't find method ACL", 44 ].forEach(function(response) { 45 const e = createEmberDataError(response); 46 assert.ok(isValidServerError(e)); 47 }); 48 });