diff --git a/test/search.js b/test/search.js index f0e285cb9d..7a6db73d1d 100644 --- a/test/search.js +++ b/test/search.js @@ -11,6 +11,7 @@ const user = require('../src/user'); const search = require('../src/search'); const privileges = require('../src/privileges'); const request = require('../src/request'); +const posts = require('../src/posts'); describe('Search', () => { let phoebeUid; @@ -136,6 +137,48 @@ describe('Search', () => { assert.strictEqual(data.length, 5); }); + it('should search in bookmarks', async () => { + posts.bookmark(post1Data.pid, gingerUid); + const result = await search.search({ + searchIn: 'bookmarks', + uid: gingerUid, + categories: ['all'], + }); + assert.strictEqual(result.matchCount, 1); + assert.strictEqual(result.posts[0].pid, post1Data.pid); + }); + + it('should not find any bookmark', async () => { + const result = await search.search({ + searchIn: 'bookmarks', + uid: phoebeUid, + categories: ['all'], + }); + assert.strictEqual(result.matchCount, 0); + }); + + it('should search bookmark by query', async () => { + posts.bookmark(post1Data.pid, gingerUid); + let result = await search.search({ + query: 'nodebb', + searchIn: 'bookmarks', + uid: gingerUid, + categories: ['all'], + matchWords: 'any', + }); + assert.strictEqual(result.matchCount, 1); + assert.strictEqual(result.posts[0].pid, post1Data.pid); + + result = await search.search({ + query: 'xxxx', + searchIn: 'bookmarks', + uid: gingerUid, + categories: ['all'], + matchWords: 'any', + }); + assert.strictEqual(result.matchCount, 0); + }); + it('should fail if searchIn is wrong', (done) => { search.search({ query: 'plug',