Skip to content

Commit 77041f3

Browse files
committed
feat(cli): remove integration test
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
1 parent 33b664d commit 77041f3

2 files changed

Lines changed: 51 additions & 28 deletions

File tree

‎lib/postgresql.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,17 +601,13 @@ PostgreSQL.prototype.buildExpression = function(columnName, operator,
601601
const postgresTypeMap = new Map([
602602
[Number, 'INTEGER'],
603603
[String, 'TEXT'],
604-
[Boolean, 'BOOLEAN'],
605604
]);
606-
607605
const arrayItemType = postgresTypeMap.get(itemType);
608606

609607
if (!arrayItemType) {
610-
throw new Error(`Unsupported array item type: ${itemType.name}`);
608+
throw new Error(`Unsupported array item type: ${itemType ? itemType.name : 'unknown'}`);
611609
}
612-
613-
const isArray =
614-
propertyDefinition.postgresql.dataType === 'ARRAY';
610+
const isArray = propertyDefinition.postgresql.dataType === 'ARRAY';
615611
const conditions = [];
616612
const params = [];
617613

‎test/postgresql.test.js‎

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -985,53 +985,80 @@ describe('postgresql connector', function() {
985985
});
986986

987987
context('jsonContains operator', function() {
988-
let Item;
988+
let ItemWithJson, ItemWithIntegerArray, ItemWithStringArray;
989989

990990
before(function(done) {
991991
db = global.getDataSource();
992992
// Define a test model utilizing a jsonb column type to test JSON containment filters.
993-
Item = db.define('ItemWithJson', {
993+
ItemWithJson = db.define('ItemWithJson', {
994994
name: {type: String},
995995
tags: {
996-
type: 'object',
996+
type: [String],
997+
postgresql: {
998+
dataType: 'jsonb',
999+
},
1000+
},
1001+
});
1002+
ItemWithIntegerArray = db.define('ItemWithIntegerArray', {
1003+
name: {type: String},
1004+
tags: {
1005+
type: [Number],
1006+
postgresql: {
1007+
dataType: 'jsonb',
1008+
},
1009+
},
1010+
});
1011+
ItemWithStringArray = db.define('ItemWithStringArray', {
1012+
name: {type: String},
1013+
tags: {
1014+
type: [String],
9971015
postgresql: {
9981016
dataType: 'jsonb',
9991017
},
10001018
},
10011019
});
1002-
db.automigrate(['ItemWithJson'], done);
1020+
db.automigrate(['ItemWithJson', 'ItemWithIntegerArray', 'ItemWithStringArray'], done);
10031021
});
10041022

10051023
beforeEach(function(done) {
1006-
Item.destroyAll(done);
1024+
ItemWithJson.destroyAll();
1025+
ItemWithIntegerArray.destroyAll();
1026+
ItemWithStringArray.destroyAll(done);
10071027
});
10081028

10091029
after(function(done) {
1010-
Item.destroyAll(done);
1030+
ItemWithJson.destroyAll();
1031+
ItemWithIntegerArray.destroyAll();
1032+
ItemWithStringArray.destroyAll(done);
10111033
});
10121034

1013-
it('should find records matching jsonContains filter', async () => {
1014-
// Seed test records to verify multi-value containment matching.
1015-
await Item.createAll([
1016-
{name: 'Item A', tags: ['foo', 'bar']},
1017-
{name: 'Item B', tags: ['baz']},
1018-
]);
1035+
it('should support unit-level SQL building verification for jsonContains', function() {
1036+
const where = db.connector.buildWhere(
1037+
'ItemWithJson',
1038+
{tags: {jsonContains: ['bar', 'foo']}},
1039+
);
10191040

1020-
// Execute find query using the mapped jsonContains operator.
1021-
const found = await Item.find({
1022-
where: {
1023-
tags: {jsonContains: ['bar', 'foo']},
1024-
},
1041+
where.toJSON().should.eql({
1042+
sql: 'WHERE ("tags" @> CAST(? AS JSONB) OR "tags" @> CAST(? AS JSONB))',
1043+
params: ['["bar"]', '["foo"]'],
10251044
});
1045+
});
10261046

1027-
found.should.have.property('length', 1);
1028-
found[0].name.should.equal('Item A');
1047+
it('should support unit-level SQL building verification for jsonContains with integer array', function() {
1048+
const where = db.connector.buildWhere(
1049+
'ItemWithIntegerArray',
1050+
{tags: {jsonContains: [1, 2]}},
1051+
);
1052+
1053+
where.toJSON().should.eql({
1054+
sql: 'WHERE ("tags" @> CAST(? AS JSONB) OR "tags" @> CAST(? AS JSONB))',
1055+
params: ['[1]', '[2]'],
1056+
});
10291057
});
10301058

1031-
it('should support unit-level SQL building verification for jsonContains', function() {
1032-
// Verify that buildWhere constructs the exact PostgreSQL-native JSONB containment syntax and parameters.
1059+
it('should support unit-level SQL building verification for jsonContains with string array', function() {
10331060
const where = db.connector.buildWhere(
1034-
'ItemWithJson',
1061+
'ItemWithStringArray',
10351062
{tags: {jsonContains: ['bar', 'foo']}},
10361063
);
10371064

0 commit comments

Comments
 (0)