Fix various bugs in the new syncing script
[WebKit.git] / Websites / perf.webkit.org / server-tests / resources / common-operations.js
1
2 const crypto = require('crypto');
3
4 function addBuilderForReport(report)
5 {
6     return TestServer.database().insert('builders', {
7         name: report.builderName,
8         password_hash: crypto.createHash('sha256').update(report.builderPassword).digest('hex')
9     });
10 }
11
12 function addSlaveForReport(report)
13 {
14     return TestServer.database().insert('build_slaves', {
15         name: report.slaveName,
16         password_hash: crypto.createHash('sha256').update(report.slavePassword).digest('hex')
17     });
18 }
19
20 function connectToDatabaseInEveryTest()
21 {
22     beforeEach(function () {
23         TestServer.database().connect({keepAlive: true});
24     });
25
26     afterEach(function () {
27         TestServer.database().disconnect();
28     });
29 }
30
31 function submitReport(report)
32 {
33     return TestServer.database().insert('builders', {
34         name: report[0].builderName,
35         password_hash: crypto.createHash('sha256').update(report[0].builderPassword).digest('hex')
36     }).then(function () {
37         return TestServer.remoteAPI().postJSON('/api/report/', report);
38     });
39 }
40
41 if (typeof module != 'undefined') {
42     module.exports.addBuilderForReport = addBuilderForReport;
43     module.exports.addSlaveForReport = addSlaveForReport;
44     module.exports.connectToDatabaseInEveryTest = connectToDatabaseInEveryTest;
45     module.exports.submitReport = submitReport;
46 }