2018-12-27 13:11:07 +00:00
|
|
|
const expect = require('chai').expect
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const request = require('supertest')
|
2018-12-20 21:30:14 +00:00
|
|
|
|
2018-12-27 13:11:07 +00:00
|
|
|
const sample = require('./sample')
|
|
|
|
const App = require('../src/app')
|
|
|
|
const Builds = require('../src/builds')
|
|
|
|
const Comments = require('../src/comments')
|
2018-12-20 21:30:14 +00:00
|
|
|
|
2018-12-20 22:35:19 +00:00
|
|
|
let ghc, app
|
2018-12-20 21:30:14 +00:00
|
|
|
|
|
|
|
describe('App', () => {
|
|
|
|
beforeEach(() => {
|
2018-12-20 22:35:19 +00:00
|
|
|
ghc = sinon.createStubInstance(Comments)
|
|
|
|
ghc.db = sinon.createStubInstance(Builds, {
|
2018-12-20 21:47:55 +00:00
|
|
|
getComments: sample.COMMENTS,
|
2020-07-06 16:59:59 +00:00
|
|
|
getBuilds: sample.BUILDS,
|
2018-12-20 21:36:37 +00:00
|
|
|
}),
|
2019-02-06 21:50:48 +00:00
|
|
|
app = App({ghc})
|
2018-12-20 21:30:14 +00:00
|
|
|
})
|
|
|
|
|
2021-08-16 17:43:58 +00:00
|
|
|
describe('GET /', () => {
|
|
|
|
it('should redirect to main site', async () => {
|
|
|
|
const resp = await request(app.callback()).get('/')
|
|
|
|
expect(resp.status).to.eq(302)
|
|
|
|
expect(resp.headers.location).to.eq('https://status.im/')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-20 21:47:55 +00:00
|
|
|
describe('GET /health', () => {
|
2018-12-20 21:30:14 +00:00
|
|
|
it('should return OK', async () => {
|
2018-12-20 22:35:19 +00:00
|
|
|
const resp = await request(app.callback())
|
|
|
|
.get('/health')
|
2018-12-20 21:30:14 +00:00
|
|
|
expect(resp.text).to.eq('OK')
|
|
|
|
expect(resp.status).to.eq(200)
|
|
|
|
})
|
|
|
|
})
|
2018-12-20 21:36:37 +00:00
|
|
|
|
2018-12-20 21:47:55 +00:00
|
|
|
describe('GET /comments', () => {
|
2020-07-06 16:59:59 +00:00
|
|
|
it('should return list of comments', async () => {
|
2018-12-20 22:35:19 +00:00
|
|
|
const resp = await request(app.callback())
|
|
|
|
.get('/comments')
|
2018-12-20 21:47:55 +00:00
|
|
|
expect(resp.body).to.eql({
|
|
|
|
count: sample.COMMENTS.length, comments: sample.COMMENTS
|
|
|
|
})
|
2018-12-20 21:36:37 +00:00
|
|
|
expect(resp.status).to.eq(200)
|
|
|
|
})
|
|
|
|
})
|
2018-12-20 22:35:19 +00:00
|
|
|
|
2019-02-06 21:50:48 +00:00
|
|
|
describe('POST /builds/:repo/:pr', () => {
|
2018-12-20 22:35:19 +00:00
|
|
|
it('should store the POSTed build', async () => {
|
|
|
|
const resp = await request(app.callback())
|
2019-02-06 21:50:48 +00:00
|
|
|
.post('/builds/REPO-1/PR-1')
|
2018-12-20 22:35:19 +00:00
|
|
|
.send(sample.BUILD)
|
|
|
|
expect(resp.body).to.eql({status:'ok'})
|
|
|
|
expect(resp.status).to.eq(201)
|
2019-02-06 21:50:48 +00:00
|
|
|
expect(ghc.db.addBuild).calledOnceWith({
|
|
|
|
repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD,
|
|
|
|
})
|
2019-07-22 20:13:38 +00:00
|
|
|
expect(ghc.safeUpdate).calledOnceWith({
|
2019-02-06 21:50:48 +00:00
|
|
|
repo: 'REPO-1', pr: 'PR-1'
|
|
|
|
})
|
2018-12-20 22:35:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-07-06 16:59:59 +00:00
|
|
|
describe('GET /builds/:repo/:pr', () => {
|
|
|
|
it('should return list of builds', async () => {
|
|
|
|
const resp = await request(app.callback())
|
|
|
|
.get('/builds/REPO-1/PR-1')
|
|
|
|
expect(resp.body).to.eql({
|
|
|
|
count: sample.BUILDS.length, builds: sample.BUILDS,
|
|
|
|
})
|
|
|
|
expect(resp.status).to.eq(200)
|
|
|
|
})
|
|
|
|
})
|
2018-12-20 22:35:19 +00:00
|
|
|
|
2020-07-06 17:02:27 +00:00
|
|
|
describe('DELETE /builds/:repo/:pr', () => {
|
|
|
|
it('should delete all matching builds', async () => {
|
|
|
|
const resp = await request(app.callback())
|
|
|
|
.delete('/builds/REPO-1/PR-1')
|
|
|
|
expect(resp.body).to.eql({})
|
|
|
|
expect(resp.status).to.eq(200)
|
|
|
|
expect(ghc.db.removeBuilds).calledOnceWith({
|
|
|
|
repo: 'REPO-1', pr: 'PR-1',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-02-06 21:50:48 +00:00
|
|
|
describe('POST /builds/:repo/:pr/refresh', () => {
|
2018-12-20 22:35:19 +00:00
|
|
|
it('should update github comment', async () => {
|
|
|
|
const resp = await request(app.callback())
|
2019-02-06 21:50:48 +00:00
|
|
|
.post('/builds/REPO-1/PR-1/refresh')
|
2018-12-20 22:35:19 +00:00
|
|
|
.send(sample.BUILD)
|
|
|
|
expect(resp.body).to.eql({status:'ok'})
|
|
|
|
expect(resp.status).to.eq(201)
|
2019-02-06 21:50:48 +00:00
|
|
|
expect(ghc.db.addBuild).not.calledOnceWith({
|
|
|
|
repo: 'REPO-1', pr: 'PR-1', build: sample.BUILD
|
|
|
|
})
|
2019-07-22 20:13:38 +00:00
|
|
|
expect(ghc.safeUpdate).calledOnceWith({
|
2019-02-06 21:50:48 +00:00
|
|
|
repo: 'REPO-1', pr: 'PR-1',
|
|
|
|
})
|
2018-12-20 22:35:19 +00:00
|
|
|
})
|
|
|
|
})
|
2018-12-20 21:30:14 +00:00
|
|
|
})
|