Skip to content
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

feat: Add ExpiryDate to tips to remove them after they are no longer relavent #49

Merged
merged 8 commits into from
Feb 5, 2024
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
This page is a list of _notable_ changes made in each version.
Every time a tip is added the patch version is incremented, so there will be a lot of patch version changes not documented here.

## v1.1.0 - February 4, 2024

Features:

- Added an `ExpiryDate` property to the `PowerShellTip` class to allow tips to be automatically removed after a certain date.
This is useful for tips that are no longer relevant after a certain date, such as tips about a specific event or conference.

## v1.0.0 - October 16, 2023

Features:
Expand Down
14 changes: 12 additions & 2 deletions build/Convert-PowerShellTipFilesToJsonFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Write-Verbose "Finding all PowerShell tip files in '$powerShellTipsDirectoryPath

[System.Collections.ArrayList] $tips = @()
[int] $numberOfTipFiles = $tipFilePaths.Count
[int] $numberOfExpiredTipFiles = 0

Write-Verbose "Reading in and validating $numberOfTipFiles PowerShell tip files."
foreach ($tipFilePath in $tipFilePaths)
Expand All @@ -37,13 +38,22 @@ foreach ($tipFilePath in $tipFilePaths)

$tip.TrimAllProperties()
$tip.Validate()

if ($tip.ExpiryDate -lt [DateTime]::Today)
{
Write-Verbose "Skipping expired tip: $($tip.Title)"
$numberOfExpiredTipFiles++
continue
}

$tips.Add($tip) > $null
}

[int] $numberOfTips = $tips.Count
if ($numberOfTips -ne $numberOfTipFiles)
[int] $numberOfNonExpiredTipFiles = $numberOfTipFiles - $numberOfExpiredTipFiles
if ($numberOfTips -ne $numberOfNonExpiredTipFiles)
{
throw "Found $numberOfTipFiles tip files, but read in $numberOfTips tips. The number of tip files and tips should match."
throw "Found $numberOfNonExpiredTipFiles non-expired tip files ($numberOfTipFiles files, but $numberOfExpiredTipFiles were expired), but read in $numberOfTips tips. The number of non-expired tip files and tips should match."
}

if ($numberOfTips -eq 0)
Expand Down
12 changes: 12 additions & 0 deletions deploy/Invoke-SmokeTests.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# These tests are runs as part of the deployment process to ensure the newly published module is working as expected.
# These tests run against the installed module, not the source code, so they do not use mocks and are more of a real-world test.
# Since mocks are not used, we must be careful to not rely on state stored on the machine, such as the module Configuration file.
# To run these tests on your local machine, see the comments in the BeforeAll block.

BeforeAll {
Import-Module -Name tiPS -Force

# To run these tests on your local machine, comment out the Import-Module command above and uncomment the one below.
# Do this to use the module version from source code, not the installed version.
# This is necessary to test functionality that you've added to the module, but have not yet published and installed.
# Import-Module "$PSScriptRoot\..\src\tiPS" -Force
}

Describe 'Get-PowerShellTip' {
Expand Down Expand Up @@ -34,6 +40,12 @@ Describe 'Get-PowerShellTip' {
$allTips | Should -Not -BeNullOrEmpty
$allTips.Count | Should -BeGreaterThan 2
}

It 'Should not return any expired tips, as they should have been removed during initialization' {
$allTips = Get-PowerShellTip -All
$expiredTips = $allTips.Values | Where-Object { $_.ExpiryDate -lt [DateTime]::Today }
$expiredTips | Should -BeNullOrEmpty
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/CSharpClasses/tiPSClasses/PowerShellTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class PowerShellTip
public string Example { get; set; }
public string[] Urls { get; set; }
public TipCategory Category { get; set; }
public DateTime ExpiryDate { get; set; }

public PowerShellTip()
{
Expand All @@ -32,6 +33,7 @@ public PowerShellTip()
Example = string.Empty;
Urls = Array.Empty<string>();
Category = TipCategory.Other;
ExpiryDate = DateTime.MaxValue;
}

public string Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $tip.Urls = @(
'https://sessionize.com/pshsummit24/'
)
$tip.Category = [tiPS.TipCategory]::Community # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
$tip.ExpiryDate = [DateTime]::Parse('2024-04-11') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.

# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc.
# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tip.Urls = @(
'https://psconf.eu/'
)
$tip.Category = [tiPS.TipCategory]::Community # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
$tip.ExpiryDate = [DateTime]::Parse('2024-06-27') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.

# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc.
# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc.
Expand Down
1 change: 1 addition & 0 deletions src/PowerShellTips/2023-10-09-psconfeu-2023-minicon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $tip.Urls = @(
'https://app.gather.town/events/It0l-Wx8TQmTI93yQvs-'
)
$tip.Category = [tiPS.TipCategory]::Community # Community, Editor, Module, NativeCmdlet, Performance, Security, Syntax, Terminal, or Other.
$tip.ExpiryDate = [DateTime]::Parse('2023-10-24') # Optional. If the tip is not relevant after a certain date, set the expiration date. e.g. Announcing a conference or event.

# Community: Social events and community resources. e.g. PowerShell Summit, podcasts, etc.
# Editor: Editor tips and extensions. e.g. VSCode, ISE, etc.
Expand Down
6 changes: 6 additions & 0 deletions src/tiPS/Classes/PowerShellTip.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Describe 'Trimming all tip properties' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should not change any of the properties' {
Expand Down Expand Up @@ -41,6 +42,7 @@ Describe 'Trimming all tip properties' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should trim the leading and trailing whitespace from all of the properties' {
Expand Down Expand Up @@ -78,6 +80,7 @@ Describe 'Validating a PowerShellTip' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should throw an error when the CreatedDate has not been set' {
Expand Down Expand Up @@ -131,6 +134,7 @@ Describe 'Validating a PowerShellTip' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should not throw an error when all properties are valid' {
Expand All @@ -150,6 +154,7 @@ Describe 'Getting the Id property' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should create the Id properly from the other property values' {
Expand Down Expand Up @@ -178,6 +183,7 @@ Describe 'Checking if URLs are provided' {
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}

It 'Should return true when URLs are supplied' {
Expand Down
Loading
Loading