Fix tests
[oweals/peertube.git] / server / tests / plugins / translations.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   cleanupTests,
7   flushAndRunMultipleServers,
8   flushAndRunServer, killallServers, reRunServer,
9   ServerInfo,
10   waitUntilLog
11 } from '../../../shared/extra-utils/server/servers'
12 import {
13   addVideoCommentReply,
14   addVideoCommentThread,
15   deleteVideoComment,
16   getPluginTestPath,
17   getVideosList,
18   installPlugin,
19   removeVideo,
20   setAccessTokensToServers,
21   updateVideo,
22   uploadVideo,
23   viewVideo,
24   getVideosListPagination,
25   getVideo,
26   getVideoCommentThreads,
27   getVideoThreadComments,
28   getVideoWithToken,
29   setDefaultVideoChannel,
30   waitJobs,
31   doubleFollow, getVideoLanguages, getVideoLicences, getVideoCategories, uninstallPlugin, getPluginTranslations
32 } from '../../../shared/extra-utils'
33 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
34 import { VideoDetails } from '../../../shared/models/videos'
35 import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
36
37 const expect = chai.expect
38
39 describe('Test plugin translations', function () {
40   let server: ServerInfo
41
42   before(async function () {
43     this.timeout(30000)
44
45     server = await flushAndRunServer(1)
46     await setAccessTokensToServers([ server ])
47
48     await installPlugin({
49       url: server.url,
50       accessToken: server.accessToken,
51       path: getPluginTestPath()
52     })
53
54     await installPlugin({
55       url: server.url,
56       accessToken: server.accessToken,
57       path: getPluginTestPath('-two')
58     })
59   })
60
61   it('Should not have translations for locale pt', async function () {
62     const res = await getPluginTranslations({ url: server.url, locale: 'pt' })
63
64     expect(res.body).to.deep.equal({})
65   })
66
67   it('Should have translations for locale fr', async function () {
68     const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' })
69
70     expect(res.body).to.deep.equal({
71       'peertube-plugin-test': {
72         'Hi': 'Coucou'
73       },
74       'peertube-plugin-test-two': {
75         'Hello world': 'Bonjour le monde'
76       }
77     })
78   })
79
80   it('Should have translations of locale it', async function () {
81     const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' })
82
83     expect(res.body).to.deep.equal({
84       'peertube-plugin-test-two': {
85         'Hello world': 'Ciao, mondo!'
86       }
87     })
88   })
89
90   it('Should remove the plugin and remove the locales', async function () {
91     await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-two' })
92
93     {
94       const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' })
95
96       expect(res.body).to.deep.equal({
97         'peertube-plugin-test': {
98           'Hi': 'Coucou'
99         }
100       })
101     }
102
103     {
104       const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' })
105
106       expect(res.body).to.deep.equal({})
107     }
108   })
109
110   after(async function () {
111     await cleanupTests([ server ])
112   })
113 })