From 11cedcce6e115a977ca3bb5e724f15ad18e43da2 Mon Sep 17 00:00:00 2001 From: lilia Date: Sat, 5 Dec 2015 19:23:10 -0800 Subject: [PATCH] Add model-level search tests // FREEBIE --- test/models/conversations_test.js | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/models/conversations_test.js b/test/models/conversations_test.js index 4e130f6f..a54e0c6b 100644 --- a/test/models/conversations_test.js +++ b/test/models/conversations_test.js @@ -190,6 +190,43 @@ }); }); + describe('Conversation search', function() { + var convo = new Whisper.ConversationCollection().add({ + id: '+14155555555', type: 'private', name: 'John Doe' + }); + before(function(done) { convo.save().then(done); }); + function testSearch(queries, done) { + return Promise.all(queries.map(function(query) { + var collection = new Whisper.ConversationCollection(); + return collection.search(query).then(function() { + assert.isDefined(collection.get(convo.id), 'no result for "' + query + '"'); + }).catch(done); + })).then(function() { + done(); + }); + } + it('matches by partial phone number', function(done) { + testSearch([ + '1', + '4', + '+1', + '415', + '4155', + '4155555555', + '14155555555', + '+14155555555', + ], done); + }); + it('matches by name', function(done) { + testSearch([ 'John', 'Doe', 'john', 'doe', 'John Doe', 'john doe' ], done); + }); + it('does not match +', function(done) { + var collection = new Whisper.ConversationCollection(); + return collection.search('+').then(function() { + assert.isUndefined(collection.get(convo.id), 'got result for "+"'); + done(); + }).catch(done); + }); }); })();;