]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/requests/requests.ts
API: Add ability to update video channel avatar
[github/Chocobozzz/PeerTube.git] / server / tests / utils / requests / requests.ts
index b6195089dd169e95711b4e46474fc2e473a7865e..ebde692cd44ea6ef25a3373106dbd15664406baf 100644 (file)
@@ -1,5 +1,6 @@
 import * as request from 'supertest'
 import { buildAbsoluteFixturePath } from '../miscs/miscs'
+import { isAbsolute, join } from 'path'
 
 function makeGetRequest (options: {
   url: string,
@@ -45,7 +46,7 @@ function makeUploadRequest (options: {
   url: string,
   method?: 'POST' | 'PUT',
   path: string,
-  token: string,
+  token?: string,
   fields: { [ fieldName: string ]: any },
   attaches: { [ attachName: string ]: any },
   statusCodeExpected?: number
@@ -122,6 +123,29 @@ function makePutBodyRequest (options: {
             .expect(options.statusCodeExpected)
 }
 
+function updateAvatarRequest (options: {
+  url: string,
+  path: string,
+  accessToken: string,
+  fixture: string
+}) {
+  let filePath = ''
+  if (isAbsolute(options.fixture)) {
+    filePath = options.fixture
+  } else {
+    filePath = join(__dirname, '..', '..', 'fixtures', options.fixture)
+  }
+
+  return makeUploadRequest({
+    url: options.url,
+    path: options.path,
+    token: options.accessToken,
+    fields: {},
+    attaches: { avatarfile: filePath },
+    statusCodeExpected: 200
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -129,5 +153,6 @@ export {
   makeUploadRequest,
   makePostBodyRequest,
   makePutBodyRequest,
-  makeDeleteRequest
+  makeDeleteRequest,
+  updateAvatarRequest
 }