PeerTube/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts

35 lines
842 B
TypeScript
Raw Normal View History

2021-08-27 07:32:44 -05:00
import express from 'express'
2021-10-22 07:31:38 -05:00
import { Server } from 'http'
import { getPort, randomListen } from './shared'
2021-03-11 09:54:52 -06:00
export class MockJoinPeerTubeVersions {
2021-10-22 07:31:38 -05:00
private server: Server
2021-03-11 09:54:52 -06:00
private latestVersion: string
2021-10-22 07:31:38 -05:00
async initialize () {
const app = express()
2021-03-11 09:54:52 -06:00
2021-10-22 07:31:38 -05:00
app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url)
2021-03-11 09:54:52 -06:00
2021-10-22 07:31:38 -05:00
return next()
})
2021-03-11 09:54:52 -06:00
2021-10-22 07:31:38 -05:00
app.get('/versions.json', (req: express.Request, res: express.Response) => {
return res.json({
peertube: {
latestVersion: this.latestVersion
}
2021-03-11 09:54:52 -06:00
})
})
2021-10-22 07:31:38 -05:00
this.server = await randomListen(app)
return getPort(this.server)
2021-03-11 09:54:52 -06:00
}
setLatestVersion (latestVersion: string) {
this.latestVersion = latestVersion
}
}