-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from spaceheroes/feature/commit-trigger
Diff scan flow improvements
- Loading branch information
Showing
17 changed files
with
773 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
force-app/main/default/classes/GetClaytonProjectIdFromUserStoryId.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public with sharing class GetClaytonProjectIdFromUserStoryId { | ||
|
||
@InvocableMethod(label='GetClaytonProjectIdFromUserStoryId' description='Get Clayton Project Id from User Story Id') | ||
public static List<Response> GetClaytonProjectIdFromUserStoryId(List<Request> requests) { | ||
Request request = requests[0]; | ||
List<clayton__ClaytonSettings__c> claytonSettings = [select clayton__ProjectId__c from clayton__ClaytonSettings__c limit 1]; | ||
String customSettingProjectId = claytonSettings[0].clayton__ProjectId__c; | ||
|
||
List<copado__Project__c> projects = [select Clayton_Project_Id__c from copado__Project__c where Id IN (select copado__Project__c from copado__User_Story__c where Id=:request.userStoryId) limit 1]; | ||
copado__Project__c project = projects[0]; | ||
|
||
List<Response> responses = new List<Response>(); | ||
Response response = new Response(); | ||
response.projectId = String.isBlank(project.Clayton_Project_Id__c) ? customSettingProjectId : project.Clayton_Project_Id__c; | ||
responses.add(response); | ||
return responses; | ||
} | ||
|
||
@TestVisible | ||
public class Request{ | ||
|
||
@InvocableVariable | ||
public String userStoryId; | ||
|
||
} | ||
|
||
@TestVisible | ||
public class Response{ | ||
|
||
@InvocableVariable | ||
public String projectId; | ||
|
||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/GetClaytonProjectIdFromUserStoryId.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
64 changes: 64 additions & 0 deletions
64
force-app/main/default/classes/GetClaytonProjectIdFromUserStoryIdTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@isTest | ||
public class GetClaytonProjectIdFromUserStoryIdTest { | ||
|
||
@isTest | ||
public static void testReadFromUserStory() { | ||
|
||
// Given | ||
String projectId = 'd8959b82-0154-4156-89ea-bd303f4083ea'; | ||
clayton__ClaytonSettings__c customSettings = new clayton__ClaytonSettings__c(); | ||
customSettings.clayton__ProjectId__c='c56dea19-1cce-431f-891f-d6dea0a0fc26'; | ||
customSettings.clayton__AccountId__c='ca6e81ac-5c10-4e11-88ee-6ff4a01f913e'; | ||
insert customSettings; | ||
copado__Project__c project = new copado__Project__c(); | ||
project.Clayton_Project_Id__c = projectId; | ||
insert project; | ||
copado__User_Story__c userStory = new copado__User_Story__c(); | ||
userStory.copado__Project__c = project.Id; | ||
insert userStory; | ||
|
||
|
||
List<GetClaytonProjectIdFromUserStoryId.Request> requests = new List<GetClaytonProjectIdFromUserStoryId.Request>(); | ||
GetClaytonProjectIdFromUserStoryId.Request request = new GetClaytonProjectIdFromUserStoryId.Request(); | ||
request.userStoryId = userStory.Id; | ||
requests.add(request); | ||
|
||
// When | ||
List<GetClaytonProjectIdFromUserStoryId.Response> responses = GetClaytonProjectIdFromUserStoryId.GetClaytonProjectIdFromUserStoryId(requests); | ||
|
||
// Then | ||
GetClaytonProjectIdFromUserStoryId.Response response = responses[0]; | ||
System.assertEquals(response.projectId, projectId, 'Project Id read from user story'); | ||
} | ||
|
||
@isTest | ||
public static void testFallbackCustomSetting() { | ||
|
||
// Given | ||
String projectId = 'd8959b82-0154-4156-89ea-bd303f4083ea'; | ||
clayton__ClaytonSettings__c customSettings = new clayton__ClaytonSettings__c(); | ||
customSettings.clayton__ProjectId__c=projectId; | ||
customSettings.clayton__AccountId__c='ca6e81ac-5c10-4e11-88ee-6ff4a01f913e'; | ||
insert customSettings; | ||
copado__Project__c project = new copado__Project__c(); | ||
project.Clayton_Project_Id__c = ''; | ||
insert project; | ||
copado__User_Story__c userStory = new copado__User_Story__c(); | ||
userStory.copado__Project__c = project.Id; | ||
insert userStory; | ||
|
||
|
||
List<GetClaytonProjectIdFromUserStoryId.Request> requests = new List<GetClaytonProjectIdFromUserStoryId.Request>(); | ||
GetClaytonProjectIdFromUserStoryId.Request request = new GetClaytonProjectIdFromUserStoryId.Request(); | ||
request.userStoryId = userStory.Id; | ||
requests.add(request); | ||
|
||
// When | ||
List<GetClaytonProjectIdFromUserStoryId.Response> responses = GetClaytonProjectIdFromUserStoryId.GetClaytonProjectIdFromUserStoryId(requests); | ||
|
||
// Then | ||
GetClaytonProjectIdFromUserStoryId.Response response = responses[0]; | ||
System.assertEquals(response.projectId, projectId, 'Project Id read from custom settings when not available at user story level'); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/GetClaytonProjectIdFromUserStoryIdTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
34 changes: 34 additions & 0 deletions
34
force-app/main/default/classes/GetTargetBranchFromUserStoryId.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public with sharing class GetTargetBranchFromUserStoryId { | ||
|
||
@InvocableMethod(label='GetTargetBranchFromUserStoryId' description='Get Branch Name from User Story Id') | ||
public static List<Response> GetTargetBranchFromUserStoryId(List<Request> requests) { | ||
Request request = requests[0]; | ||
List<clayton__ClaytonSettings__c> claytonSettings = [select TargetBranch__c from clayton__ClaytonSettings__c LIMIT 1]; | ||
String customSettingsTargetBranch = String.isBlank(claytonSettings[0].TargetBranch__c) ? 'main' : claytonSettings[0].TargetBranch__c; | ||
|
||
List<copado__User_Story__c> userStories = [SELECT copado__Base_Branch__c from copado__User_Story__c where Id=:request.userStoryId LIMIT 1]; | ||
copado__User_Story__c userStory = userStories[0]; | ||
|
||
List<Response> responses = new List<Response>(); | ||
Response response = new Response(); | ||
response.targetBranch = String.isBlank(userStory.copado__Base_Branch__c) ? customSettingsTargetBranch : userStory.copado__Base_Branch__c; | ||
responses.add(response); | ||
return responses; | ||
} | ||
|
||
@TestVisible | ||
public class Request{ | ||
|
||
@InvocableVariable | ||
public String userStoryId; | ||
|
||
} | ||
|
||
@TestVisible | ||
public class Response{ | ||
|
||
@InvocableVariable | ||
public String targetBranch; | ||
|
||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/GetTargetBranchFromUserStoryId.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
88 changes: 88 additions & 0 deletions
88
force-app/main/default/classes/GetTargetBranchFromUserStoryIdTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
@isTest | ||
public class GetTargetBranchFromUserStoryIdTest { | ||
|
||
@isTest | ||
public static void testReadFromUserStory() { | ||
|
||
// Given | ||
String targetBranch = 'dev'; | ||
clayton__ClaytonSettings__c customSettings = new clayton__ClaytonSettings__c(); | ||
customSettings.TargetBranch__c = 'main'; | ||
customSettings.clayton__ProjectId__c='123'; | ||
customSettings.clayton__AccountId__c='123'; | ||
insert customSettings; | ||
copado__User_Story__c userStory = new copado__User_Story__c(); | ||
userStory.copado__Base_Branch__c = targetBranch; | ||
insert userStory; | ||
|
||
|
||
List<GetTargetBranchFromUserStoryId.Request> requests = new List<GetTargetBranchFromUserStoryId.Request>(); | ||
GetTargetBranchFromUserStoryId.Request request = new GetTargetBranchFromUserStoryId.Request(); | ||
request.userStoryId = userStory.Id; | ||
requests.add(request); | ||
|
||
// When | ||
List<GetTargetBranchFromUserStoryId.Response> responses = GetTargetBranchFromUserStoryId.GetTargetBranchFromUserStoryId(requests); | ||
|
||
// Then | ||
GetTargetBranchFromUserStoryId.Response response = responses[0]; | ||
System.assertEquals(response.targetBranch, targetBranch, 'Target branch read from user story'); | ||
} | ||
|
||
@isTest | ||
public static void testFallbackCustomSetting() { | ||
|
||
// Given | ||
String targetBranch = 'main'; | ||
clayton__ClaytonSettings__c customSettings = new clayton__ClaytonSettings__c(); | ||
customSettings.TargetBranch__c = targetBranch; | ||
customSettings.clayton__ProjectId__c='123'; | ||
customSettings.clayton__AccountId__c='123'; | ||
insert customSettings; | ||
copado__User_Story__c userStory = new copado__User_Story__c(); | ||
userStory.copado__Base_Branch__c = ''; | ||
insert userStory; | ||
|
||
|
||
List<GetTargetBranchFromUserStoryId.Request> requests = new List<GetTargetBranchFromUserStoryId.Request>(); | ||
GetTargetBranchFromUserStoryId.Request request = new GetTargetBranchFromUserStoryId.Request(); | ||
request.userStoryId = userStory.Id; | ||
requests.add(request); | ||
|
||
// When | ||
List<GetTargetBranchFromUserStoryId.Response> responses = GetTargetBranchFromUserStoryId.GetTargetBranchFromUserStoryId(requests); | ||
|
||
// Then | ||
GetTargetBranchFromUserStoryId.Response response = responses[0]; | ||
System.assertEquals(response.targetBranch, targetBranch, 'Target branch read from custom settings when not available at user story level'); | ||
} | ||
|
||
@isTest | ||
public static void testDefaultValue() { | ||
|
||
// Given | ||
String defaultTargetBranch = 'main'; | ||
clayton__ClaytonSettings__c customSettings = new clayton__ClaytonSettings__c(); | ||
customSettings.TargetBranch__c = ''; | ||
customSettings.clayton__ProjectId__c='123'; | ||
customSettings.clayton__AccountId__c='123'; | ||
insert customSettings; | ||
copado__User_Story__c userStory = new copado__User_Story__c(); | ||
userStory.copado__Base_Branch__c = ''; | ||
insert userStory; | ||
|
||
|
||
List<GetTargetBranchFromUserStoryId.Request> requests = new List<GetTargetBranchFromUserStoryId.Request>(); | ||
GetTargetBranchFromUserStoryId.Request request = new GetTargetBranchFromUserStoryId.Request(); | ||
request.userStoryId = userStory.Id; | ||
requests.add(request); | ||
|
||
// When | ||
List<GetTargetBranchFromUserStoryId.Response> responses = GetTargetBranchFromUserStoryId.GetTargetBranchFromUserStoryId(requests); | ||
|
||
// Then | ||
GetTargetBranchFromUserStoryId.Response response = responses[0]; | ||
System.assertEquals(response.targetBranch, defaultTargetBranch, 'Default Target branch when not available at custom settings and user story levels'); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/GetTargetBranchFromUserStoryIdTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>55.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.