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
39 changes: 39 additions & 0 deletions Test/include/callPrivateContext.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# CALL PRIVATE FUNCTIONS
#
# This file enables tests to invoke private (non-exported) functions
# defined inside the main module by evaluating a provided scriptblock
# in the module context.
#
# It relies on variables initialized by module.helper.ps1.
# REQUIRED:
# $MODULE_PATH - Full path to the module .psm1 file (or a file inside its folder)
#
# THIS INCLUDE REQUIRES module.helper.ps1
if(-not $MODULE_PATH){ throw "Missing MODULE_PATH variable initialization. Check for module.helper.ps1 file." }

function Invoke-PrivateContext {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Invoke-PrivateContext' does not have a help comment. Note

The cmdlet 'Invoke-PrivateContext' does not have a help comment.
param (
[Parameter(Mandatory, Position = 0)]
[scriptblock]$ScriptBlock,
[string]$ModulePath,
[string[]]$Arguments
)

if ([string]::IsNullOrEmpty($ModulePath)) {
$modulePath = $MODULE_PATH | Split-Path -Parent
}

$module = Import-Module -Name $modulePath -PassThru

if ($null -eq $module) {
throw "Failed to import the main module."
}

if($Arguments){
& $module $ScriptBlock -Arguments $Arguments
}
else {
& $module $ScriptBlock
}

} Export-ModuleMember -Function Invoke-PrivateContext
4 changes: 4 additions & 0 deletions Test/mockfiles.log
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
{
"Command": "Get-ProjectItems -owner githubcustomers -projectNumber 3023 -IncludeDone",
"FileName": "get-projectitems-githubcustomers-3023.json"
},
{
"FileName": "testuser-search-repos.json",
"Command": "Invoke-SearchRepo -SearchString \"org:githubcustomers props.SolutionEngineer:testuser\""
}
]
90 changes: 90 additions & 0 deletions Test/private/mocks/testuser-search-repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"name": "Santander",
"url": "https://github.com/githubcustomers/Santander"
},
{
"name": "santander-cybersecurity",
"url": "https://github.com/githubcustomers/santander-cybersecurity"
},
{
"name": "ECI",
"url": "https://github.com/githubcustomers/ECI"
},
{
"name": "iberdrola",
"url": "https://github.com/githubcustomers/iberdrola"
},
{
"name": "indra-mobility",
"url": "https://github.com/githubcustomers/indra-mobility"
},
{
"name": "adevinta-motor",
"url": "https://github.com/githubcustomers/adevinta-motor"
},
{
"name": "bit21",
"url": "https://github.com/githubcustomers/bit21"
},
{
"name": "santander-internal",
"url": "https://github.com/githubcustomers/santander-internal"
},
{
"name": "bbva-global-security",
"url": "https://github.com/githubcustomers/bbva-global-security"
},
{
"name": "indra",
"url": "https://github.com/githubcustomers/indra"
},
{
"name": "bbva-internal",
"url": "https://github.com/githubcustomers/bbva-internal"
},
{
"name": "mapfre",
"url": "https://github.com/githubcustomers/mapfre"
},
{
"name": "microsoft-spain-internal",
"url": "https://github.com/githubcustomers/microsoft-spain-internal"
},
{
"name": "inditex",
"url": "https://github.com/githubcustomers/inditex"
},
{
"name": "indra-group",
"url": "https://github.com/githubcustomers/indra-group"
},
{
"name": "sw-se-team",
"url": "https://github.com/githubcustomers/sw-se-team"
},
{
"name": "bbva-accenture",
"url": "https://github.com/githubcustomers/bbva-accenture"
},
{
"name": "bbva",
"url": "https://github.com/githubcustomers/bbva"
},
{
"name": "santander-global-tech",
"url": "https://github.com/githubcustomers/santander-global-tech"
},
{
"name": "kk",
"url": "https://github.com/githubcustomers/kk"
},
{
"name": "caixabank",
"url": "https://github.com/githubcustomers/caixabank"
},
{
"name": "EPO",
"url": "https://github.com/githubcustomers/EPO"
}
]
7 changes: 6 additions & 1 deletion Test/private/run_BeforeAfter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
function Run_BeforeEach{
# Write-Verbose "Run_BeforeEach"
Reset-InvokeCommandMock


Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
Invoke-PrivateContext {
# Clear the repo list cache to ensure tests are isolated
$script:projectlist = $null
$script:repoList = @{}
}
}

