Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 15, 2021
1 parent 52a5aae commit 2e60252
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 16 deletions.
18 changes: 18 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@
"lines": 80,
"statements": 80
},
"./src/app/metadata/domain/filter/component/": {
"branches": 0,
"functions": 0,
"lines": 0,
"statements": 0
},
"./src/app/metadata/domain/source/component/": {
"branches": 0,
"functions": 0,
"lines": 0,
"statements": 0
},
"./src/app/metadata/domain/provider/component/": {
"branches": 0,
"functions": 0,
"lines": 0,
"statements": 0
},
"./src/app/metadata/hooks/": {
"branches": 80,
"functions": 80,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const CustomAttributeDefinition = {
return data;
}
const { attributeType } = data;
let parsed = { ...data };
let { defaultValueBoolean, defaultValueString, ...parsed } = data;
if (attributeType === 'SELECTION_LIST') {
parsed = {
...parsed,
Expand All @@ -61,14 +61,14 @@ export const CustomAttributeDefinition = {
if (attributeType === 'BOOLEAN') {
parsed = {
...parsed,
defaultValue: data.defaultValueBoolean
defaultValue: defaultValueBoolean
}
}

if (attributeType === 'STRING') {
parsed = {
...parsed,
defaultValue: data.defaultValueString
defaultValue: defaultValueString
}
}

Expand All @@ -79,30 +79,30 @@ export const CustomAttributeDefinition = {
if (!changes) {
return changes;
}
let formatted = { ...changes };
let { defaultValue, ...formatted } = changes;
const { attributeType } = changes;

if (attributeType === 'SELECTION_LIST') {
formatted = {
...formatted,
customAttrListDefinitions: formatted.customAttrListDefinitions.map(d => ({
value: d,
default: d === changes.defaultValue
default: d === defaultValue
}))
}
}

if (attributeType === 'BOOLEAN') {
formatted = {
...formatted,
defaultValueBoolean: formatted.defaultValue === 'true' ? true : false
defaultValueBoolean: defaultValue === 'true' ? true : false
}
}

if (attributeType === 'STRING') {
formatted = {
...formatted,
defaultValueString: formatted.defaultValue
defaultValueString: defaultValue
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { CustomAttributeDefinition } from "./CustomAttributeDefinition";


describe('formatter', () => {
it('should format the object passed for the json-schema-form', () => {
expect(CustomAttributeDefinition.formatter(null)).toBeNull();

expect(CustomAttributeDefinition.formatter({
helpText: 'foo',
attributeType: 'SELECTION_LIST',
customAttrListDefinitions: [
'foo'
],
defaultValue: 'foo'
})).toEqual({
helpText: 'foo',
attributeType: 'SELECTION_LIST',
customAttrListDefinitions: [
{
default: true,
value: 'foo'
}
]
});

expect(CustomAttributeDefinition.formatter({
attributeType: 'BOOLEAN',
defaultValue: 'true'
})).toEqual({
attributeType: 'BOOLEAN',
defaultValueBoolean: true
});

expect(CustomAttributeDefinition.formatter({
attributeType: 'STRING',
defaultValue: 'true'
})).toEqual({
attributeType: 'STRING',
defaultValueString: 'true'
});
});
});

describe('parser', () => {

it('should parse the object provided to save to the server', () => {
expect(CustomAttributeDefinition.parser(null)).toBeNull();

expect(CustomAttributeDefinition.parser({
attributeType: 'SELECTION_LIST',
customAttrListDefinitions: [
{
default: true,
value: 'foo'
}
]
})).toEqual({
attributeType: 'SELECTION_LIST',
customAttrListDefinitions: [
'foo'
],
defaultValue: 'foo'
});

expect(CustomAttributeDefinition.parser({
attributeType: 'BOOLEAN',
defaultValueBoolean: true
})).toEqual({
attributeType: 'BOOLEAN',
defaultValue: true
});

expect(CustomAttributeDefinition.parser({
attributeType: 'STRING',
defaultValueString: 'true'
})).toEqual({
attributeType: 'STRING',
defaultValue: 'true'
});
});
});
19 changes: 19 additions & 0 deletions ui/src/app/metadata/domain/filter/BaseFilterDefinition.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BaseFilterDefinition } from "./BaseFilterDefinition";

describe('formatter', () => {
it('should return the provided object with no changes', () => {
expect(BaseFilterDefinition.formatter({})).toEqual({});
})
});

describe('parser', () => {
it('should return the provided object with no changes', () => {
expect(BaseFilterDefinition.parser({})).toEqual({});
})
});

describe('display', () => {
it('should return the provided object with no changes', () => {
expect(BaseFilterDefinition.display({})).toEqual({});
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export const EntityAttributesFilterWizard = {
warnings: (data) => {
let warnings = {};
if (!data?.relyingPartyOverrides?.signAssertion && data?.relyingPartyOverrides?.dontSignResponse) {
// ...(warnings.hasOwnProperty('options') ? warnings['options'] : []),
warnings = {
...warnings,
'options': [
...(warnings.hasOwnProperty('options') ? warnings['options'] : []),
'message.invalid-signing'
]
};
Expand All @@ -72,7 +72,7 @@ export const EntityAttributesFilterWizard = {
parser: (changes) => {
return {
...changes,
relyingPartyOverrides: removeNull(changes)
relyingPartyOverrides: removeNull(changes.relyingPartyOverrides)
};
},
formatter: (changes) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { EntityAttributesFilterWizard } from "./EntityAttributesFilterDefinition";
const addErrorMockFn = jest.fn();

const filters = [
{
resourceId: 1,
name: 'foo'
},
{
resourceId: 2,
name: 'baz'
}
];

const e = {
name: { addError: addErrorMockFn },
entityAttributesFilterTarget: {
addError: addErrorMockFn,
entityAttributesFilterTargetType: {
addError: addErrorMockFn
},
value: {
addError: addErrorMockFn
}
}
};

describe('validator function', () => {
it('should validate against the provider names', () => {
const validator = EntityAttributesFilterWizard.validator(filters, 2);
const errors = validator({
name: 'foo'
}, e);

expect(addErrorMockFn).toHaveBeenCalledTimes(1);
});

it('should validate against the provider names 2', () => {
const validator = EntityAttributesFilterWizard.validator(filters);
const errors = validator({
name: 'bar'
}, e);

expect(addErrorMockFn).toHaveBeenCalledTimes(0);
});

it('should validate the regex target', () => {
const validator = EntityAttributesFilterWizard.validator(filters, 2);
const errors = validator({
name: 'baz2',
entityAttributesFilterTarget: {
entityAttributesFilterTargetType: 'REGEX',
value: '()((*()*)(**'
}
}, e);

expect(addErrorMockFn).toHaveBeenCalledTimes(1);
});

it('should validate the regex target 2', () => {
const validator = EntityAttributesFilterWizard.validator(filters, 2);
const errors = validator({
name: 'baz2',
entityAttributesFilterTarget: {
entityAttributesFilterTargetType: 'REGEX',
value: 'test'
}
}, e);

expect(addErrorMockFn).toHaveBeenCalledTimes(0);
});
});

describe('formatter', () => {
it('should return the provided object with no changes', () => {
expect(EntityAttributesFilterWizard.formatter({})).toEqual({ '@type': 'EntityAttributes' });
})
});

describe('parser', () => {
it('should return the provided object with no changes', () => {
expect(EntityAttributesFilterWizard.parser({})).toEqual({
relyingPartyOverrides: {}
});

expect(EntityAttributesFilterWizard.parser({
relyingPartyOverrides: {
foo: null
}
})).toEqual({
relyingPartyOverrides: {}
});
})
});

describe('warnings', () => {
it('should return warnings based on provided data', () => {
expect(EntityAttributesFilterWizard.warnings({
relyingPartyOverrides: {
signAssertion: false,
dontSignResponse: true
}
})).toEqual({
'options': [
'message.invalid-signing'
]
});
})

it('should return no warnings', () => {
expect(EntityAttributesFilterWizard.warnings({
relyingPartyOverrides: {
signAssertion: true,
dontSignResponse: true
}
})).toEqual({});
})
});

describe('display', () => {
it('should return the provided object with no changes', () => {
expect(EntityAttributesFilterWizard.display({})).toEqual({});
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const NameIDFilterWizard = {
validator: (data = [], current = { resourceId: null }) => {

const filters = current ? data.filter(s => s.resourceId !== current.resourceId) : data;
const names = filters.map(s => s.entityId);
const names = filters.map(s => s.name);

return (formData, errors) => {
if (names.indexOf(formData.name) > -1) {
Expand Down
Loading

0 comments on commit 2e60252

Please sign in to comment.