]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to delete previously added constants
authorChocobozzz <me@florianbigard.com>
Tue, 15 Jun 2021 13:18:11 +0000 (15:18 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 15 Jun 2021 13:18:11 +0000 (15:18 +0200)
server/lib/plugins/register-helpers.ts
server/tests/fixtures/peertube-plugin-test-video-constants/main.js [moved from server/tests/fixtures/peertube-plugin-test-three/main.js with 91% similarity]
server/tests/fixtures/peertube-plugin-test-video-constants/package.json [moved from server/tests/fixtures/peertube-plugin-test-three/package.json with 78% similarity]
server/tests/plugins/video-constants.ts

index f5b5733702105ad1a53d0cf029c61deb8b5ccf20..09275f9ba8ea6e59a268bc9b2a5243931e8f980b 100644 (file)
@@ -37,18 +37,20 @@ type VideoConstant = { [key in number | string]: string }
 
 type UpdatedVideoConstant = {
   [name in AlterableVideoConstant]: {
-    added: { key: number | string, label: string }[]
-    deleted: { key: number | string, label: string }[]
+    [ npmName: string]: {
+      added: { key: number | string, label: string }[]
+      deleted: { key: number | string, label: string }[]
+    }
   }
 }
 
 export class RegisterHelpers {
   private readonly updatedVideoConstants: UpdatedVideoConstant = {
-    playlistPrivacy: { added: [], deleted: [] },
-    privacy: { added: [], deleted: [] },
-    language: { added: [], deleted: [] },
-    licence: { added: [], deleted: [] },
-    category: { added: [], deleted: [] }
+    playlistPrivacy: { },
+    privacy: { },
+    language: { },
+    licence: { },
+    category: { }
   }
 
   private readonly transcodingProfiles: {
@@ -377,7 +379,7 @@ export class RegisterHelpers {
     const { npmName, type, obj, key } = parameters
 
     if (!obj[key]) {
-      logger.warn('Cannot delete %s %s by plugin %s: key does not exist.', type, npmName, key)
+      logger.warn('Cannot delete %s by plugin %s: key %s does not exist.', type, npmName, key)
       return false
     }
 
@@ -388,7 +390,15 @@ export class RegisterHelpers {
       }
     }
 
-    this.updatedVideoConstants[type][npmName].deleted.push({ key, label: obj[key] })
+    const updatedConstants = this.updatedVideoConstants[type][npmName]
+
+    const alreadyAdded = updatedConstants.added.find(a => a.key === key)
+    if (alreadyAdded) {
+      updatedConstants.added.filter(a => a.key !== key)
+    } else if (obj[key]) {
+      updatedConstants.deleted.push({ key, label: obj[key] })
+    }
+
     delete obj[key]
 
     return true
similarity index 91%
rename from server/tests/fixtures/peertube-plugin-test-three/main.js
rename to server/tests/fixtures/peertube-plugin-test-video-constants/main.js
index f2b89bcf0de526ba8f4161f78be4d3d45bebaced..3e650e0a12c542588781695af6f98919ecf7dcea 100644 (file)
@@ -11,8 +11,10 @@ async function register ({
 }) {
   videoLanguageManager.addLanguage('al_bhed', 'Al Bhed')
   videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2')
+  videoLanguageManager.addLanguage('al_bhed3', 'Al Bhed 3')
   videoLanguageManager.deleteLanguage('en')
   videoLanguageManager.deleteLanguage('fr')
+  videoLanguageManager.deleteLanguage('al_bhed3')
 
   videoCategoryManager.addCategory(42, 'Best category')
   videoCategoryManager.addCategory(43, 'High best category')
similarity index 78%
rename from server/tests/fixtures/peertube-plugin-test-three/package.json
rename to server/tests/fixtures/peertube-plugin-test-video-constants/package.json
index 41d4c93fe43205e3844b45000619eee63acd379f..0fcf399330379e2648cde8dbc8634c71186ee88b 100644 (file)
@@ -1,7 +1,7 @@
 {
-  "name": "peertube-plugin-test-three",
+  "name": "peertube-plugin-test-video-constants",
   "version": "0.0.1",
-  "description": "Plugin test 3",
+  "description": "Plugin test video constants",
   "engine": {
     "peertube": ">=1.3.0"
   },
index 5ee41fee14d8c4164478e3711cb619cc54fbaab5..eb014c596deb492c975541281d28cee114e33558 100644 (file)
@@ -32,7 +32,7 @@ describe('Test plugin altering video constants', function () {
     await installPlugin({
       url: server.url,
       accessToken: server.accessToken,
-      path: getPluginTestPath('-three')
+      path: getPluginTestPath('-video-constants')
     })
   })
 
@@ -45,6 +45,7 @@ describe('Test plugin altering video constants', function () {
 
     expect(languages['al_bhed']).to.equal('Al Bhed')
     expect(languages['al_bhed2']).to.equal('Al Bhed 2')
+    expect(languages['al_bhed3']).to.not.exist
   })
 
   it('Should have updated categories', async function () {
@@ -116,7 +117,7 @@ describe('Test plugin altering video constants', function () {
   })
 
   it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
-    await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' })
+    await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' })
 
     {
       const res = await getVideoLanguages(server.url)
@@ -127,6 +128,7 @@ describe('Test plugin altering video constants', function () {
 
       expect(languages['al_bhed']).to.not.exist
       expect(languages['al_bhed2']).to.not.exist
+      expect(languages['al_bhed3']).to.not.exist
     }
 
     {