Skip to content

Commit

Permalink
Merge pull request #193 from synatic/feat/noql-fix
Browse files Browse the repository at this point in the history
Adding test case from QA to verify that results will be returned
  • Loading branch information
eXigentCoder authored Aug 29, 2024
2 parents 616ef5f + e1d044a commit 60e1525
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 181 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synatic/noql",
"version": "4.1.4",
"version": "4.1.5",
"description": "Convert SQL statements to mongo queries or aggregates",
"main": "index.js",
"files": [
Expand Down
34 changes: 33 additions & 1 deletion test/bug-fix-tests/bug-fix.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const {setup, disconnect} = require('../utils/mongo-client.js');
const {buildQueryResultTester} = require('../utils/query-tester/index.js');
const {getAllSchemas} = require('../utils/get-all-schemas.js');

const {parseSQLtoAST, makeMongoAggregate} = require('../../lib/SQLParser');
const fs = require('fs/promises');
const emptyResultsBugPipeline = require('./empty-results-pipeline.json');
const isEqual = require('lodash/isEqual');
const assert = require('node:assert');
describe('bug-fixes', function () {
this.timeout(90000);
const fileName = 'bug-fix';
Expand Down Expand Up @@ -1020,4 +1024,32 @@ describe('bug-fixes', function () {
});
});
});
describe('empty-results', () => {
it("should work with Avi's example", async () => {
const queryString = `
SELECT bp.CustId,
bp.PolId,
bp.PolNo,
bp.PolEffDate,
bp.PolExpDate,
lob.LineOfBus
FROM \`faizel-polinfo\` bp
INNER JOIN (
SELECT PolId,
LineOfBus
--,EffDate
FROM \`faizel-lob\`) \`lob|optimize\`
ON lob.PolId = bp.PolId
AND lob.EffDate >= bp.PolEffDate
WHERE bp.Status != 'D'
--AND lob.LineOfBus IN ('CGL','WORK','AUTOB', 'CUMBR','ELIAB', 'XLIB','INMRC', 'PROP', 'BOPGL', 'CFIRE', 'EMP LIAB OH', 'EPLI', 'MTRTK', 'PL', 'RFRBR', 'POLL' )
AND TO_DATE(bp.PolExpDate) > CURRENT_DATE()
AND bp.PolSubType != 'S'
AND bp.CustId = 'test-customer-1'
LIMIT 10 `;
const aggregate = makeMongoAggregate(queryString);

assert.ok(isEqual(aggregate.pipeline, emptyResultsBugPipeline));
});
});
});
103 changes: 103 additions & 0 deletions test/bug-fix-tests/empty-results-pipeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[
{
"$project": {
"bp": "$$ROOT"
}
},
{
"$lookup": {
"from": "faizel-lob",
"as": "lob",
"let": {
"bp_PolId": "$bp.PolId",
"bp_PolEffDate": "$bp.PolEffDate"
},
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{
"$eq": ["$PolId", "$$bp_PolId"]
},
{
"$gte": ["$EffDate", "$$bp_PolEffDate"]
}
]
}
}
},
{
"$project": {
"PolId": "$PolId",
"LineOfBus": "$LineOfBus"
}
}
]
}
},
{
"$match": {
"$expr": {
"$gt": [
{
"$size": "$lob"
},
0
]
}
}
},
{
"$match": {
"$and": [
{
"$and": [
{
"$and": [
{
"bp.Status": {
"$ne": "D"
}
},
{
"$expr": {
"$gt": [
{
"$toDate": "$bp.PolExpDate"
},
"$$NOW"
]
}
}
]
},
{
"bp.PolSubType": {
"$ne": "S"
}
}
]
},
{
"bp.CustId": {
"$eq": "test-customer-1"
}
}
]
}
},
{
"$project": {
"CustId": "$bp.CustId",
"PolId": "$bp.PolId",
"PolNo": "$bp.PolNo",
"PolEffDate": "$bp.PolEffDate",
"PolExpDate": "$bp.PolExpDate",
"LineOfBus": "$lob.LineOfBus"
}
},
{
"$limit": 10
}
]
179 changes: 0 additions & 179 deletions test/bug-fix-tests/expected-pipeline.json

This file was deleted.

0 comments on commit 60e1525

Please sign in to comment.