From 302742243ae7f197c48555209a1353afde0bda0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 20 Dec 2018 22:47:55 +0100 Subject: [PATCH] move data used in tests to test/sample.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- test/app.js | 19 ++++++++----------- test/comments.js | 26 ++------------------------ test/sample.js | 41 +++++++++++++++++++++++++++++++++++++++++ test/schema.js | 13 ++----------- 4 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 test/sample.js diff --git a/test/app.js b/test/app.js index 0da16d6..d602ecf 100644 --- a/test/app.js +++ b/test/app.js @@ -2,28 +2,23 @@ import { expect } from 'chai' import sinon from 'sinon' import request from 'supertest' +import sample from './sample' import App from '../src/app' import Builds from '../src/builds' import Comments from '../src/comments' -let comments -let app -const COMMENTS = [ - { pr: 'PR-1', comment_id: 1234 }, - { pr: 'PR-2', comment_id: 4321 }, - { pr: 'PR-3', comment_id: 9753 }, -] +let comments, app describe('App', () => { beforeEach(() => { comments = sinon.createStubInstance(Comments) comments.db = sinon.createStubInstance(Builds, { - getComments: COMMENTS, + getComments: sample.COMMENTS, }), app = App(comments) }) - describe('/health', () => { + describe('GET /health', () => { it('should return OK', async () => { const resp = await request(app.callback()).get('/health') expect(resp.text).to.eq('OK') @@ -31,10 +26,12 @@ describe('App', () => { }) }) - describe('/comments', () => { + describe('GET /comments', () => { it('should return list of builds', async () => { 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) }) }) diff --git a/test/comments.js b/test/comments.js index 1ca3344..ca71ad6 100644 --- a/test/comments.js +++ b/test/comments.js @@ -1,34 +1,12 @@ import { expect } from 'chai' import sinon from 'sinon' +import sample from './sample' import Builds from '../src/builds' import Comments from '../src/comments' 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 */ const COMMENT = ` ### Jenkins Builds @@ -48,7 +26,7 @@ describe('Comments', () => { }, } builds = sinon.createStubInstance(Builds, { - getBuilds: BUILDS, + getBuilds: sample.BUILDS, }) comments = new Comments(client, 'owner', 'repo', builds) }) diff --git a/test/sample.js b/test/sample.js new file mode 100644 index 0000000..9fe975c --- /dev/null +++ b/test/sample.js @@ -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 } diff --git a/test/schema.js b/test/schema.js index 9f7cca8..9270279 100644 --- a/test/schema.js +++ b/test/schema.js @@ -2,24 +2,15 @@ import { expect } from 'chai' import sinon from 'sinon' import Joi from 'joi' +import sample from './sample' import Schema from '../src/schema' 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', () => { beforeEach(() => { /* refresh for every test */ - build = Object.assign({}, BUILD) + build = Object.assign({}, sample.BUILD) }) describe('id', () => {