163 lines
4.0 KiB
JavaScript
163 lines
4.0 KiB
JavaScript
import {describe, it} from 'mocha';
|
|
import {expect} from 'chai';
|
|
|
|
export const checkFieldConstraintSize = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
limit,
|
|
expectedValue = '',
|
|
expectedError,
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should be able to read from ${fieldName}`, () => {
|
|
expect(eval(`${fieldName}`)).to.equal(expectedValue);
|
|
});
|
|
|
|
it(`Should be able to write upto ${limit} characters to ${fieldName}`,
|
|
() => {
|
|
expect(() => eval(`${fieldName} = 'x'.repeat(${limit})`)).
|
|
to.not.throw();
|
|
});
|
|
|
|
it(`Should fail to write more than ${limit} characters to ${fieldName}`,
|
|
() => {
|
|
expect(() => eval(`${fieldName} = 'x'.repeat(${limit + 1})`)).
|
|
to.throw(expectedError + '');
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkInvalidSet = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
expectedValue = '',
|
|
expectedError,
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should be able to read from ${fieldName}`, () => {
|
|
expect(eval(`${fieldName}`)).to.equal(expectedValue);
|
|
});
|
|
|
|
it(`Should fail to write to ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName} = 'xxx'`)).
|
|
to.throw(expectedError + '');
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkReadOnly = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
expectedValue = '',
|
|
expectedError,
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should be able to read from ${fieldName}`, () => {
|
|
expect(eval(`${fieldName}`)).to.equal(expectedValue);
|
|
});
|
|
|
|
it(`Should fail to write to ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName} = 'xxx'`)).
|
|
to.throw(expectedError + '');
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkRead = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
expectedValue = '',
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should be able to read from ${fieldName}`, () => {
|
|
expect(eval(`${fieldName}`)).to.equal(expectedValue);
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkReadAndWrite = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
expectedValue = '',
|
|
valueToTest = 'xxx',
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should be able to read from ${fieldName}`, () => {
|
|
expect(eval(`${fieldName}`)).to.equal(expectedValue);
|
|
});
|
|
|
|
it(`Should successfully write to ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName} = '${valueToTest}'`)).
|
|
to.not.throw();
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkWriteOnly = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
valueToTest = 'xxx',
|
|
expectedError,
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should fail to read from ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName}`)).
|
|
to.throw(expectedError + '');
|
|
});
|
|
|
|
it(`Should successfully write to ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName} = '${valueToTest}'`)).to.not.throw();
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkWrite = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
valueToTest = 'xxx',
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
it(`Should successfully write to ${fieldName}`, () => {
|
|
expect(() => eval(`${fieldName} = '${valueToTest}'`)).to.not.throw();
|
|
});
|
|
});
|
|
};
|
|
|
|
export const checkValidValues = (
|
|
{
|
|
cmi,
|
|
fieldName,
|
|
expectedError,
|
|
validValues,
|
|
invalidValues,
|
|
}) => {
|
|
describe(`Field: ${fieldName}`, () => {
|
|
for (const idx in validValues) {
|
|
if ({}.hasOwnProperty.call(validValues, idx)) {
|
|
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`,
|
|
() => {
|
|
expect(() => eval(`${fieldName} = '${validValues[idx]}'`)).
|
|
to.not.throw();
|
|
});
|
|
}
|
|
}
|
|
|
|
for (const idx in invalidValues) {
|
|
if ({}.hasOwnProperty.call(invalidValues, idx)) {
|
|
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`,
|
|
() => {
|
|
expect(() => eval(`${fieldName} = '${invalidValues[idx]}'`)).
|
|
to.throw(expectedError + '');
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|