Skip to content

Commit 4f2c0d6

Browse files
Add tests for pattern matching operators
1 parent 7c72725 commit 4f2c0d6

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
@@ -215,6 +215,121 @@ describe('postgresql connector', function() {
215215
});
216216
});
217217

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

0 commit comments

Comments
 (0)