Commit should order by 'commit_order' as secondary key.
[WebKit.git] / Websites / perf.webkit.org / server-tests / api-commits.js
index a42c60dc767b880c547508ec4cd85535d39a8b79..4c7c0066d5872e567f495aac98a592584c54443a 100644 (file)
@@ -39,6 +39,43 @@ describe("/api/commits/", () => {
         ]
     }
 
+    const systemVersionCommits = {
+        "slaveName": "someSlave",
+        "slavePassword": "somePassword",
+        "commits": [
+            {
+                "repository": "OSX",
+                "revision": "16D32",
+                "order": 6
+            },
+            {
+                "repository": "OSX",
+                "revision": "16C68",
+                "order": 5
+            },
+            {
+                "repository": "OSX",
+                "revision": "16C67",
+                "order": 4
+            },
+            {
+                "repository": "OSX",
+                "revision": "16B2657",
+                "order": 3
+            },
+            {
+                "repository": "OSX",
+                "revision": "16B2555",
+                "order": 2
+            },
+            {
+                "repository": "OSX",
+                "revision": "16A323",
+                "order": 1
+            }
+        ]
+    }
+
     const notYetReportedCommit = {
         revision: '210951',
         time: '2017-01-20T03:56:20.045Z'
@@ -96,6 +133,26 @@ describe("/api/commits/", () => {
                 assert.equal(commits[2]['previousCommit'], commits[1]['id']);
             });
         });
+
+        it("should return the list of ordered commits for a given repository", () => {
+            return addSlaveForReport(subversionCommits).then(() => {
+                return TestServer.remoteAPI().postJSON('/api/report-commits/', systemVersionCommits);
+            }).then(function (response) {
+                assert.equal(response['status'], 'OK');
+                return TestServer.remoteAPI().getJSON('/api/commits/OSX/');
+            }).then(function (result) {
+                assert.equal(result['status'], 'OK');
+                const commits = result['commits'];
+                const submittedCommits = systemVersionCommits['commits'];
+                assert.equal(commits.length, submittedCommits.length);
+                assert.equal(commits[0]['revision'], submittedCommits[5]['revision']);
+                assert.equal(commits[1]['revision'], submittedCommits[4]['revision']);
+                assert.equal(commits[2]['revision'], submittedCommits[3]['revision']);
+                assert.equal(commits[3]['revision'], submittedCommits[2]['revision']);
+                assert.equal(commits[4]['revision'], submittedCommits[1]['revision']);
+                assert.equal(commits[5]['revision'], submittedCommits[0]['revision']);
+            });
+        });
     });
 
     describe('/api/commits/<repository>/oldest', () => {
@@ -126,6 +183,19 @@ describe("/api/commits/", () => {
                 assertCommitIsSameAsOneSubmitted(result['commits'][0], subversionCommits['commits'][0]);
             });
         });
+
+        it("should return the oldest commit based on 'commit_order' when 'commit_time' is missing", () => {
+            const remote = TestServer.remoteAPI();
+            return addSlaveForReport(systemVersionCommits).then(() => {
+                return remote.postJSONWithStatus('/api/report-commits/', systemVersionCommits);
+            }).then(() => {
+                return remote.getJSON('/api/commits/OSX/oldest');
+            }).then(function (result) {
+                assert.equal(result['status'], 'OK');
+                assert.equal(result['commits'].length, 1);
+                assert.equal(result['commits'][0]['revision'], systemVersionCommits['commits'][5]['revision']);
+            });
+        });
     });
 
     describe('/api/commits/<repository>/latest', () => {
@@ -156,6 +226,19 @@ describe("/api/commits/", () => {
                 assertCommitIsSameAsOneSubmitted(result['commits'][0], subversionCommits['commits'].slice().pop());
             });
         });
+
+        it("should return the latest commit based on 'commit_order' when 'commit_time' is missing", () => {
+            const remote = TestServer.remoteAPI();
+            return addSlaveForReport(systemVersionCommits).then(() => {
+                return remote.postJSONWithStatus('/api/report-commits/', systemVersionCommits);
+            }).then(() => {
+                return remote.getJSON('/api/commits/OSX/latest');
+            }).then(function (result) {
+                assert.equal(result['status'], 'OK');
+                assert.equal(result['commits'].length, 1);
+                assert.equal(result['commits'][0]['revision'], systemVersionCommits['commits'][0]['revision']);
+            });
+        });
     });
 
     describe('/api/commits/<repository>/last-reported', () => {
@@ -204,6 +287,19 @@ describe("/api/commits/", () => {
                 assertCommitIsSameAsOneSubmitted(result['commits'][0], subversionCommits['commits'].slice().pop());
             });
         });
+
+        it("should return the last reported commit based on 'commit_order' when 'commit_time' is missing", () => {
+            const remote = TestServer.remoteAPI();
+            return addSlaveForReport(systemVersionCommits).then(() => {
+                return remote.postJSONWithStatus('/api/report-commits/', systemVersionCommits);
+            }).then(() => {
+                return remote.getJSON('/api/commits/OSX/last-reported');
+            }).then(function (result) {
+                assert.equal(result['status'], 'OK');
+                assert.equal(result['commits'].length, 1);
+                assert.equal(result['commits'][0]['revision'], systemVersionCommits['commits'][0]['revision']);
+            });
+        });
     });
 
     describe('/api/commits/<repository>/<commit>', () => {