Escape builder names in url* and pathFor* methods of BuildbotSyncer
[WebKit-https.git] / Websites / perf.webkit.org / server-tests / admin-reprocess-report-tests.js
1 'use strict';
2
3 const assert = require('assert');
4
5 const TestServer = require('./resources/test-server.js');
6 const addBuilderForReport = require('./resources/common-operations.js').addBuilderForReport;
7 const connectToDatabaseInEveryTest = require('./resources/common-operations.js').connectToDatabaseInEveryTest;
8
9 describe("/admin/reprocess-report", function () {
10     this.timeout(1000);
11     TestServer.inject();
12     connectToDatabaseInEveryTest();
13
14     const simpleReport = [{
15         "buildNumber": "1986",
16         "buildTime": "2013-02-28T10:12:03",
17         "builderName": "someBuilder",
18         "builderPassword": "somePassword",
19         "platform": "Mountain Lion",
20         "tests": {
21                 "test": {
22                     "metrics": {"FrameRate": { "current": [[1, 2, 3], [4, 5, 6]] }}
23                 },
24             },
25         }];
26
27     it("should add build", function (done) {
28         let db = TestServer.database();
29         let reportId;
30         addBuilderForReport(simpleReport[0]).then(function () {
31             return TestServer.remoteAPI().postJSON('/api/report/', simpleReport);
32         }).then(function (response) {
33             assert.equal(response['status'], 'OK');
34             return Promise.all([db.selectAll('builds'), db.selectAll('reports')]);
35         }).then(function (result) {
36             const builds = result[0];
37             const reports = result[1];
38             assert.equal(builds.length, 1);
39             assert.equal(builds[0]['number'], 1986);
40             assert.equal(reports.length, 1);
41             reportId = reports[0]['id'];
42             assert.equal(reports[0]['build_number'], 1986);
43             return db.query('UPDATE reports SET report_build = NULL; DELETE FROM builds');
44         }).then(function () {
45             return db.selectAll('builds');
46         }).then(function (builds) {
47             assert.equal(builds.length, 0);
48             return TestServer.remoteAPI().getJSONWithStatus(`/admin/reprocess-report?report=${reportId}`);
49         }).then(function () {
50             return db.selectAll('builds');
51         }).then(function (builds) {
52             assert.equal(builds.length, 1);
53             assert.equal(builds[0]['number'], 1986);
54             done();
55         }).catch(done);
56     });
57
58     it("should not duplicate the reprocessed report", function (done) {
59         let db = TestServer.database();
60         let originalReprot;
61         addBuilderForReport(simpleReport[0]).then(function () {
62             return TestServer.remoteAPI().postJSON('/api/report/', simpleReport);
63         }).then(function (response) {
64             assert.equal(response['status'], 'OK');
65             return db.selectAll('reports');
66         }).then(function (reports) {
67             assert.equal(reports.length, 1);
68             originalReprot = reports[0];
69             return db.query('UPDATE reports SET report_build = NULL; DELETE FROM builds');
70         }).then(function () {
71             return TestServer.remoteAPI().getJSONWithStatus(`/admin/reprocess-report?report=${originalReprot['id']}`);
72         }).then(function () {
73             return db.selectAll('reports');
74         }).then(function (reports) {
75             assert.equal(reports.length, 1);
76             const newPort = reports[0];
77             originalReprot['committed_at'] = null;
78             newPort['committed_at'] = null;
79             assert.notEqual(originalReprot['build'], newPort['build']);
80             originalReprot['build'] = null;
81             newPort['build'] = null;
82             assert.deepEqual(originalReprot, newPort);
83             done();
84         }).catch(done);
85     });
86 });