mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Add mock for upload response
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
5933fb801d
commit
ed9f4aefab
4 changed files with 14 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import { ImageProxyResponse } from '../../components/markdown-renderer/replace-components/image/types'
|
||||
import { isMockMode } from '../../utils/test-modes'
|
||||
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
|
||||
|
||||
export const getProxiedUrl = async (imageUrl: string): Promise<ImageProxyResponse> => {
|
||||
|
@ -23,16 +24,16 @@ export interface UploadedMedia {
|
|||
link: string
|
||||
}
|
||||
|
||||
export const uploadFile = async (noteId: string, contentType: string, media: Blob): Promise<UploadedMedia> => {
|
||||
const response = await fetch(getApiUrl() + 'media/upload', {
|
||||
export const uploadFile = async (noteId: string, media: Blob): Promise<UploadedMedia> => {
|
||||
const response = await fetch(`${getApiUrl()}media/upload${isMockMode() ? '-post' : ''}`, {
|
||||
...defaultFetchConfig,
|
||||
headers: {
|
||||
'Content-Type': contentType,
|
||||
'Content-Type': media.type,
|
||||
'HedgeDoc-Note': noteId
|
||||
},
|
||||
method: 'POST',
|
||||
body: media
|
||||
method: isMockMode() ? 'GET' : 'POST',
|
||||
body: isMockMode() ? undefined : media
|
||||
})
|
||||
expectResponseCode(response, 201)
|
||||
expectResponseCode(response, isMockMode() ? 200 : 201)
|
||||
return (await response.json()) as Promise<UploadedMedia>
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue