-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(ProjectDatabase): implement safe save functionality to prevent data loss #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
516e757
bd3c0b7
6d3d641
cfa9804
596254f
c534470
da6a753
2cee305
f29fbb5
0c9ce0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
|
|
||
| function Test_SaveProjectDatabase_SafeId_Flag_PrivateCall{ | ||
|
|
||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
|
|
||
| $Owner = "SomeOrg" ; $ProjectNumber = 164 | ||
| MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json' | ||
|
|
||
|
||
| # Call on private mode | ||
| $modulePath = $MODULE_PATH | Split-Path -Parent | ||
| $module = Import-Module -Name $modulePath -PassThru | ||
|
|
||
| & $module { | ||
| $Owner = "SomeOrg" ; $ProjectNumber = 164 | ||
| # Cache the project | ||
| $prj = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber | ||
|
|
||
|
|
||
| $prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber | ||
| Assert-IsNotNull -Object $prj.safeId | ||
|
|
||
|
||
| # Update project and the safeId should be updated | ||
| $oldSafeId = $prj.safeId | ||
| Save-ProjectDatabaseSafe -Database $prj | ||
| $prj2 = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber | ||
|
|
||
|
||
| Assert-IsNotNull -Object $prj2.safeId | ||
| Assert-AreNotEqual -Presented $oldSafeId -Expected $prj2.safeId | ||
| } | ||
|
|
||
| } | ||
|
|
||
| function Test_SaveProjectDatabase_Safe_PrivateCall{ | ||
|
|
||
| Reset-InvokeCommandMock | ||
| Mock_DatabaseRoot | ||
|
|
||
| $Owner = "SomeOrg" ; $ProjectNumber = 164 | ||
| MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json' | ||
|
|
||
|
||
| # Call on private mode | ||
| $modulePath = $MODULE_PATH | Split-Path -Parent | ||
| $module = Import-Module -Name $modulePath -PassThru | ||
|
|
||
| & $module { | ||
|
|
||
| $Owner = "SomeOrg" ; $ProjectNumber = 164 | ||
| # Cache the project | ||
| $prj1 = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber | ||
|
|
||
| # modify the project | ||
| $db = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber ; Save-ProjectDatabaseSafe -Database $db | ||
|
|
||
| # Check that safeId has changed | ||
| $prj2 = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber | ||
| Assert-AreNotEqual -Presented $prj2.safeId -Expected $prj1.safeId | ||
|
|
||
|
||
| ## When saving again as prj1 that has been saved before it will throw | ||
| $hasThrow = $false | ||
| try{ | ||
| Save-ProjectDatabaseSafe -Database $prj1 | ||
| } catch { | ||
| $hasThrow = $true | ||
| } | ||
| Assert-IsTrue -Condition $hasThrow | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| function Resolve-ProjectItem { | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory, Position = 0)][object]$Database, | ||
| [Parameter(Mandatory, Position = 1)][string]$ItemId, | ||
| [Parameter()][switch]$Force | ||
| ) | ||
|
|
||
| $dirty = $false | ||
|
|
||
| # Get Item to know what we are updating | ||
| $item = Get-Item -Database $Database -ItemId $ItemId | ||
|
|
||
| if (( ! $item ) -or $Force) { | ||
| "Fetching item [$ItemId] from API" | Write-Verbose | ||
|
|
||
Check noticeCode scanning / PSScriptAnalyzer Line has trailing whitespace Note
Line has trailing whitespace
|
||
| # Get direct. No cache as we are in a database modification context | ||
| $item = Get-ProjectItemDirect -ItemId $ItemId | ||
|
|
||
| if ( ! $item ) { | ||
| "Item [$ItemId] not found in API" | Write-MyError | ||
| return $null, $false | ||
|
||
| } | ||
|
|
||
| # Add to database | ||
| Set-Item $Database $item | ||
|
|
||
| # Get item again to allow the merge between staged and project fields | ||
| $item = Get-Item $Database $itemId | ||
|
|
||
| $dirty = $true | ||
| } | ||
|
|
||
| return $item, $dirty | ||
Check noticeCode scanning / PSScriptAnalyzer The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute. Note
The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute.
|
||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.