]> source.dussan.org Git - sonarqube.git/commitdiff
Use new mocks in branch helper tests
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 25 Mar 2019 16:12:36 +0000 (17:12 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Mar 2019 08:44:57 +0000 (09:44 +0100)
server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts
server/sonar-web/src/main/js/helpers/testMocks.ts

index ef494587ddf5107a77c3568e92a41bdc605a0ad1..d84f430be0cd96d256051407e576cf746d846953 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import { sortBranchesAsTree, isSameBranchLike } from '../branches';
+import {
+  mockShortLivingBranch,
+  mockLongLivingBranch,
+  mockPullRequest,
+  mockMainBranch
+} from '../testMocks';
 
 describe('#sortBranchesAsTree', () => {
   it('sorts main branch and short-living branches', () => {
-    const main = mainBranch();
-    const foo = shortLivingBranch({ name: 'foo' });
-    const bar = shortLivingBranch({ name: 'bar' });
+    const main = mockMainBranch();
+    const foo = mockShortLivingBranch({ name: 'foo' });
+    const bar = mockShortLivingBranch({ name: 'bar' });
     expect(sortBranchesAsTree([main, foo, bar])).toEqual([main, bar, foo]);
   });
 
   it('sorts main branch and long-living branches', () => {
-    const main = mainBranch();
-    const foo = longLivingBranch({ name: 'foo' });
-    const bar = longLivingBranch({ name: 'bar' });
+    const main = mockMainBranch();
+    const foo = mockLongLivingBranch({ name: 'foo' });
+    const bar = mockLongLivingBranch({ name: 'bar' });
     expect(sortBranchesAsTree([main, foo, bar])).toEqual([main, bar, foo]);
   });
 
   it('sorts all types of branches', () => {
-    const main = mainBranch();
-    const shortFoo = shortLivingBranch({ name: 'shortFoo', mergeBranch: 'master' });
-    const shortBar = shortLivingBranch({ name: 'shortBar', mergeBranch: 'longBaz' });
-    const shortPre = shortLivingBranch({ name: 'shortPre', mergeBranch: 'shortFoo' });
-    const longBaz = longLivingBranch({ name: 'longBaz' });
-    const longQux = longLivingBranch({ name: 'longQux' });
-    const longQwe = longLivingBranch({ name: 'longQwe' });
-    const pr = pullRequest({ base: 'master' });
+    const main = mockMainBranch();
+    const shortFoo = mockShortLivingBranch({ name: 'shortFoo', mergeBranch: 'master' });
+    const shortBar = mockShortLivingBranch({ name: 'shortBar', mergeBranch: 'longBaz' });
+    const shortPre = mockShortLivingBranch({ name: 'shortPre', mergeBranch: 'shortFoo' });
+    const longBaz = mockLongLivingBranch({ name: 'longBaz' });
+    const longQux = mockLongLivingBranch({ name: 'longQux' });
+    const longQwe = mockLongLivingBranch({ name: 'longQwe' });
+    const pr = mockPullRequest({ base: 'master' });
     // - main                     - main
     //    - shortFoo                - shortFoo
     //      - shortPre              - shortPre
@@ -58,10 +64,10 @@ describe('#sortBranchesAsTree', () => {
 
 describe('#isSameBranchLike', () => {
   it('compares different kinds', () => {
-    const main = mainBranch();
-    const short = shortLivingBranch({ name: 'foo' });
-    const long = longLivingBranch({ name: 'foo' });
-    const pr = pullRequest();
+    const main = mockMainBranch();
+    const short = mockShortLivingBranch({ name: 'foo' });
+    const long = mockLongLivingBranch({ name: 'foo' });
+    const pr = mockPullRequest();
     expect(isSameBranchLike(main, pr)).toBeFalsy();
     expect(isSameBranchLike(main, short)).toBeFalsy();
     expect(isSameBranchLike(main, long)).toBeFalsy();
@@ -72,58 +78,31 @@ describe('#isSameBranchLike', () => {
 
   it('compares pull requests', () => {
     expect(
-      isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '1234' }))
+      isSameBranchLike(mockPullRequest({ key: '1234' }), mockPullRequest({ key: '1234' }))
     ).toBeTruthy();
     expect(
-      isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '5678' }))
+      isSameBranchLike(mockPullRequest({ key: '1234' }), mockPullRequest({ key: '5678' }))
     ).toBeFalsy();
   });
 
   it('compares branches', () => {
     expect(
-      isSameBranchLike(longLivingBranch({ name: 'foo' }), longLivingBranch({ name: 'foo' }))
+      isSameBranchLike(mockLongLivingBranch({ name: 'foo' }), mockLongLivingBranch({ name: 'foo' }))
     ).toBeTruthy();
     expect(
-      isSameBranchLike(shortLivingBranch({ name: 'foo' }), shortLivingBranch({ name: 'foo' }))
+      isSameBranchLike(
+        mockShortLivingBranch({ name: 'foo' }),
+        mockShortLivingBranch({ name: 'foo' })
+      )
     ).toBeTruthy();
     expect(
-      isSameBranchLike(longLivingBranch({ name: 'foo' }), longLivingBranch({ name: 'bar' }))
+      isSameBranchLike(mockLongLivingBranch({ name: 'foo' }), mockLongLivingBranch({ name: 'bar' }))
     ).toBeFalsy();
     expect(
-      isSameBranchLike(shortLivingBranch({ name: 'foo' }), shortLivingBranch({ name: 'bar' }))
+      isSameBranchLike(
+        mockShortLivingBranch({ name: 'foo' }),
+        mockShortLivingBranch({ name: 'bar' })
+      )
     ).toBeFalsy();
   });
 });
-
-function mainBranch(): T.MainBranch {
-  return { isMain: true, name: 'master' };
-}
-
-function shortLivingBranch(overrides?: Partial<T.ShortLivingBranch>): T.ShortLivingBranch {
-  const status = { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 };
-  return {
-    isMain: false,
-    mergeBranch: 'master',
-    name: 'foo',
-    status,
-    type: 'SHORT',
-    ...overrides
-  };
-}
-
-function longLivingBranch(overrides?: Partial<T.LongLivingBranch>): T.LongLivingBranch {
-  const status = { qualityGateStatus: 'OK' };
-  return { isMain: false, name: 'foo', status, type: 'LONG', ...overrides };
-}
-
-function pullRequest(overrides?: Partial<T.PullRequest>): T.PullRequest {
-  const status = { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 };
-  return {
-    base: 'master',
-    branch: 'feature',
-    key: '1234',
-    status,
-    title: 'Random Name',
-    ...overrides
-  };
-}
index a14df2435cce5171dc1758a6c2611ef9681d1e23..5ba89478c2ddb7c7f39d878999b5df8750c4101e 100644 (file)
@@ -387,3 +387,12 @@ export function mockDocumentationEntry(
     ...overrides
   };
 }
+
+export function mockMainBranch(overrides: Partial<T.MainBranch> = {}): T.MainBranch {
+  return {
+    analysisDate: '2018-01-01',
+    isMain: true,
+    name: 'master',
+    ...overrides
+  };
+}