* Add state and taskName in elastic page mappings * Add state and taskName in elastic page interface * Create page with PROCESSING state before scrapping * Update createArticleRequest API * Fix tests * Add default state for pages * Update createArticle API * Update save page * Update save file * Update saving item description * Show unable to parse content for failed page * Fix date parsing * Search for not failed pages * Fix tests * Add test for saveUrl * Update get article saving request api * Update get article test * Add test for articleSavingRequest API * Add test for failure * Return new page id if clientRequestId empty * Update clientRequestId in savePage * Update clientRequestId in saveFile * Replace article with slug in articleSavingRequest * Add slug in articleSavingRequest response * Depreciate article * Use slug in web * Remove article and highlight fragments * Query article.slug on Prod * Show unable to parse description for failed page * Fix a bug having duplicate pages when saving the same url multiple times * Add state in response * Rename variables in removeArticle API * Rename state * Add state in response in web * Make state an enum * Open temporary page by link id * Use an empty reader view as the background for loading pages * Progressively load the article page as content is loaded * Add includePending flag in getArticles API * Set includePending = true in web * Add elastic update mappings in migration script * Add elastic mappings in docker image * Move index_settings.json to migrate package * Remove elastic index creation in api * Move elastic migrations to a separate directory * Remove index_settings from api docker image Co-authored-by: Jackson Harper <jacksonh@gmail.com>
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { createApp } from '../src/server'
|
|
import supertest from 'supertest'
|
|
import { v4 } from 'uuid'
|
|
import { corsConfig } from '../src/utils/corsConfig'
|
|
import { ArticleSavingRequestStatus, Page } from '../src/elastic/types'
|
|
import { PageType } from '../src/generated/graphql'
|
|
import { User } from '../src/entity/user'
|
|
import { Label } from '../src/entity/label'
|
|
import { createPubSubClient } from '../src/datalayer/pubsub'
|
|
import { createPage, getPageById } from '../src/elastic/pages'
|
|
|
|
const { app, apollo } = createApp()
|
|
export const request = supertest(app)
|
|
|
|
export const startApolloServer = async () => {
|
|
await apollo.start()
|
|
apollo.applyMiddleware({ app, path: '/api/graphql', cors: corsConfig })
|
|
}
|
|
|
|
export const stopApolloServer = async () => {
|
|
await apollo.stop()
|
|
}
|
|
|
|
export const graphqlRequest = (
|
|
query: string,
|
|
authToken?: string
|
|
): supertest.Test => {
|
|
return request
|
|
.post(apollo.graphqlPath)
|
|
.send({
|
|
query,
|
|
})
|
|
.set('Accept', 'application/json')
|
|
.set('authorization', authToken || '')
|
|
.expect('Content-Type', /json/)
|
|
}
|
|
|
|
export const generateFakeUuid = () => {
|
|
return v4()
|
|
}
|
|
|
|
export const createTestElasticPage = async (
|
|
user: User,
|
|
labels?: Label[]
|
|
): Promise<Page> => {
|
|
const page: Page = {
|
|
id: '',
|
|
hash: 'test hash',
|
|
userId: user.id,
|
|
pageType: PageType.Article,
|
|
title: 'test title',
|
|
content: '<p>test content</p>',
|
|
createdAt: new Date(),
|
|
url: 'https://example.com/test-url',
|
|
slug: 'test-with-omnivore',
|
|
labels: labels,
|
|
readingProgressPercent: 0,
|
|
readingProgressAnchorIndex: 0,
|
|
state: ArticleSavingRequestStatus.Succeeded,
|
|
}
|
|
|
|
const pageId = await createPage(page, {
|
|
pubsub: createPubSubClient(),
|
|
refresh: true,
|
|
uid: user.id,
|
|
})
|
|
if (pageId) {
|
|
page.id = pageId
|
|
}
|
|
|
|
const res = await getPageById(page.id)
|
|
console.log('got page', res)
|
|
if (!res) {
|
|
throw new Error('Failed to create page')
|
|
}
|
|
return res
|
|
}
|