]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/filter-hooks.ts
Translated using Weblate (Japanese)
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / filter-hooks.ts
index 6724b3bf86dcfcc7b6fd3946be8fbc4bd70b8ad9..37eef6cf36385536107853cf990bde8c733bd513 100644 (file)
@@ -1,7 +1,15 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import { expect } from 'chai'
-import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
+import {
+  HttpStatusCode,
+  PeerTubeProblemDocument,
+  VideoDetails,
+  VideoImportState,
+  VideoPlaylist,
+  VideoPlaylistPrivacy,
+  VideoPrivacy
+} from '@shared/models'
 import {
   cleanupTests,
   createMultipleServers,
@@ -408,23 +416,52 @@ describe('Test plugin filter hooks', function () {
 
   describe('Should run filter:api.user.signup.allowed.result', function () {
 
+    before(async function () {
+      await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: false } } })
+    })
+
     it('Should run on config endpoint', async function () {
       const body = await servers[0].config.getConfig()
       expect(body.signup.allowed).to.be.true
     })
 
     it('Should allow a signup', async function () {
-      await servers[0].users.register({ username: 'john', password: 'password' })
+      await servers[0].registrations.register({ username: 'john1' })
     })
 
     it('Should not allow a signup', async function () {
-      const res = await servers[0].users.register({
-        username: 'jma',
-        password: 'password',
+      const res = await servers[0].registrations.register({
+        username: 'jma 1',
+        expectedStatus: HttpStatusCode.FORBIDDEN_403
+      })
+
+      expect(res.body.error).to.equal('No jma 1')
+    })
+  })
+
+  describe('Should run filter:api.user.request-signup.allowed.result', function () {
+
+    before(async function () {
+      await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: true } } })
+    })
+
+    it('Should run on config endpoint', async function () {
+      const body = await servers[0].config.getConfig()
+      expect(body.signup.allowed).to.be.true
+    })
+
+    it('Should allow a signup request', async function () {
+      await servers[0].registrations.requestRegistration({ username: 'john2', registrationReason: 'tt' })
+    })
+
+    it('Should not allow a signup request', async function () {
+      const body = await servers[0].registrations.requestRegistration({
+        username: 'jma 2',
+        registrationReason: 'tt',
         expectedStatus: HttpStatusCode.FORBIDDEN_403
       })
 
-      expect(res.body.error).to.equal('No jma')
+      expect((body as unknown as PeerTubeProblemDocument).error).to.equal('No jma 2')
     })
   })