Skip to content

Commit 3cb3fa1

Browse files
Add tests for pattern matching operators
1 parent 7346acd commit 3cb3fa1

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

test/postgresql.test.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,121 @@ describe('postgresql connector', function() {
230230
});
231231
});
232232

233+
context('pattern matching operators', function() {
234+
before(function deleteTestFixtures(done) {
235+
Post.destroyAll(done);
236+
});
237+
before(function createTextFixtures(done) {
238+
Post.create([{
239+
title: 't1',
240+
content: 'T1_TestCase',
241+
}, {
242+
title: 't2',
243+
content: 'T2_TheOtherCase',
244+
}], done);
245+
});
246+
after(function deleteTestFixtures(done) {
247+
Post.destroyAll(done);
248+
});
249+
250+
it('should support case sensitive queries using like',
251+
function(done) {
252+
Post.find({where: {content: {like: '%TestCase%'}}},
253+
function(err, posts) {
254+
should.not.exists(err);
255+
posts.length.should.equal(1);
256+
posts[0].content.should.equal('T1_TestCase');
257+
done();
258+
});
259+
});
260+
261+
it('should not support case insensitive queries using like',
262+
function(done) {
263+
Post.find({where: {content: {like: '%tesTcasE%'}}},
264+
function(err, posts) {
265+
should.not.exists(err);
266+
posts.length.should.equal(0);
267+
done();
268+
});
269+
});
270+
271+
it('should support like for no match', function(done) {
272+
Post.find({where: {content: {like: '%TestXase%'}}},
273+
function(err, posts) {
274+
should.not.exists(err);
275+
posts.length.should.equal(0);
276+
done();
277+
});
278+
});
279+
280+
it('should support negative case sensitive queries using nlike',
281+
function(done) {
282+
Post.find({where: {content: {nlike: '%Case%'}}},
283+
function(err, posts) {
284+
should.not.exists(err);
285+
posts.length.should.equal(0);
286+
done();
287+
});
288+
});
289+
290+
it('should not support negative case insensitive queries using nlike',
291+
function(done) {
292+
Post.find({where: {content: {nlike: '%casE%'}}},
293+
function(err, posts) {
294+
should.not.exists(err);
295+
posts.length.should.equal(2);
296+
done();
297+
});
298+
});
299+
300+
it('should support nlike for no match', function(done) {
301+
Post.find({where: {content: {nlike: '%TestXase%'}}},
302+
function(err, posts) {
303+
should.not.exists(err);
304+
posts.length.should.equal(2);
305+
done();
306+
});
307+
});
308+
309+
it('should support case insensitive queries using ilike', function(done) {
310+
Post.find({where: {content: {ilike: '%tesTcasE%'}}},
311+
function(err, posts) {
312+
should.not.exist(err);
313+
posts.length.should.equal(1);
314+
posts[0].content.should.equal('T1_TestCase');
315+
done();
316+
});
317+
});
318+
319+
it('should support ilike for no match', function(done) {
320+
Post.find({where: {content: {ilike: '%tesTxasE%'}}},
321+
function(err, posts) {
322+
should.not.exists(err);
323+
posts.length.should.equal(0);
324+
done();
325+
});
326+
});
327+
328+
it('should support negative case insensitive queries using nilike',
329+
function(done) {
330+
Post.find({where: {content: {nilike: '%casE%'}}},
331+
function(err, posts) {
332+
should.not.exist(err);
333+
posts.length.should.equal(0);
334+
done();
335+
});
336+
});
337+
338+
it('should support nilike for no match', function(done) {
339+
Post.find({where: {content: {nilike: '%tesTxasE%'}}},
340+
function(err, posts) {
341+
should.not.exists(err);
342+
posts.length.should.equal(2);
343+
done();
344+
});
345+
});
346+
});
347+
233348
context('regexp operator', function() {
234349
before(function deleteTestFixtures(done) {
235350
Post.destroyAll(done);

0 commit comments

Comments
 (0)