From 8f78d524896dae5cda446d59055351b71710a37a Mon Sep 17 00:00:00 2001 From: BAUVENT Kilian Date: Thu, 5 Sep 2024 15:54:46 +0200 Subject: [PATCH] test: ClosedTicketsMetricTest --- .../ClosedTicketsMetricTest.class.st | 42 +++++++++++++++++ .../GLPHImporterMock.class.st | 25 +++++++++-- .../JiraImporterMock.class.st | 45 +++++++++++++++++++ .../GLHUserCatalogueV2.class.st | 2 +- .../GPJCConnector.class.st | 1 - 5 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 src/GitLabHealth-Model-Analysis-Tests/ClosedTicketsMetricTest.class.st create mode 100644 src/GitLabHealth-Model-Analysis-Tests/JiraImporterMock.class.st diff --git a/src/GitLabHealth-Model-Analysis-Tests/ClosedTicketsMetricTest.class.st b/src/GitLabHealth-Model-Analysis-Tests/ClosedTicketsMetricTest.class.st new file mode 100644 index 0000000..9d81b52 --- /dev/null +++ b/src/GitLabHealth-Model-Analysis-Tests/ClosedTicketsMetricTest.class.st @@ -0,0 +1,42 @@ +" +A ClosedTicketsMetricTest is a test class for testing the behavior of ClosedTicketsMetric +" +Class { + #name : #ClosedTicketsMetricTest, + #superclass : #TestCase, + #category : #'GitLabHealth-Model-Analysis-Tests' +} + +{ #category : #tests } +ClosedTicketsMetricTest >> testCalculate [ + + | result glhImporter user closedTicket jiraImporter | + "Given" + user := GLHUser new + username: 'test'; + contributedProjects: + { (GLHProject new repository: GLHRepository new) }. + + glhImporter := GLPHImporterMock new. + glhImporter mergeRequests: { (GLPHEMergeRequest new + author: user; + created_at: '09-05-2024'; + title: '205 feat do something') }. + + jiraImporter := JiraImporterMock new. + jiraImporter issues: { (JPIssue new key: '205') }. + + + closedTicket := ClosedTicketsMetric new + user: user; + glhImporter: glhImporter; + jiraImporter: jiraImporter; + setPeriodSince: '09-04-2024' until: '09-04-2024'; + over: Week. + + "When" + result := closedTicket calculate. + + "Then" + self assert: result equals: 1 +] diff --git a/src/GitLabHealth-Model-Analysis-Tests/GLPHImporterMock.class.st b/src/GitLabHealth-Model-Analysis-Tests/GLPHImporterMock.class.st index 3e30da6..d5e860e 100644 --- a/src/GitLabHealth-Model-Analysis-Tests/GLPHImporterMock.class.st +++ b/src/GitLabHealth-Model-Analysis-Tests/GLPHImporterMock.class.st @@ -4,7 +4,8 @@ Class { #instVars : [ 'commits', 'commitDiffs', - 'mergeRequests' + 'mergeRequests', + 'glhModel' ], #category : #'GitLabHealth-Model-Analysis-Tests' } @@ -32,10 +33,23 @@ GLPHImporterMock >> completeImportedCommit: commit [ ^self ] +{ #category : #accessing } +GLPHImporterMock >> glhModel [ + + ^ glhModel +] + +{ #category : #accessing } +GLPHImporterMock >> glhModel: anObject [ + + glhModel := anObject +] + { #category : #commit } GLPHImporterMock >> importCommitsOProject: project since: since until: until [ - ^commits + glhModel addAll: commits. + ^ commits ] { #category : #'as yet unclassified' } @@ -46,8 +60,9 @@ GLPHImporterMock >> importCreatorOfCommit: commit [ { #category : #'import - merge request' } GLPHImporterMock >> importMergeRequests: project since: since until: until [ - ^mergeRequests - + + glhModel addAll: mergeRequests. + ^ mergeRequests ] { #category : #'import - merge request' } @@ -65,6 +80,8 @@ GLPHImporterMock >> initialize [ commits := OrderedCollection new. mergeRequests := OrderedCollection new. + +glhModel := GLPHEModel new name: 'model' ] { #category : #accessing } diff --git a/src/GitLabHealth-Model-Analysis-Tests/JiraImporterMock.class.st b/src/GitLabHealth-Model-Analysis-Tests/JiraImporterMock.class.st new file mode 100644 index 0000000..3ba29d2 --- /dev/null +++ b/src/GitLabHealth-Model-Analysis-Tests/JiraImporterMock.class.st @@ -0,0 +1,45 @@ +Class { + #name : #JiraImporterMock, + #superclass : #Object, + #instVars : [ + 'issues', + 'model' + ], + #category : #'GitLabHealth-Model-Analysis-Tests' +} + +{ #category : #'api - import' } +JiraImporterMock >> importAllCurrentAndPastIssuesOf: email [ + + model addAll: issues. + ^ issues +] + +{ #category : #initialization } +JiraImporterMock >> initialize [ + model := GLPHEModel new name: 'model' +] + +{ #category : #accessing } +JiraImporterMock >> issues [ + + ^ issues +] + +{ #category : #accessing } +JiraImporterMock >> issues: anObject [ + + issues := anObject +] + +{ #category : #accessing } +JiraImporterMock >> model [ + + ^ model +] + +{ #category : #accessing } +JiraImporterMock >> model: anObject [ + + model := anObject +] diff --git a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st index 8739277..5cc8bbd 100644 --- a/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st +++ b/src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st @@ -214,7 +214,7 @@ GLHUserCatalogueV2 >> exportToJson [ (#id -> assoc key id) } asDictionary); yourself ]." tempDic := Dictionary new. self associationsDo: [ :assoc | - |entry user names| + | entry user names | entry := assoc value. user := entry at: #user. names := entry at: #names. diff --git a/src/GitProject-JiraConnector/GPJCConnector.class.st b/src/GitProject-JiraConnector/GPJCConnector.class.st index 6237db5..c8c2222 100644 --- a/src/GitProject-JiraConnector/GPJCConnector.class.st +++ b/src/GitProject-JiraConnector/GPJCConnector.class.st @@ -24,7 +24,6 @@ Class { { #category : #accessing } GPJCConnector >> connect [ - (self gpModel allWithType: GLHCommit) do: [ :commit | self connectCommit: commit ]. (self gpModel allWithType: GLPHEMergeRequest) do: [ :mergeRequest |