Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Test/private/MockCall_GitHubUpdateItemValues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function MockCall_GitHubUpdateItemValues {
function MockCall_GetItem{
[cmdletbinding()]
param(
[parameter(Mandatory)][string]$ItemId
[parameter(Mandatory, Position = 0)][string]$ItemId
)

$command = "Invoke-GetItem -ItemId $ItemId"
Expand Down
5 changes: 5 additions & 0 deletions Test/private/MockCall_Project700.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function Get-Mock_Project_700 {

$project.projectFile = "invoke-GitHubOrgProjectWithFields-octodemo-700.json"
$project.projectFile_skipitems = "invoke-GitHubOrgProjectWithFields-octodemo-700-skipitems.json"
$project.projectFile_WrongField = "invoke-GitHubOrgProjectWithFields-octodemo-700-skipitems-WrongField.json"

# Version of the project file modified manually to have two items with same id case sensitive
# this is used to test case sensitivity of item ids in hashtables
Expand All @@ -32,6 +33,10 @@ function Get-Mock_Project_700 {
$project.url = $pActual.url

# Fields info
$project.fields = @{}
$project.fields = @{ totalCount = $pActual.fields.nodes.Count + 2 } # Extra two Content fields Body and Comments. Title is removed from Fields and added as Content Field.
$project.fields.list = $pActual.fields.nodes | Select-Object name, datatype

$project.fieldtext = @{ id = $fieldtext.id ; name = $fieldtext.name }
$project.fieldnumber = @{ id = $fieldnumber.id ; name = $fieldnumber.name }
$project.fielddate = @{ id = $fielddate.id ; name = $fielddate.name }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"data": {
"organization": {
"projectV2": {
"number": 700,
"url": "https://github.com/orgs/octodemo/projects/700",
"shortDescription": "Project used as development environment by rulasg",
"public": false,
"closed": false,
"title": "rulasg-dev-700",
"id": "PVT_kwDOAlIw4c4BCe3V",
"readme": null,
"items": {
"pageInfo": {
"endCursor": null,
"hasNextPage": true
},
"totalCount": 28,
"nodes": []
},
"fields": {
"totalCount": 15,
"nodes": [
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-M",
"name": "Title",
"dataType": "TITLE"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-Q",
"name": "Assignees",
"dataType": "ASSIGNEES"
},
{
"__typename": "ProjectV2SingleSelectField",
"id": "PVTSSF_lADOAlIw4c4BCe3Vzg0rg-U",
"name": "Status",
"dataType": "SINGLE_SELECT",
"options": [
{
"id": "f75ad846",
"name": "Todo"
},
{
"id": "47fc9ee4",
"name": "In Progress"
},
{
"id": "98236657",
"name": "Done"
}
]
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-Y",
"name": "Labels",
"dataType": "LABELS"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-c",
"name": "Linked pull requests",
"dataType": "LINKED_PULL_REQUESTS"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-g",
"name": "Milestone",
"dataType": "MILESTONE"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-k",
"name": "Repository",
"dataType": "REPOSITORY"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-s",
"name": "Reviewers",
"dataType": "REVIEWERS"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-w",
"name": "Parent issue",
"dataType": "PARENT_ISSUE"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rg-0",
"name": "Sub-issues progress",
"dataType": "SUB_ISSUES_PROGRESS"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rhjU",
"name": "field-number",
"dataType": "NUMBER"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rhko",
"name": "Body",
"dataType": "TEXT"
},
{
"__typename": "ProjectV2Field",
"id": "PVTF_lADOAlIw4c4BCe3Vzg0rhlU",
"name": "AddComment",
"dataType": "TEXT"
},
{
"__typename": "ProjectV2SingleSelectField",
"id": "PVTSSF_lADOAlIw4c4BCe3Vzg0rhno",
"name": "field-singleselect",
"dataType": "SINGLE_SELECT",
"options": [
{
"id": "7d96a925",
"name": "option-1"
},
{
"id": "cd02c585",
"name": "option-2"
},
{
"id": "6b66c93a",
"name": "option-3"
}
]
},
{
"__typename": "ProjectV2IterationField",
"id": "PVTIF_lADOAlIw4c4BCe3Vzg0rhqQ",
"name": "field-iteration",
"dataType": "ITERATION"
}
],
"pageInfo": {
"endCursor": "MTU",
"hasNextPage": false
}
},
"owner": {
"__typename": "Organization",
"login": "octodemo"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"addComment": {
"commentEdge": {
"node": {
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3324995787"
"url": "https://github.com/octodemo/rulasg-dev-1/issues/26#issuecomment-3350059109"
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions Test/public/edit-sync-projectitem-comments.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Test_Edit_Sync_ProjectItem_AddComments_Issue {

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
Reset-InvokeCommandMock
Mock_DatabaseRoot

$p = Get-Mock_Project_700 ; $owner = $p.owner ; $projectNumber = $p.number
$i = $p.issue

$comment = "New comment"

MockCall_GetProject -MockProject $p -skipItems
MockCall_GetItem $i.id

MockCallJson -Command "Invoke-AddComment -SubjectId $($i.contentId) -Comment ""New comment""" -filename "invoke-addcomment-$($i.contentId).json"

# Act the edit part
Edit-ProjectItem -Owner $owner -ProjectNumber $projectNumber -ItemId $i.id -FieldName "AddComment" -Value $comment

# Assert the Edit part
$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-AreEqual -Expected $comment -Presented $staged.$($i.id).addcomment.Value

# Act the sync part
Sync-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber

$staged = Get-ProjectItemStaged -Owner $owner -ProjectNumber $projectNumber
Assert-Count -Expected 0 -Presented $staged.Count
}
12 changes: 6 additions & 6 deletions Test/public/issues/Add-IssuePullRequestComment.test.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

function Test_AddIssueComment_SUCCESS_Using_Cache{
function Test_AddComment_SUCCESS_Using_Cache{
Reset-InvokeCommandMock
Mock_DatabaseRoot

Expand All @@ -12,7 +12,7 @@ function Test_AddIssueComment_SUCCESS_Using_Cache{

Set-ProjectHelperEnvironment -Owner $owner -ProjectNumber $projectNumber -DisplayFields @("Status","FieldText")

MockCallJson -Command "Invoke-AddIssueComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addissuecomment-$contentId.json"
MockCallJson -Command "Invoke-AddComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addcomment-$contentId.json"

#Act
$result = Add-IssuePullRequestCommentDirect -ItemId $i.id -Comment $comment
Expand All @@ -21,7 +21,7 @@ function Test_AddIssueComment_SUCCESS_Using_Cache{
Assert-IsUrl -Presented $result
}

function Test_AddIssueComment_SUCCESS_Using_Direct{
function Test_AddComment_SUCCESS_Using_Direct{
Reset-InvokeCommandMock
Mock_DatabaseRoot

Expand All @@ -33,7 +33,7 @@ function Test_AddIssueComment_SUCCESS_Using_Direct{

MockCallJson -Command "Invoke-GetItem -ItemId $id" -FileName "invoke-getitem-$id.json"

MockCallJson -Command "Invoke-AddIssueComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addissuecomment-$contentId.json"
MockCallJson -Command "Invoke-AddComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addcomment-$contentId.json"

#Act
$result = Add-IssuePullRequestCommentDirect -ItemId $i.id -Comment $comment
Expand All @@ -42,7 +42,7 @@ function Test_AddIssueComment_SUCCESS_Using_Direct{
Assert-IsUrl -Presented $result
}

function Test_AddIssueComment_SUCCESS_Using_Direct_PR{
function Test_AddComment_SUCCESS_Using_Direct_PR{
Reset-InvokeCommandMock
Mock_DatabaseRoot

Expand All @@ -54,7 +54,7 @@ function Test_AddIssueComment_SUCCESS_Using_Direct_PR{

MockCallJson -Command "Invoke-GetItem -ItemId $id" -FileName "invoke-getitem-$id.json"

MockCallJson -Command "Invoke-AddIssueComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addissuecomment-$contentId.json"
MockCallJson -Command "Invoke-AddComment -SubjectId $contentId -Comment ""$comment""" -FileName "invoke-addcomment-$contentId.json"

#Act
$result = Add-IssuePullRequestCommentDirect -ItemId $i.id -Comment $comment
Expand Down
68 changes: 41 additions & 27 deletions Test/public/project_fields_list.test.ps1
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
function Test_GetProjectFields_SUCCESS{
function Test_GetProjectFields_SUCCESS_AllFields{

Reset-InvokeCommandMock
Mock_DatabaseRoot

$Owner = "SomeOrg" ; $ProjectNumber = 164

MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2-skipitems.json' -SkipItems
$p = Get-Mock_Project_700 ; $owner = $p.Owner ; $projectNumber = $p.Number
MockCall_GetProject -MockProject $p -SkipItems

$result = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber

Assert-Count -Expected 19 -Presented $result
Assert-Count -Expected $p.fields.totalCount -Presented $result

$result = $result | Sort-Object -Property Name

function AssertField($index, $expectedName, $expectedDataType, $expectedType){
Assert-AreEqual -Presented $result[$index].Name -Expected $expectedName
Assert-AreEqual -Presented $result[$index].dataType -Expected $expectedDataType
foreach ($expField in $p.fields.list){
$f = $result | Where-Object { $_.Name -eq $expField.Name }

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
Assert-AreEqual -Presented $f.Name -Expected $expField.Name
Assert-AreEqual -Presented $f.dataType -Expected $expField.dataType
}

# Body
$f = $result | Where-Object { $_.Name -eq "Body" }
Assert-AreEqual -Presented $f.Name -Expected "Body"
Assert-AreEqual -Presented $f.dataType -Expected "BODY"

# AddComment
$f = $result | Where-Object { $_.Name -eq "AddComment" }
Assert-AreEqual -Presented $f.Name -Expected "AddComment"
Assert-AreEqual -Presented $f.dataType -Expected "ADDCOMMENT"

}

function Test_GetProjectFields_Fail_Comments_Present{

Reset-InvokeCommandMock
Mock_DatabaseRoot

$p = Get-Mock_Project_700 ; $owner = $p.Owner ; $projectNumber = $p.Number

MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName $p.projectFile_WrongField -SkipItems

$hasthrow = $false
try{
$null = Get-ProjectFields -Owner $owner -ProjectNumber $projectNumber
} catch {
$hasthrow = $true
$resultErrorMessage = $_.Exception.Message
}
Assert-IsTrue -Condition $hasthrow

AssertField -Index 0 -ExpectedName "Assignees" -ExpectedDataType "ASSIGNEES"
AssertField -Index 1 -ExpectedName "Body" -ExpectedDataType "BODY"
AssertField -Index 2 -ExpectedName "Comment" -ExpectedDataType "TEXT"
AssertField -Index 3 -ExpectedName "End Date" -ExpectedDataType "DATE"
AssertField -Index 4 -ExpectedName "Labels" -ExpectedDataType "LABELS"
AssertField -Index 5 -ExpectedName "Linked pull requests" -ExpectedDataType "LINKED_PULL_REQUESTS"
AssertField -Index 6 -ExpectedName "Milestone" -ExpectedDataType "MILESTONE"
AssertField -Index 7 -ExpectedName "Next Action Date" -ExpectedDataType "DATE"
AssertField -Index 8 -ExpectedName "Priority" -ExpectedDataType "SINGLE_SELECT"
AssertField -Index 9 -ExpectedName "Repository" -ExpectedDataType "REPOSITORY"
AssertField -Index 10 -ExpectedName "Reviewers" -ExpectedDataType "REVIEWERS"
AssertField -Index 11 -ExpectedName "Severity" -ExpectedDataType "SINGLE_SELECT"
AssertField -Index 12 -ExpectedName "Start Date" -ExpectedDataType "DATE"
AssertField -Index 13 -ExpectedName "Status" -ExpectedDataType "SINGLE_SELECT"
AssertField -Index 14 -ExpectedName "TimeTracker" -ExpectedDataType "NUMBER"
AssertField -Index 15 -ExpectedName "Title" -ExpectedDataType "TITLE"
AssertField -Index 16 -ExpectedName "Tracked by" -ExpectedDataType "TRACKED_BY"
AssertField -Index 17 -ExpectedName "Tracks" -ExpectedDataType "TRACKS"
AssertField -Index 18 -ExpectedName "UserStories" -ExpectedDataType "NUMBER"
$errorMessage = "Set-ContentFields: [ Body ] field already exists. Please remove or rename this field from the project"
Assert-AreEqual -Expected $errorMessage -Presented $resultErrorMessage
}

function Test_GetProjectFields_SUCCESS_FilterByName{
Expand Down
Loading