|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var uuid = require('node-uuid'); |
| 4 | + |
| 5 | +function TestStorage() { |
| 6 | +} |
| 7 | + |
| 8 | +TestStorage.prototype = { |
| 9 | + run: function(storageGenerator) { |
| 10 | + describe('integration-tests', function() { |
| 11 | + var storage; |
| 12 | + |
| 13 | + beforeEach(function() { |
| 14 | + storage = storageGenerator(); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('#hasProject', function() { |
| 18 | + it('resolves false if project does not exist', function() { |
| 19 | + return assert.eventually.isFalse(storage.hasProject('foo')); |
| 20 | + }); |
| 21 | + |
| 22 | + it('resolves true if project exists', function() { |
| 23 | + return storage.createProject({ |
| 24 | + info: 'foo' |
| 25 | + }) |
| 26 | + .then(function(result) { |
| 27 | + return assert.eventually.isTrue(storage.hasProject(result.project)); |
| 28 | + }); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('#createProject', function() { |
| 33 | + describe('with invalid args', function() { |
| 34 | + it('should throw with no arg', function() { |
| 35 | + assert.throws(function() { |
| 36 | + return storage.createProject(); |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should throw with non object arg', function() { |
| 41 | + assert.throws(function() { |
| 42 | + return storage.createProject('string'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('with valid args', function() { |
| 48 | + var options; |
| 49 | + |
| 50 | + beforeEach(function() { |
| 51 | + options = { |
| 52 | + github: { |
| 53 | + repository: 'foo' |
| 54 | + } |
| 55 | + }; |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return an object with id', function() { |
| 59 | + return storage.createProject(options) |
| 60 | + .then(function(result) { |
| 61 | + assert.isObject(result); |
| 62 | + assert.isString(result.project); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('#getProjectInfo', function() { |
| 69 | + describe('with invalid args', function() { |
| 70 | + it('should throw with non string id', function() { |
| 71 | + assert.throws(function() { |
| 72 | + return storage.getProjectInfo({}); |
| 73 | + }); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + describe('with valid args', function() { |
| 78 | + it('should reject non existent project', function() { |
| 79 | + return assert.isRejected(storage.getProjectInfo('project'), /Unknown Project/); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should return info about the build', function() { |
| 83 | + var projectOptions = { |
| 84 | + github: { |
| 85 | + user: 'user', |
| 86 | + repository: 'repository' |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + return storage.createProject(projectOptions) |
| 91 | + .then(function(result) { |
| 92 | + return storage.getProjectInfo(result.project); |
| 93 | + }) |
| 94 | + .then(function(projectInfo) { |
| 95 | + assert.shallowDeepEqual(projectInfo, projectOptions); |
| 96 | + }); |
| 97 | + }); |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + describe('#startBuild', function() { |
| 102 | + describe('with invalid args', function() { |
| 103 | + it('should throw with no arg', function() { |
| 104 | + assert.throws(function() { |
| 105 | + return storage.startBuild(); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should throw with only an object', function() { |
| 110 | + assert.throws(function() { |
| 111 | + return storage.startBuild({}); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should throw with only head', function() { |
| 116 | + assert.throws(function() { |
| 117 | + return storage.startBuild({ |
| 118 | + head: 'head' |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should throw with only base', function() { |
| 124 | + assert.throws(function() { |
| 125 | + return storage.startBuild({ |
| 126 | + base: 'base' |
| 127 | + }); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should throw with numBrowsers as string', function() { |
| 132 | + assert.throws(function() { |
| 133 | + return storage.startBuild({ |
| 134 | + numBrowsers: '4' |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + it('should throw without numBrowsers', function() { |
| 140 | + assert.throws(function() { |
| 141 | + return storage.startBuild({ |
| 142 | + head: 'head', |
| 143 | + base: 'base' |
| 144 | + }); |
| 145 | + }); |
| 146 | + }); |
| 147 | + |
| 148 | + it('should reject if project does not exist', function() { |
| 149 | + assert.isRejected(storage.startBuild({ |
| 150 | + project: 'project', |
| 151 | + head: 'head', |
| 152 | + base: 'base', |
| 153 | + numBrowsers: 2 |
| 154 | + })); |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + describe('with valid args', function() { |
| 159 | + var buildOptions; |
| 160 | + |
| 161 | + beforeEach(function() { |
| 162 | + return storage.createProject({}) |
| 163 | + .then(function(project) { |
| 164 | + buildOptions = { |
| 165 | + project: project.project, |
| 166 | + head: uuid.v4(), |
| 167 | + base: uuid.v4(), |
| 168 | + numBrowsers: 3 |
| 169 | + }; |
| 170 | + }); |
| 171 | + }); |
| 172 | + |
| 173 | + it('should return an id', function() { |
| 174 | + return storage.startBuild(buildOptions) |
| 175 | + .then(function(data) { |
| 176 | + assert.isObject(data); |
| 177 | + assert.isString(data.build); |
| 178 | + }); |
| 179 | + }); |
| 180 | + }); |
| 181 | + }); |
| 182 | + |
| 183 | + describe('#saveImages', function() { |
| 184 | + it('implement integration tests'); |
| 185 | + }); |
| 186 | + |
| 187 | + describe('#hasBuild', function() { |
| 188 | + describe('with invalid args', function() { |
| 189 | + it('should throw with non string id', function() { |
| 190 | + assert.throws(function() { |
| 191 | + return storage.hasBuild(4) |
| 192 | + .then(function(err) { |
| 193 | + console.error(err); |
| 194 | + }); |
| 195 | + }); |
| 196 | + }); |
| 197 | + }); |
| 198 | + |
| 199 | + describe('with valid args', function() { |
| 200 | + var projectOptions; |
| 201 | + var buildOptions; |
| 202 | + |
| 203 | + beforeEach(function() { |
| 204 | + projectOptions = { |
| 205 | + }; |
| 206 | + |
| 207 | + buildOptions = { |
| 208 | + head: 'head', |
| 209 | + base: 'base', |
| 210 | + numBrowsers: 3 |
| 211 | + }; |
| 212 | + }); |
| 213 | + |
| 214 | + it('should resolve false if project does not exist', function() { |
| 215 | + return assert.eventually.isFalse(storage.hasBuild({ |
| 216 | + project: 'project', |
| 217 | + build: 'build' |
| 218 | + })); |
| 219 | + }); |
| 220 | + |
| 221 | + it('should resolve false if no build', function() { |
| 222 | + return storage.createProject(projectOptions) |
| 223 | + .then(function(project) { |
| 224 | + return assert.eventually.isFalse(storage.hasBuild({ |
| 225 | + project: project.project, |
| 226 | + build: 'build' |
| 227 | + })); |
| 228 | + }); |
| 229 | + }); |
| 230 | + |
| 231 | + it('should resolve true if build exists', function() { |
| 232 | + return storage.createProject(projectOptions) |
| 233 | + .then(function(project) { |
| 234 | + buildOptions.project = project.project; |
| 235 | + |
| 236 | + return storage.startBuild(buildOptions); |
| 237 | + }) |
| 238 | + .then(function(data) { |
| 239 | + return assert.eventually.isTrue(storage.hasBuild({ |
| 240 | + project: buildOptions.project, |
| 241 | + build: data.build |
| 242 | + })); |
| 243 | + }); |
| 244 | + }); |
| 245 | + |
| 246 | + it('should resolve false if called with different id than startBuild', function() { |
| 247 | + return storage.createProject(projectOptions) |
| 248 | + .then(function(project) { |
| 249 | + buildOptions.project = project.project; |
| 250 | + |
| 251 | + return storage.startBuild(buildOptions) |
| 252 | + .then(function(data) { |
| 253 | + return storage.hasBuild({ |
| 254 | + project: buildOptions.project, |
| 255 | + build: data.build + '_' |
| 256 | + }); |
| 257 | + }) |
| 258 | + .then(function(status) { |
| 259 | + assert.isFalse(status); |
| 260 | + }); |
| 261 | + }); |
| 262 | + }); |
| 263 | + }); |
| 264 | + }); |
| 265 | + }); |
| 266 | + } |
| 267 | +}; |
| 268 | + |
| 269 | +module.exports = TestStorage; |
0 commit comments