Add test case for deleteLabel

This commit is contained in:
Hongbo Wu 2022-06-08 17:01:38 +08:00
parent 0d67d0fb90
commit a981e13c86
2 changed files with 29 additions and 2 deletions

View file

@ -286,7 +286,7 @@ export const deleteLabelForHighlights = async (
path: 'highlights',
query: {
nested: {
path: 'labels',
path: 'highlights.labels',
query: {
term: {
'highlights.labels.name': label,

View file

@ -14,7 +14,10 @@ import { getRepository } from '../../src/entity/utils'
import { getPageById } from '../../src/elastic/pages'
import { addLabelInPage } from '../../src/elastic/labels'
import { createPubSubClient } from '../../src/datalayer/pubsub'
import { addHighlightToPage } from '../../src/elastic/highlights'
import {
addHighlightToPage,
getHighlightById,
} from '../../src/elastic/highlights'
describe('Labels API', () => {
const username = 'fakeUser'
@ -239,6 +242,30 @@ describe('Labels API', () => {
expect(updatedPage?.labels).not.to.include(toDeleteLabel)
})
})
context('when a highlight has this label', () => {
const highlightId = 'testDeleteLabel'
before(async () => {
const highlight: Highlight = {
id: highlightId,
patch: 'test patch',
quote: 'test quote',
shortId: 'test shortId',
userId: user.id,
createdAt: new Date(),
labels: [toDeleteLabel],
}
await addHighlightToPage(page.id, highlight, ctx)
})
it('should update highlight', async () => {
await graphqlRequest(query, authToken).expect(200)
const updatedHighlight = await getHighlightById(highlightId)
expect(updatedHighlight?.labels).not.to.include(toDeleteLabel)
})
})
})
context('when label not exist', () => {