| 'use strict'; |
| |
| const assert = require('assert'); |
| |
| require('../tools/js/v3-models.js'); |
| let MockModels = require('./resources/mock-v3-models.js').MockModels; |
| |
| function sampleBuildRequestData() |
| { |
| return { |
| "buildRequests": [{ |
| "id": "16985", |
| "triggerable": "3", |
| "test": "844", |
| "platform": "31", |
| "testGroup": "2128", |
| "order": "0", |
| "rootSet": "4255", |
| "status": "pending", |
| "url": null, |
| "build": null, |
| "createdAt": 1458688514000 |
| }], |
| "rootSets": [{ |
| "id": "4255", |
| "roots": ["87832", "93116"] |
| }, { |
| "id": "4256", |
| "roots": ["87832", "96336"] |
| }], |
| "roots": [{ |
| "id": "87832", |
| "repository": "9", |
| "revision": "10.11 15A284", |
| "time": 0 |
| }, { |
| "id": "93116", |
| "repository": "11", |
| "revision": "191622", |
| "time": 1445945816878 |
| }, { |
| "id": "87832", |
| "repository": "9", |
| "revision": "10.11 15A284", |
| "time": 0 |
| }, { |
| "id": "96336", |
| "repository": "11", |
| "revision": "192736", |
| "time": 1448225325650 |
| }], |
| "status": "OK" |
| }; |
| } |
| |
| describe('TestGroup', function () { |
| MockModels.inject(); |
| |
| describe('waitingTime', function () { |
| it('should return "0 minutes" when the reference time is identically equal to createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '0 minutes'); |
| }); |
| |
| it('should return "1 minute" when the reference time is exactly one minute head of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 60 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '1 minute'); |
| }); |
| |
| it('should return "1 minute" when the reference time is 75 seconds head of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 75 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '1 minute'); |
| }); |
| |
| it('should return "2 minutes" when the reference time is 118 seconds head of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 118 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '2 minutes'); |
| }); |
| |
| it('should return "75 minutes" when the reference time is 75 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 75 * 60 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '75 minutes'); |
| }); |
| |
| it('should return "1 hour 58 minutes" when the reference time is 118 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 118 * 60 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '1 hour 58 minutes'); |
| }); |
| |
| it('should return "3 hours 2 minutes" when the reference time is 182 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - 182 * 60 * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '3 hours 2 minutes'); |
| }); |
| |
| it('should return "27 hours 14 minutes" when the reference time is 27 hours 14 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - (27 * 3600 + 14 * 60) * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '27 hours 14 minutes'); |
| }); |
| |
| it('should return "2 days 3 hours" when the reference time is 51 hours 14 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - (51 * 3600 + 14 * 60) * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '2 days 3 hours'); |
| }); |
| |
| it('should return "2 days 0 hours" when the reference time is 48 hours 1 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - (48 * 3600 + 1 * 60) * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '2 days 0 hours'); |
| }); |
| |
| it('should return "2 days 2 hours" when the reference time is 49 hours 59 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - (49 * 3600 + 59 * 60) * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '2 days 2 hours'); |
| }); |
| |
| it('should return "2 weeks 6 days" when the reference time is 20 days 5 hours 21 minutes ahead of createdAt', function () { |
| const data = sampleBuildRequestData(); |
| const now = Date.now(); |
| data.buildRequests[0].createdAt = now - ((20 * 24 + 5) * 3600 + 21 * 60) * 1000; |
| const request = BuildRequest.constructBuildRequestsFromData(data)[0]; |
| assert.equal(request.waitingTime(now), '2 weeks 6 days'); |
| }); |
| |
| }); |
| |
| }); |