consul/ui/packages/consul-ui/tests/unit/utils/acls-status-test.js
John Cowen 6589cbbd0d
ui: Move to Workspaced Structure (#8994)
* ui: Add the most basic workspace root in /ui

* We already have a LICENSE file in the repository root

* Change directory path in build scripts ui-v2 -> ui

* Make yarn install flags configurable from elsewhere

* Minimal workspace root makefile

* Call the new docker specific target

* Update yarn in the docker build image

* Reconfigure the netlify target and move to the higher makefile

* Move ui-v2 -> ui/packages/consul-ui

* Change repo root to refleect new folder structure

* Temporarily don't hoist consul-api-double

* Fixup CI configuration

* Fixup lint errors

* Fixup Netlify target
2020-10-21 15:23:16 +01:00

90 lines
3.1 KiB
JavaScript

import { module } from 'qunit';
import test from 'ember-sinon-qunit/test-support/test';
import aclsStatus from 'consul-ui/utils/acls-status';
module('Unit | Utility | acls status', function() {
test('it rejects and nothing is enabled or authorized', function(assert) {
const isValidServerError = this.stub().returns(false);
const status = aclsStatus(isValidServerError);
[
this.stub().rejects(),
this.stub().rejects({ errors: [] }),
this.stub().rejects({ errors: [{ status: '404' }] }),
].forEach(function(reject) {
const actual = status({
response: reject(),
});
assert.rejects(actual.response);
['isAuthorized', 'isEnabled'].forEach(function(prop) {
actual[prop].then(function(actual) {
assert.notOk(actual);
});
});
});
});
test('with a 401 it resolves with an empty array and nothing is enabled or authorized', function(assert) {
assert.expect(3);
const isValidServerError = this.stub().returns(false);
const status = aclsStatus(isValidServerError);
const actual = status({
response: this.stub().rejects({ errors: [{ status: '401' }] })(),
});
actual.response.then(function(actual) {
assert.deepEqual(actual, []);
});
['isAuthorized', 'isEnabled'].forEach(function(prop) {
actual[prop].then(function(actual) {
assert.notOk(actual);
});
});
});
test("with a 403 it resolves with an empty array and it's enabled but not authorized", function(assert) {
assert.expect(3);
const isValidServerError = this.stub().returns(false);
const status = aclsStatus(isValidServerError);
const actual = status({
response: this.stub().rejects({ errors: [{ status: '403' }] })(),
});
actual.response.then(function(actual) {
assert.deepEqual(actual, []);
});
actual.isEnabled.then(function(actual) {
assert.ok(actual);
});
actual.isAuthorized.then(function(actual) {
assert.notOk(actual);
});
});
test("with a 500 (but not a 'valid' error) it rejects and nothing is enabled or authorized", function(assert) {
assert.expect(3);
const isValidServerError = this.stub().returns(false);
const status = aclsStatus(isValidServerError);
const actual = status({
response: this.stub().rejects({ errors: [{ status: '500' }] })(),
});
assert.rejects(actual.response);
['isAuthorized', 'isEnabled'].forEach(function(prop) {
actual[prop].then(function(actual) {
assert.notOk(actual);
});
});
});
test("with a 500 and a 'valid' error, it resolves with an empty array and it's enabled but not authorized", function(assert) {
assert.expect(3);
const isValidServerError = this.stub().returns(true);
const status = aclsStatus(isValidServerError);
const actual = status({
response: this.stub().rejects({ errors: [{ status: '500' }] })(),
});
actual.response.then(function(actual) {
assert.deepEqual(actual, []);
});
actual.isEnabled.then(function(actual) {
assert.ok(actual);
});
actual.isAuthorized.then(function(actual) {
assert.notOk(actual);
});
});
});