Skip to content

Commit

Permalink
fix: problem when diffs got no hunks (#103)
Browse files Browse the repository at this point in the history
* fix: problem when diffs got no hunks + add tests

* test(BitBucketApiMock): change diffsNoHunks
  • Loading branch information
knowbased authored Oct 28, 2024
1 parent 22282a2 commit 0cb6f17
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 113 deletions.
96 changes: 63 additions & 33 deletions src/BitBucketHealth-Model-Importer-Tests/BitBucketApiMock.class.st
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
Class {
#name : 'BitBucketApiMock',
#superclass : 'Object',
#name : #BitBucketApiMock,
#superclass : #Object,
#instVars : [
'userMock',
'commits',
'diffs',
'mergeRequests'
],
#category : 'BitBucketHealth-Model-Importer-Tests',
#package : 'BitBucketHealth-Model-Importer-Tests'
#category : #'BitBucketHealth-Model-Importer-Tests'
}

{ #category : 'api - pull-requests' }
{ #category : #'api - pull-requests' }
BitBucketApiMock >> activitiesOfPullRequest: pullRequestId inRepoProjectId: repoSlug ofProjectGroupId: projectKey [

^self pullRequestActivities
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> commit2 [

| commits2 |
Expand Down Expand Up @@ -49,13 +48,13 @@ BitBucketApiMock >> commit2 [
^ commits2 := (NeoJSONReader on: commits2 readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> commits [

^ commits
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> commits1 [

| commits1 |
Expand Down Expand Up @@ -87,19 +86,19 @@ BitBucketApiMock >> commits1 [
^ commits1 := (NeoJSONReader on: commits1 readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> commits: anObject [

commits := anObject
]

{ #category : 'api - pull-requests' }
{ #category : #'api - pull-requests' }
BitBucketApiMock >> commitsOfPullRequest: mergeRequestId ofRepoProjectId: repoSlug inProjectGroupId: projectKey [

^commits
]

{ #category : 'api - projects' }
{ #category : #'api - projects' }
BitBucketApiMock >> commitsOfRepoProjectId: repositorySlug inProjectGroupId: projectKey since: since until: until [

^ self commits select: [ :commit |
Expand All @@ -111,7 +110,7 @@ BitBucketApiMock >> commitsOfRepoProjectId: repositorySlug inProjectGroupId: pro
commitDate >= since asDate and: commitDate <= until asDate ]
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> declinedMergeRequest [

| pullRequest |
Expand Down Expand Up @@ -307,13 +306,13 @@ BitBucketApiMock >> declinedMergeRequest [
^ pullRequest := (NeoJSONReader on: pullRequest readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffs [

^ diffs
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffs1 [

| diffs1 |
Expand Down Expand Up @@ -410,18 +409,49 @@ BitBucketApiMock >> diffs1 [
^ diffs1 := (NeoJSONReader on: diffs1 readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffs: anObject [

diffs := anObject
]

{ #category : 'api - commits' }
{ #category : #accessing }
BitBucketApiMock >> diffsNohunks [

| diffs1 |
diffs1 := '{
"fromHash": null,
"toHash": "123",
"contextLines": 10,
"whitespace": "SHOW",
"diffs": [
{
"source": null,
"destination": {
"components": [
"api",
"api.xlsx"
],
"parent": "api",
"name": "api.xlsx",
"extension": "xlsx",
"toString": "api/api.xlsx"
},
"binary": true
}
],
"truncated": false
}'.

^ diffs1 := (NeoJSONReader on: diffs1 readStream) next
]

{ #category : #'api - commits' }
BitBucketApiMock >> diffsOfCommit: commitID inRepoProjectId: repositorySlug inProjectGroupId: projectKey [
^diffs
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffsWithoutAdded [

| diffsWithoutAdded |
Expand Down Expand Up @@ -519,7 +549,7 @@ BitBucketApiMock >> diffsWithoutAdded [
diffsWithoutAdded readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffsWithoutHunks [

| diffsWithoutHunks |
Expand Down Expand Up @@ -559,7 +589,7 @@ BitBucketApiMock >> diffsWithoutHunks [
diffsWithoutHunks readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> diffsWithoutRemoved [

| diffsWithoutRemoved |
Expand Down Expand Up @@ -645,7 +675,7 @@ BitBucketApiMock >> diffsWithoutRemoved [
diffsWithoutRemoved readStream) next
]

{ #category : 'initialization' }
{ #category : #initialization }
BitBucketApiMock >> initialize [

commits := self commits1.
Expand All @@ -654,19 +684,19 @@ BitBucketApiMock >> initialize [
mergeRequests := { self openedMergeRequest }
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> mergeRequests [

^ mergeRequests
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> mergeRequests: anObject [

mergeRequests := anObject
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> mergedMergeRequest [

| pullRequest |
Expand Down Expand Up @@ -862,7 +892,7 @@ BitBucketApiMock >> mergedMergeRequest [
^ pullRequest := (NeoJSONReader on: pullRequest readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> openedMergeRequest [

| pullRequest |
Expand Down Expand Up @@ -1057,7 +1087,7 @@ BitBucketApiMock >> openedMergeRequest [
^pullRequest := (NeoJSONReader on: pullRequest readStream) next.
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> projects [

| projects |
Expand All @@ -1081,7 +1111,7 @@ BitBucketApiMock >> projects [
^ projects
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> pullRequestActivities [

| pullRequestActivities |
Expand Down Expand Up @@ -1112,13 +1142,13 @@ BitBucketApiMock >> pullRequestActivities [
pullRequestActivities readStream) next
]

{ #category : 'api - pull-requests' }
{ #category : #'api - pull-requests' }
BitBucketApiMock >> pullRequestsOfRepoProjectId: repoSlug inProjectGroupId: projectKey since: since until: until [

^ mergeRequests
]

{ #category : 'api - projects' }
{ #category : #'api - projects' }
BitBucketApiMock >> repositoryProjectsOfProjectGroupId: projectKey [

| repos |
Expand Down Expand Up @@ -1158,7 +1188,7 @@ repos := (NeoJSONReader on: repos readStream) next.
^repos
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> user1 [

| user1 |
Expand Down Expand Up @@ -1190,7 +1220,7 @@ BitBucketApiMock >> user1 [
^ user1 := (NeoJSONReader on: user1 readStream) next
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> user: accountId [

| user |
Expand All @@ -1205,19 +1235,19 @@ BitBucketApiMock >> user: accountId [
^ user
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> userMock [

^ userMock
]

{ #category : 'accessing' }
{ #category : #accessing }
BitBucketApiMock >> userMock: anObject [

userMock := anObject
]

{ #category : 'api - user' }
{ #category : #'api - user' }
BitBucketApiMock >> usersByUsername: username [

userMock ifNil: [ ^Array new ] ifNotNil: [ ^{ userMock }]
Expand Down
Loading

0 comments on commit 0cb6f17

Please sign in to comment.