move data used in tests to test/sample.js

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-12-20 22:47:55 +01:00
parent 19a2d8b031
commit 302742243a
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 53 additions and 46 deletions

View File

@ -2,28 +2,23 @@ import { expect } from 'chai'
import sinon from 'sinon' import sinon from 'sinon'
import request from 'supertest' import request from 'supertest'
import sample from './sample'
import App from '../src/app' import App from '../src/app'
import Builds from '../src/builds' import Builds from '../src/builds'
import Comments from '../src/comments' import Comments from '../src/comments'
let comments let comments, app
let app
const COMMENTS = [
{ pr: 'PR-1', comment_id: 1234 },
{ pr: 'PR-2', comment_id: 4321 },
{ pr: 'PR-3', comment_id: 9753 },
]
describe('App', () => { describe('App', () => {
beforeEach(() => { beforeEach(() => {
comments = sinon.createStubInstance(Comments) comments = sinon.createStubInstance(Comments)
comments.db = sinon.createStubInstance(Builds, { comments.db = sinon.createStubInstance(Builds, {
getComments: COMMENTS, getComments: sample.COMMENTS,
}), }),
app = App(comments) app = App(comments)
}) })
describe('/health', () => { describe('GET /health', () => {
it('should return OK', async () => { it('should return OK', async () => {
const resp = await request(app.callback()).get('/health') const resp = await request(app.callback()).get('/health')
expect(resp.text).to.eq('OK') expect(resp.text).to.eq('OK')
@ -31,10 +26,12 @@ describe('App', () => {
}) })
}) })
describe('/comments', () => { describe('GET /comments', () => {
it('should return list of builds', async () => { it('should return list of builds', async () => {
const resp = await request(app.callback()).get('/comments') const resp = await request(app.callback()).get('/comments')
expect(resp.body).to.eql({ count: COMMENTS.length, comments: COMMENTS}) expect(resp.body).to.eql({
count: sample.COMMENTS.length, comments: sample.COMMENTS
})
expect(resp.status).to.eq(200) expect(resp.status).to.eq(200)
}) })
}) })

View File

@ -1,34 +1,12 @@
import { expect } from 'chai' import { expect } from 'chai'
import sinon from 'sinon' import sinon from 'sinon'
import sample from './sample'
import Builds from '../src/builds' import Builds from '../src/builds'
import Comments from '../src/comments' import Comments from '../src/comments'
let comments, client, builds let comments, client, builds
const BUILDS = [
{
id: 'ID-1',
commit: 'COMMIT-1',
success: true,
platform: 'PLATFORM-1',
duration: 'DURATION-1',
url: 'URL-1',
pkg_url: 'PKG_URL-1',
meta: { created: 1545294393058 },
},
{
id: 'ID-2',
commit: 'COMMIT-2',
success: false,
platform: 'PLATFORM-2',
duration: 'DURATION-2',
url: 'URL-2',
pkg_url: 'PKG_URL-2',
meta: { created: 1545295528896 },
},
]
/* expected comment based on given builds */ /* expected comment based on given builds */
const COMMENT = ` const COMMENT = `
### Jenkins Builds ### Jenkins Builds
@ -48,7 +26,7 @@ describe('Comments', () => {
}, },
} }
builds = sinon.createStubInstance(Builds, { builds = sinon.createStubInstance(Builds, {
getBuilds: BUILDS, getBuilds: sample.BUILDS,
}) })
comments = new Comments(client, 'owner', 'repo', builds) comments = new Comments(client, 'owner', 'repo', builds)
}) })

41
test/sample.js Normal file
View File

@ -0,0 +1,41 @@
/* example valid build */
const BUILD = {
id: 'ID-1',
commit: 'abcd1234',
success: true,
platform: 'PLATFORM-1',
duration: 'DURATION-1',
url: 'https://example.com/some/url/path',
pkg_url: 'https://example.com/some/pkg/path',
}
const BUILDS = [
{
id: 'ID-1',
commit: 'COMMIT-1',
success: true,
platform: 'PLATFORM-1',
duration: 'DURATION-1',
url: 'URL-1',
pkg_url: 'PKG_URL-1',
meta: { created: 1545294393058 },
},
{
id: 'ID-2',
commit: 'COMMIT-2',
success: false,
platform: 'PLATFORM-2',
duration: 'DURATION-2',
url: 'URL-2',
pkg_url: 'PKG_URL-2',
meta: { created: 1545295528896 },
},
]
const COMMENTS = [
{ pr: 'PR-1', comment_id: 1234 },
{ pr: 'PR-2', comment_id: 4321 },
{ pr: 'PR-3', comment_id: 9753 },
]
module.exports = { BUILD, BUILDS, COMMENTS }

View File

@ -2,24 +2,15 @@ import { expect } from 'chai'
import sinon from 'sinon' import sinon from 'sinon'
import Joi from 'joi' import Joi from 'joi'
import sample from './sample'
import Schema from '../src/schema' import Schema from '../src/schema'
let build let build
/* example valid build */
const BUILD = {
id: 'ID-1',
commit: 'abcd1234',
success: true,
platform: 'PLATFORM-1',
duration: 'DURATION-1',
url: 'https://example.com/some/url/path',
pkg_url: 'https://example.com/some/pkg/path',
}
describe('Schema', () => { describe('Schema', () => {
beforeEach(() => { beforeEach(() => {
/* refresh for every test */ /* refresh for every test */
build = Object.assign({}, BUILD) build = Object.assign({}, sample.BUILD)
}) })
describe('id', () => { describe('id', () => {