Files
shields/services/codeship/codeship.tester.js
Paul Melnikow ea4b758612 Move service tests alongside code (#1563)
Per discussion in #1543
2018-03-20 18:32:48 -07:00

56 lines
1.7 KiB
JavaScript

'use strict';
const Joi = require('joi');
const ServiceTester = require('../service-tester');
const isBuildStatus = Joi.string().regex(/^(passing|pending|failing|not built)$/);
const t = new ServiceTester({ id: 'codeship', title: 'codeship' });
module.exports = t;
t.create('codeship (valid, no branch)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1.json')
.expectJSONTypes(Joi.object().keys({
name: 'build',
value: isBuildStatus,
}));
t.create('codeship (valid, with branch)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1/master.json')
.expectJSONTypes(Joi.object().keys({
name: 'build',
value: isBuildStatus,
}));
t.create('codeship (repo not found)')
.get('/not-a-repo.json')
.expectJSON({name: 'build', value: 'not found'});
t.create('codeship (branch not found)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1/not-a-branch.json')
.expectJSON({name: 'build', value: 'branch not found'});
t.create('codeship (connection error)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1.json')
.networkOff()
.expectJSON({name: 'build', value: 'inaccessible'});
t.create('codeship (unexpected response header)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1.json')
.intercept(nock => nock('https://codeship.com')
.get('/projects/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1/status')
.reply(200, "", {
'content-disposition': 'foo'
})
)
.expectJSON({name: 'build', value: 'unknown'});
t.create('codeship (unexpected response body)')
.get('/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1.json')
.intercept(nock => nock('https://codeship.com')
.get('/projects/d6c1ddd0-16a3-0132-5f85-2e35c05e22b1/status')
.reply(200, "")
)
.expectJSON({name: 'build', value: 'invalid'});