From eb1d8caa1c57c2f860d3d28d26f5740e7a142ac6 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 17 Feb 2023 18:03:53 +0800 Subject: [PATCH] Add tests --- packages/api/test/resolvers/article.test.ts | 34 ++++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/api/test/resolvers/article.test.ts b/packages/api/test/resolvers/article.test.ts index 77fd10fad..a7c3caff2 100644 --- a/packages/api/test/resolvers/article.test.ts +++ b/packages/api/test/resolvers/article.test.ts @@ -810,7 +810,7 @@ describe('Article API', () => { userId: user.id, pageType: PageType.Article, title: 'test title', - content: '

search page

', + content: '

test search api

', slug: 'test slug', createdAt: new Date(), updatedAt: new Date(), @@ -849,7 +849,7 @@ describe('Article API', () => { context('when we search for a keyword', () => { before(() => { - keyword = 'search' + keyword = 'search api' }) it('saves the term in search history', async () => { @@ -875,7 +875,7 @@ describe('Article API', () => { context('when type:highlights is not in the query', () => { before(() => { - keyword = 'search' + keyword = 'search api' }) it('should return pages in descending order', async () => { @@ -901,7 +901,7 @@ describe('Article API', () => { context('when type:highlights is in the query', () => { before(() => { - keyword = 'search type:highlights' + keyword = "'search api' type:highlights" }) it('should return highlights in descending order', async () => { @@ -918,7 +918,7 @@ describe('Article API', () => { context('when is:unread is in the query', () => { before(() => { - keyword = 'search is:unread' + keyword = "'search api' is:unread" }) it('should return unread articles in descending order', async () => { @@ -932,6 +932,30 @@ describe('Article API', () => { expect(res.body.data.search.edges[4].node.id).to.eq(pages[0].id) }) }) + + context('when no:label is in the query', () => { + before(async () => { + keyword = "'search api' no:label" + }) + + it('returns non-labeled items in descending order', async () => { + const res = await graphqlRequest(query, authToken).expect(200) + + expect(res.body.data.search.pageInfo.totalCount).to.eq(5) + }) + }) + + context('when no:highlight is in the query', () => { + before(async () => { + keyword = "'search api' no:highlight" + }) + + it('returns non-highlighted items in descending order', async () => { + const res = await graphqlRequest(query, authToken).expect(200) + + expect(res.body.data.search.pageInfo.totalCount).to.eq(0) + }) + }) }) describe('TypeaheadSearch API', () => {