]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/id-and-pass-auth.ts
Add runner server tests
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / id-and-pass-auth.ts
index a73d76caac96b56cc6709fc915c80c1ac805255b..10155c28b667be5087fc4d5b28e56b75c2905d82 100644 (file)
@@ -1,10 +1,9 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
 import { expect } from 'chai'
-import { HttpStatusCode } from '@shared/models'
-import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils'
-import { UserRole } from '@shared/models'
+import { wait } from '@shared/core-utils'
+import { HttpStatusCode, UserRole } from '@shared/models'
+import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/server-commands'
 
 describe('Test id and pass auth plugins', function () {
   let server: PeerTubeServer
@@ -14,6 +13,7 @@ describe('Test id and pass auth plugins', function () {
 
   let lagunaAccessToken: string
   let lagunaRefreshToken: string
+  let lagunaId: number
 
   before(async function () {
     this.timeout(30000)
@@ -49,7 +49,7 @@ describe('Test id and pass auth plugins', function () {
 
     expect(body.username).to.equal('spyro')
     expect(body.account.displayName).to.equal('Spyro the Dragon')
-    expect(body.role).to.equal(UserRole.USER)
+    expect(body.role.id).to.equal(UserRole.USER)
   })
 
   it('Should login Crash, create the user and use the token', async function () {
@@ -64,7 +64,7 @@ describe('Test id and pass auth plugins', function () {
 
       expect(body.username).to.equal('crash')
       expect(body.account.displayName).to.equal('Crash Bandicoot')
-      expect(body.role).to.equal(UserRole.MODERATOR)
+      expect(body.role.id).to.equal(UserRole.MODERATOR)
     }
   })
 
@@ -79,8 +79,10 @@ describe('Test id and pass auth plugins', function () {
       const body = await server.users.getMyInfo({ token: lagunaAccessToken })
 
       expect(body.username).to.equal('laguna')
-      expect(body.account.displayName).to.equal('laguna')
-      expect(body.role).to.equal(UserRole.USER)
+      expect(body.account.displayName).to.equal('Laguna Loire')
+      expect(body.role.id).to.equal(UserRole.USER)
+
+      lagunaId = body.id
     }
   })
 
@@ -130,7 +132,34 @@ describe('Test id and pass auth plugins', function () {
     expect(body.username).to.equal('crash')
     expect(body.account.displayName).to.equal('Beautiful Crash')
     expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
-    expect(body.role).to.equal(UserRole.MODERATOR)
+    expect(body.role.id).to.equal(UserRole.MODERATOR)
+  })
+
+  it('Should login Laguna and update the profile', async function () {
+    {
+      await server.users.update({ userId: lagunaId, videoQuota: 43000, videoQuotaDaily: 43100 })
+      await server.users.updateMe({ token: lagunaAccessToken, displayName: 'laguna updated' })
+
+      const body = await server.users.getMyInfo({ token: lagunaAccessToken })
+      expect(body.username).to.equal('laguna')
+      expect(body.account.displayName).to.equal('laguna updated')
+      expect(body.videoQuota).to.equal(43000)
+      expect(body.videoQuotaDaily).to.equal(43100)
+    }
+
+    {
+      const body = await server.login.login({ user: { username: 'laguna', password: 'laguna password' } })
+      lagunaAccessToken = body.access_token
+      lagunaRefreshToken = body.refresh_token
+    }
+
+    {
+      const body = await server.users.getMyInfo({ token: lagunaAccessToken })
+      expect(body.username).to.equal('laguna')
+      expect(body.account.displayName).to.equal('Laguna Loire')
+      expect(body.videoQuota).to.equal(42000)
+      expect(body.videoQuotaDaily).to.equal(43100)
+    }
   })
 
   it('Should reject token of laguna by the plugin hook', async function () {
@@ -148,7 +177,7 @@ describe('Test id and pass auth plugins', function () {
     await server.servers.waitUntilLog('valid username')
 
     await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
-    await server.servers.waitUntilLog('valid display name')
+    await server.servers.waitUntilLog('valid displayName')
 
     await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
     await server.servers.waitUntilLog('valid role')