Add test case for archives page and saves labels in savePage API

This commit is contained in:
Hongbo Wu 2023-03-06 11:48:06 +08:00
parent 87d3f5b3d8
commit ce273b5172
3 changed files with 38 additions and 2 deletions

View file

@ -64,6 +64,7 @@ export const createPageSaveRequest = async (
models: DataModels,
pubsub: PubsubClient = createPubSubClient(),
articleSavingRequestId = uuidv4(),
archivedAt?: Date | null,
priority?: 'low' | 'high'
): Promise<ArticleSavingRequest> => {
try {
@ -116,6 +117,7 @@ export const createPageSaveRequest = async (
state: ArticleSavingRequestStatus.Processing,
createdAt: new Date(),
savedAt: new Date(),
archivedAt,
}
// create processing page

View file

@ -140,7 +140,8 @@ export const savePage = async (
articleToSave.url,
ctx.models,
ctx.pubsub,
input.clientRequestId
input.clientRequestId,
archivedAt
)
} catch (e) {
return {

View file

@ -10,6 +10,7 @@ import {
deletePage,
deletePagesByParam,
getPageById,
getPageByParam,
updatePage,
} from '../../src/elastic/pages'
import {
@ -208,7 +209,13 @@ const searchQuery = (keyword = '') => {
`
}
const savePageQuery = (url: string, title: string, originalContent: string) => {
const savePageQuery = (
url: string,
title: string,
originalContent: string,
state: ArticleSavingRequestStatus | null = null,
labels: string[] | null = null
) => {
return `
mutation {
savePage(
@ -218,6 +225,12 @@ const savePageQuery = (url: string, title: string, originalContent: string) => {
clientRequestId: "${generateFakeUuid()}",
title: "${title}",
originalContent: "${originalContent}"
state: ${state}
labels: ${
labels
? '[' + labels.map((label) => `{ name: "${label}" }`) + ']'
: null
}
}
) {
... on SaveSuccess {
@ -611,6 +624,26 @@ describe('Article API', () => {
expect(allLinks.body.data.articles.edges[0].node.url).to.eq(url)
})
})
context('when we also want to save labels and archives the page', () => {
after(async () => {
await deletePagesByParam({ url }, ctx)
})
it('saves the labels and archives the page', async () => {
const state = ArticleSavingRequestStatus.Archived
const labels = ['test name', 'test name 2']
await graphqlRequest(
savePageQuery(url, title, originalContent, state, labels),
authToken
).expect(200)
await refreshIndex()
const savedPage = await getPageByParam({ url })
expect(savedPage?.archivedAt).to.not.be.null
expect(savedPage?.labels?.map((l) => l.name)).to.eql(labels)
})
})
})
describe('SaveUrl', () => {