# function Run_AfterEach{
Expand Down
4 changes: 4 additions & 0 deletions Test/public/items/GcProjectItems.test.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function Test_GetProjectItems_Success{

MockCall_GetAllItems
MockCall_GetGcReposMy

# All
# Act
Expand Down Expand Up @@ -52,7 +53,10 @@

function MockCall_GetAllItems{

# GetMyHandle
MockCallToString -Command 'gh api user --jq ".login"' -OutString 'testuser'

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Get-AllItems
MockCallJson -Command "Find-Project -owner githubcustomers -pattern creator:testuser" -filename "testuser-find-project-3.json"
MockCall_GetProject 2683 ; MockCall_GetProject 2988 ; MockCall_GetProject 3023

Expand Down
18 changes: 0 additions & 18 deletions Test/public/items/GcProjects.test.ps1

This file was deleted.

62 changes: 62 additions & 0 deletions Test/public/projects/GcProjects.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Test_GetGcProjects {

MockCallToString -Command 'gh api user --jq ".login"' -OutString 'testuser'

MockCallJson -Command "Find-Project -owner githubcustomers -pattern creator:testuser" -filename "testuser-find-project.json"

$projects = Get-GcProjects

Assert-Count -Expected 16 -Presented $projects

# Pick one random and check the structure
$testProject = $projects."bit21"
Assert-AreEqual -Expected "bit21" -Presented $testProject.Title
Assert-AreEqual -Expected "githubcustomers" -Presented $testProject.Owner
Assert-AreEqual -Expected 2683 -Presented $testProject.ProjectNumber
Assert-AreEqual -Expected "https://github.com/orgs/githubcustomers/projects/2683" -Presented $testProject.Url

}

function Test_GetGcProjects_Success{

# Arrange
MockCall_GetGcProjects

# Act
$result = Get-GcProjects

# Assert
Assert-Count -Expected 3 -Presented $result.Keys
Assert-Contains -Presented $result.Keys -Expected "Customer_1"
Assert-Contains -Presented $result.Keys -Expected "_TEMPLATE__Customer_Project"
Assert-Contains -Presented $result.Keys -Expected "BiT21"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Verify structure of one project
Assert-AreEqual -Expected "BiT21" -Presented $result.BiT21.Title
Assert-AreEqual -Expected "githubcustomers" -Presented $result.BiT21.Owner
Assert-AreEqual -Expected 2683 -Presented $result.BiT21.ProjectNumber
Assert-AreEqual -Expected "https://github.com/orgs/githubcustomers/projects/2683" -Presented $result.BiT21.Url
}

function Test_GetGcProjects_WithForce{

# Arrange
MockCall_GetGcProjects

# Act - First call
$result1 = Get-GcProjects
# Act - Second call without Force (should use cache)
$result2 = Get-GcProjects
# Act - Third call with Force (should refresh)
$result3 = Get-GcProjects -Force

# Assert
Assert-Count -Expected 3 -Presented $result1.Keys
Assert-Count -Expected 3 -Presented $result2.Keys
Assert-Count -Expected 3 -Presented $result3.Keys
}

function MockCall_GetGcProjects{
MockCallToString -Command 'gh api user --jq ".login"' -OutString 'testuser'
MockCallJson -Command "Find-Project -owner githubcustomers -pattern creator:testuser" -filename "testuser-find-project-3.json"
}
61 changes: 61 additions & 0 deletions Test/public/repos/getrepos.test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Test_GetGcReposMy_Success{

# Arrange
MockCall_GetGcReposMy

# Act
$result = Get-GcReposMy

# Assert
Assert-Count -Expected 22 -Presented $result.Keys
Assert-Contains -Presented $result.Keys -Expected "kk"
Assert-Contains -Presented $result.Keys -Expected "bit21"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Verify structure of one repo
Assert-AreEqual -Expected "bit21" -Presented $result.bit21.name
Assert-AreEqual -Expected "https://github.com/githubcustomers/bit21" -Presented $result.bit21.url
}

function Test_GetGcReposMy_WithForce{

# Arrange
MockCall_GetGcReposMy

# Act - First call
$result1 = Get-GcReposMy
# Act - Second call without Force (should use cache)
$result2 = Get-GcReposMy
# Act - Third call with Force (should refresh)
$result3 = Get-GcReposMy -Force

# Assert
Assert-Count -Expected 22 -Presented $result1.Keys
Assert-Count -Expected 22 -Presented $result2.Keys
Assert-Count -Expected 22 -Presented $result3.Keys
}

function Test_GetGcRepos_Success{

# Arrange
MockCall_SearchRepos

# Act
$result = Get-GcRepos -PropertyValue "testuser"

# Assert
Assert-Count -Expected 22 -Presented $result.Keys
Assert-Contains -Presented $result.Keys -Expected "kk"
Assert-Contains -Presented $result.Keys -Expected "bit21"
}

function MockCall_GetGcReposMy{
# GetMyHandle
MockCallToString -Command 'gh api user --jq ".login"' -OutString 'testuser'

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# SearchRepos
MockCall_SearchRepos
}

function MockCall_SearchRepos{
MockCallJson -Command 'Invoke-SearchRepo -SearchString "org:githubcustomers props.SolutionEngineer:testuser"' -filename "testuser-search-repos.json"
}
8 changes: 8 additions & 0 deletions include/MyHandle.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
Set-MyInvokeCommandAlias -Alias GetGhHandle -Command 'gh api user --jq ".login"'

$Script:myHandle = $null

function Get-MyHandle{
[CmdletBinding()]
param()

if($null -ne $Script:myHandle){
return $Script:myHandle
}

$user = Invoke-MyCommand -Command GetGhHandle

$Script:myHandle = $user

return $user
}
26 changes: 0 additions & 26 deletions public/getrepos.ps1

This file was deleted.

Loading
Loading