mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #775 from omnivore-app/fix/delete-label
Fix failure of lable deletion in highlight
This commit is contained in:
commit
ff613287b4
5 changed files with 47 additions and 17 deletions
|
|
@ -31,3 +31,15 @@ export const initElasticsearch = async (): Promise<void> => {
|
|||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
export const refreshIndex = async (): Promise<void> => {
|
||||
try {
|
||||
const { body } = await client.indices.refresh({
|
||||
index: INDEX_ALIAS,
|
||||
})
|
||||
console.log('elastic refresh: ', body)
|
||||
} catch (e) {
|
||||
console.error('failed to refresh elastic index', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ export const deleteLabel = async (
|
|||
ctx: PageContext
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
console.log('deleting label', label)
|
||||
const { body } = await client.updateByQuery({
|
||||
index: INDEX_ALIAS,
|
||||
body: {
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export const deleteLabelResolver = authorized<
|
|||
}
|
||||
|
||||
// delete label in elastic pages and highlights
|
||||
await deleteLabel(labelId, {
|
||||
await deleteLabel(label.name, {
|
||||
pubsub: createPubSubClient(),
|
||||
uid,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -184,9 +184,9 @@ export const createTestLabel = async (
|
|||
color: string
|
||||
): Promise<Label> => {
|
||||
return getRepository(Label).save({
|
||||
user: user,
|
||||
name: name,
|
||||
color: color,
|
||||
user,
|
||||
name,
|
||||
color,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
addHighlightToPage,
|
||||
getHighlightById,
|
||||
} from '../../src/elastic/highlights'
|
||||
import { refreshIndex } from '../../src/elastic'
|
||||
|
||||
describe('Labels API', () => {
|
||||
const username = 'fakeUser'
|
||||
|
|
@ -219,34 +220,49 @@ describe('Labels API', () => {
|
|||
context('when label exists', () => {
|
||||
let toDeleteLabel: Label
|
||||
|
||||
before(async () => {
|
||||
toDeleteLabel = await createTestLabel(user, 'label4', '#ffffff')
|
||||
labelId = toDeleteLabel.id
|
||||
})
|
||||
context('when label is not used', () => {
|
||||
before(async () => {
|
||||
toDeleteLabel = await createTestLabel(
|
||||
user,
|
||||
'label not in use',
|
||||
'#ffffff'
|
||||
)
|
||||
labelId = toDeleteLabel.id
|
||||
})
|
||||
|
||||
it('should delete label', async () => {
|
||||
await graphqlRequest(query, authToken).expect(200)
|
||||
const label = await getRepository(Label).findOneBy({ id: labelId })
|
||||
expect(label).to.not.exist
|
||||
it('should delete label', async () => {
|
||||
await graphqlRequest(query, authToken).expect(200)
|
||||
const label = await getRepository(Label).findOneBy({ id: labelId })
|
||||
expect(label).not.exist
|
||||
})
|
||||
})
|
||||
|
||||
context('when a page has this label', () => {
|
||||
before(async () => {
|
||||
toDeleteLabel = await createTestLabel(user, 'page label', '#ffffff')
|
||||
labelId = toDeleteLabel.id
|
||||
await addLabelInPage(page.id, toDeleteLabel, ctx)
|
||||
})
|
||||
|
||||
it('should update page', async () => {
|
||||
await graphqlRequest(query, authToken).expect(200)
|
||||
const updatedPage = await getPageById(page.id)
|
||||
await refreshIndex()
|
||||
|
||||
expect(updatedPage?.labels).not.to.include(toDeleteLabel)
|
||||
const updatedPage = await getPageById(page.id)
|
||||
expect(updatedPage?.labels).not.deep.include(toDeleteLabel)
|
||||
})
|
||||
})
|
||||
|
||||
context('when a highlight has this label', () => {
|
||||
const highlightId = 'testDeleteLabel'
|
||||
const highlightId = generateFakeUuid()
|
||||
|
||||
before(async () => {
|
||||
toDeleteLabel = await createTestLabel(
|
||||
user,
|
||||
'highlight label',
|
||||
'#ffffff'
|
||||
)
|
||||
labelId = toDeleteLabel.id
|
||||
const highlight: Highlight = {
|
||||
id: highlightId,
|
||||
patch: 'test patch',
|
||||
|
|
@ -261,9 +277,10 @@ describe('Labels API', () => {
|
|||
|
||||
it('should update highlight', async () => {
|
||||
await graphqlRequest(query, authToken).expect(200)
|
||||
const updatedHighlight = await getHighlightById(highlightId)
|
||||
await refreshIndex()
|
||||
|
||||
expect(updatedHighlight?.labels).not.to.include(toDeleteLabel)
|
||||
const updatedHighlight = await getHighlightById(highlightId)
|
||||
expect(updatedHighlight?.labels).not.deep.include(toDeleteLabel)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue