Skip to content

Commit 611f1c5

Browse files
committed
test(query): add tests for between query handling
1 parent e0c249e commit 611f1c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/query.tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,27 @@ describe('query test case', () => {
322322
expect(res.sql).to.be.equal('UPDATE `test` SET `number` = `number` + ? WHERE `id` = ?');
323323
expect(JSON.stringify(res.values)).to.be.equal('[0,1]');
324324
});
325+
326+
it('between query should be ok', async () => {
327+
const handle = new QueryHandler();
328+
let res = await handle.table('test').where('id', 1)
329+
.where('company_id', 1)
330+
.where('type', 'company')
331+
.where('disabled', 0)
332+
.whereBetween('time_end', ['2024-12-09 00:00:00', '2024-12-15 23:59:59'])
333+
.notExec()
334+
.select();
335+
expect(res.sql).to.be.equal('SELECT * FROM `test` WHERE `id` = ? AND `company_id` = ? AND `type` = ? AND `disabled` = ? AND `time_end` BETWEEN ? AND ?');
336+
expect(JSON.stringify(res.values)).to.be.equal('[1,1,"company",0,"2024-12-09 00:00:00","2024-12-15 23:59:59"]');
337+
338+
res = await handle.table('test').where('id', 1)
339+
.where('company_id', 1)
340+
.where('type', 'company')
341+
.where('disabled', 0)
342+
.whereBetween('json->$.time_end', ['2024-12-09 00:00:00', '2024-12-15 23:59:59'])
343+
.notExec()
344+
.select();
345+
expect(res.sql).to.be.equal('SELECT * FROM `test` WHERE `id` = ? AND `company_id` = ? AND `type` = ? AND `disabled` = ? AND JSON_EXTRACT(`json`, \'$.time_end\') BETWEEN ? AND ?');
346+
expect(JSON.stringify(res.values)).to.be.equal('[1,1,"company",0,"2024-12-09 00:00:00","2024-12-15 23:59:59"]');
347+
});
325348
});

0 commit comments

Comments
 (0)