feat: update api to include preview image
This commit is contained in:
@ -2874,6 +2874,7 @@ export type UpdatePageInput = {
|
||||
byline?: InputMaybe<Scalars['String']>;
|
||||
description?: InputMaybe<Scalars['String']>;
|
||||
pageId: Scalars['ID'];
|
||||
previewImage?: InputMaybe<Scalars['String']>;
|
||||
publishedAt?: InputMaybe<Scalars['Date']>;
|
||||
savedAt?: InputMaybe<Scalars['Date']>;
|
||||
title?: InputMaybe<Scalars['String']>;
|
||||
|
||||
@ -2219,6 +2219,7 @@ input UpdatePageInput {
|
||||
byline: String
|
||||
description: String
|
||||
pageId: ID!
|
||||
previewImage: String
|
||||
publishedAt: Date
|
||||
savedAt: Date
|
||||
title: String
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { getPageById, updatePage } from '../../elastic/pages'
|
||||
import { Page } from '../../elastic/types'
|
||||
import {
|
||||
MutationUpdatePageArgs,
|
||||
UpdatePageError,
|
||||
UpdatePageErrorCode,
|
||||
UpdatePageSuccess,
|
||||
} from '../../generated/graphql'
|
||||
import { authorized, userDataToUser } from '../../utils/helpers'
|
||||
import { getPageById, updatePage } from '../../elastic/pages'
|
||||
import { Page } from '../../entity/page'
|
||||
import { Merge } from '../../util'
|
||||
import { authorized, userDataToUser } from '../../utils/helpers'
|
||||
|
||||
export type UpdatePageSuccessPartial = Merge<
|
||||
UpdatePageSuccess,
|
||||
@ -42,6 +42,7 @@ export const updatePageResolver = authorized<
|
||||
author: input.byline ?? undefined,
|
||||
savedAt: input.savedAt ? new Date(input.savedAt) : undefined,
|
||||
publishedAt: input.publishedAt ? new Date(input.publishedAt) : undefined,
|
||||
image: input.previewImage ?? undefined,
|
||||
}
|
||||
|
||||
const updateResult = await updatePage(input.pageId, pageData, { ...ctx, uid })
|
||||
|
||||
@ -580,6 +580,7 @@ const schema = gql`
|
||||
byline: String
|
||||
savedAt: Date
|
||||
publishedAt: Date
|
||||
previewImage: String @sanitize
|
||||
}
|
||||
|
||||
type UpdatePageSuccess {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { createTestUser, deleteTestUser } from '../db'
|
||||
import { createTestElasticPage, graphqlRequest, request } from '../util'
|
||||
import { expect } from 'chai'
|
||||
import 'mocha'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { Page } from '../../src/elastic/types'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { createTestUser, deleteTestUser } from '../db'
|
||||
import { createTestElasticPage, graphqlRequest, request } from '../util'
|
||||
|
||||
describe('Update API', () => {
|
||||
let user: User
|
||||
@ -28,8 +28,9 @@ describe('Update API', () => {
|
||||
|
||||
describe('update page', () => {
|
||||
let query: string
|
||||
let title = 'New Title'
|
||||
let description = 'New Description'
|
||||
const title = 'New Title'
|
||||
const description = 'New Description'
|
||||
const previewImage = 'https://omnivore.app/image.png'
|
||||
|
||||
beforeEach(() => {
|
||||
query = `
|
||||
@ -39,12 +40,14 @@ describe('Update API', () => {
|
||||
pageId: "${page.id}"
|
||||
title: "${title}"
|
||||
description: "${description}"
|
||||
previewImage: "${previewImage}"
|
||||
}
|
||||
) {
|
||||
... on UpdatePageSuccess {
|
||||
updatedPage {
|
||||
title
|
||||
description
|
||||
image
|
||||
}
|
||||
}
|
||||
... on UpdatePageError {
|
||||
@ -61,6 +64,7 @@ describe('Update API', () => {
|
||||
const updatedPage = res?.body.data.updatePage.updatedPage
|
||||
expect(updatedPage?.title).to.eql(title)
|
||||
expect(updatedPage?.description).to.eql(description)
|
||||
expect(updatedPage?.image).to.eql(previewImage)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user