Skip to content

Commit

Permalink
fix: support additional values for Connector.isNullable
Browse files Browse the repository at this point in the history
Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
  • Loading branch information
achrinza committed Aug 22, 2022
1 parent b87431f commit 0326b75
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,15 @@ Connector.prototype.isNullable = function(prop) {
if (prop.required || prop.id) {
return false;
}
if (prop.nullable || prop['null'] || prop.allowNull) {
return true;
}
if (prop.nullable === false || prop['null'] === false ||
prop.allowNull === false) {
return false;

const nullableFlagsValue = [prop.nullable, prop['null'], prop.allowNull];
const notNullableValues = [0, 'N', 'NO', false];

for (const flagValue of nullableFlagsValue) {
if (notNullableValues.includes(flagValue))
return false;
}

return true;
};

Expand Down
42 changes: 42 additions & 0 deletions test/connector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,46 @@ describe('Connector', () => {
expect(definition).to.be.undefined;
});
});

describe('isNullable()', () => {
const nullableFlags = [
'nullable',
'null',
'allowNull',
];

const nullableValues = [
1,
'Y',
'YES',
true,
];

const notNullableValues = [
0,
'N',
'NO',
false,
];

for (const nullableFlag of nullableFlags) {
for (const nullableValue of nullableValues) {
it(`returns \`true\` for \`${nullableFlag}: ${nullableValue}\``, () => {
const propDefNullableSlice = {[nullableFlag]: nullableValue};
const result = Connector.prototype.isNullable(propDefNullableSlice);
// eslint-disable-next-line no-unused-expressions
expect(result).to.be.true;
});
}

for (const notNullableValue of notNullableValues) {
it(`returns \`false\` for \`${nullableFlag}: ${notNullableValue}\``, () => {
const propDefNotNullableSlice = {[nullableFlag]: notNullableValue};
const result = Connector.prototype.isNullable(propDefNotNullableSlice);
// eslint-disable-next-line no-unused-expressions
expect(result).to.be.false;
});
}
}
});
});

0 comments on commit 0326b75

Please sign in to comment.