From a42f78b7109cc5afee82a1795975909bd7bee161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 20 Dec 2018 18:46:49 +0100 Subject: [PATCH] add schema tests for commit field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- test/schema.js | 27 ++++++++++++++++++++------- test/setup.js | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/test/schema.js b/test/schema.js index 4ae4781..42760e1 100644 --- a/test/schema.js +++ b/test/schema.js @@ -18,11 +18,28 @@ const BUILD = { describe('Schema', () => { beforeEach(() => { /* refresh for every test */ - build = Object.assign(BUILD) + build = Object.assign({}, BUILD) }) + describe('commit', () => { + it('has to be a commit', async () => { + let rval = await Joi.validate(build, Schema) + expect(rval).to.eql(build) + }) + + it('can\'t be a null', () => { + build.commit = null + expect(Joi.validate(build, Schema)).to.be.rejectedWith('"commit" must be a string') + }) + + it('can\'t be a number', async () => { + build.commit = 1 + expect(Joi.validate(build, Schema)).to.be.rejectedWith('"commit" must be a string') + }) + }) + describe('pkg_url', () => { - it('can be a string', async () => { + it('has to be a URL', async () => { let rval = await Joi.validate(build, Schema) expect(rval).to.eql(build) }) @@ -35,11 +52,7 @@ describe('Schema', () => { it('can\'t be a number', async () => { build.pkg_url = 1 - try { - await Joi.validate(build, Schema) - } catch (err) { - expect(err.message).to.contain('"pkg_url" must be a string') - } + expect(Joi.validate(build, Schema)).to.be.rejectedWith('"pkg_url" must be a string') }) }) }) diff --git a/test/setup.js b/test/setup.js index 94e100e..d9007a9 100644 --- a/test/setup.js +++ b/test/setup.js @@ -1,4 +1,6 @@ import chai from 'chai' import sinonChai from 'sinon-chai' +import chaiAsPromised from 'chai-as-promised' chai.use(sinonChai) +chai.use(chaiAsPromised);