Skip to content

Commit

Permalink
Merge pull request #55 from deadlydog/AddAuthorProperty
Browse files Browse the repository at this point in the history
feat: Allow tip to specify the author of the tip so they get credit for it
  • Loading branch information
deadlydog authored Apr 20, 2024
2 parents d4eb579 + 8846d06 commit 1df14b0
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 77 deletions.
7 changes: 6 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
{
"version": "0.2",
"language": "en",
"ignorePaths": [],
"ignorePaths": [
"**/devcontainer.json",
"**/build-and-test-powershell-module.yml",
"**/build-test-and-deploy-powershell-module.yml"
],
"words": [
"colours",
"gifs",
Expand All @@ -15,6 +19,7 @@
"ignoreWords": [
"Codespace", // GitHub Codespaces
"Codespaces", // GitHub Codespaces
"deadlydog",
"dawidd", // GitHub action author
"devcontainer", // VS Code devcontainer
"gittools", // GitHub action author
Expand Down
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
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.3.0 - April 20, 2024

Features:

- Allow specifying the tip `Author` so they can get credit for the tip.

## v1.2.0 - March 7, 2024

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

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

public string Id
Expand All @@ -56,6 +58,11 @@ public bool UrlsAreProvided
get { return Urls != null && Urls.Length > 0; }
}

public bool AuthorIsProvided
{
get { return !string.IsNullOrWhiteSpace(Author); }
}

public void TrimAllProperties()
{
Title = Title.Trim();
Expand All @@ -65,6 +72,7 @@ public void TrimAllProperties()
{
Urls[i] = Urls[i].Trim();
}
Author = Author.Trim();
}

public void Validate()
Expand Down
225 changes: 149 additions & 76 deletions src/tiPS/Classes/PowerShellTip.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
using module './../tiPS.psm1'

Describe 'Trimming all tip properties' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given none of the properties need whitespace trimmed' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$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' {
[tiPS.PowerShellTip] $tip = $ValidTip
[string] $title = 'Title of the tip'
[string] $tipText = 'Tip Text'
[string] $example = 'Example'
[string[]] $urls = @('https://Url1.com', 'http://Url2.com')
[string] $author = 'Author Name'
$tip.Title = $title
$tip.TipText = $tipText
$tip.Example = $example
$tip.Urls = $urls
$tip.Author = $author

{ $tip.TrimAllProperties() } | Should -Not -Throw

$tip.Title | Should -Be $title
$tip.TipText | Should -Be $tipText
$tip.Example | Should -Be $example
$tip.Urls | Should -Be $urls
$tip.Author | Should -Be $author
}

It 'Should not change any of the properties' {
It 'Should not change any of the properties when an Author is not provided' {
[tiPS.PowerShellTip] $tip = $ValidTip
[string] $title = 'Title of the tip'
[string] $tipText = 'Tip Text'
[string] $example = 'Example'
[string[]] $urls = @('https://Url1.com', 'http://Url2.com')
[string] $author = ''
$tip.Title = $title
$tip.TipText = $tipText
$tip.Example = $example
$tip.Urls = $urls
$tip.Author = $author

{ $tip.TrimAllProperties() } | Should -Not -Throw

$tip.Title | Should -Be $title
$tip.TipText | Should -Be $tipText
$tip.Example | Should -Be $example
$tip.Urls | Should -Be $urls
$tip.Author | Should -Be $author
}
}

Context 'Given the properties need whitespace trimmed' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$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' {
[tiPS.PowerShellTip] $tip = $ValidTip
[string] $title = ' Title of the tip '
Expand All @@ -55,34 +70,39 @@ Describe 'Trimming all tip properties' {
[string] $expectedExample = 'Example'
[string[]] $urls = @('https://Url1.com ', ' http://Url2.com')
[string[]] $expectedUrls = @('https://Url1.com', 'http://Url2.com')
[string] $author = ' Author Name '
[string] $expectedAuthor = 'Author Name'
$tip.Title = $title
$tip.TipText = $tipText
$tip.Example = $example
$tip.Urls = $urls
$tip.Author = $author

{ $tip.TrimAllProperties() } | Should -Not -Throw

$tip.Title | Should -Be $expectedTitle
$tip.TipText | Should -Be $expectedTipText
$tip.Example | Should -Be $expectedExample
$tip.Urls | Should -Be $expectedUrls
$tip.Author | Should -Be $expectedAuthor
}
}
}

Describe 'Validating a PowerShellTip' {
Context 'Given the PowerShellTip has invalid properties' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given the PowerShellTip has invalid properties' {
It 'Should throw an error when the CreatedDate has not been set' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.CreatedDate = [DateTime]::MinValue
Expand Down Expand Up @@ -126,17 +146,6 @@ Describe 'Validating a PowerShellTip' {
}

Context 'Given the PowerShellTip has all valid properties' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$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' {
[tiPS.PowerShellTip] $tip = $ValidTip
{ $tip.Validate() } | Should -Not -Throw
Expand All @@ -145,18 +154,19 @@ Describe 'Validating a PowerShellTip' {
}

Describe 'Getting the Id property' {
Context 'Given the PowerShellTip properties are valid and have been specified' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
}
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given the PowerShellTip properties are valid and have been specified' {
It 'Should create the Id properly from the other property values' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.CreatedDate = [DateTime]::Parse('2023-07-16')
Expand All @@ -173,19 +183,56 @@ Describe 'Getting the Id property' {
}
}

Describe 'Checking if URLs are provided' {
Context 'Given the PowerShellTip has URLs' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
Describe 'Checking if an Example is provided' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given the PowerShellTip does have an example' {
It 'Should return true' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Example = 'Example'
$tip.ExampleIsProvided | Should -BeTrue
}
}

Context 'Given the PowerShellTip does not have an example' {
It 'Should return false' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Example = ''
$tip.ExampleIsProvided | Should -BeFalse
}

It 'Should return false when the example is null' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Example = $null
$tip.ExampleIsProvided | Should -BeFalse
}
}
}

Describe 'Checking if URLs are provided' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given the PowerShellTip has URLs' {
It 'Should return true when URLs are supplied' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Urls = @('https://Url1.com', 'http://Url2.com')
Expand All @@ -194,26 +241,52 @@ Describe 'Checking if URLs are provided' {
}

Context 'Given the PowerShellTip does not have URLs' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @()
$ValidTip.Category = 'Community'
}

It 'Should return false when no URLs are supplied' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Urls = @()
$tip.UrlsAreProvided | Should -BeFalse
}

It 'Should return false when the URLs array is not initialized' {
It 'Should return false when the URLs array is null' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Urls = $null
$tip.UrlsAreProvided | Should -BeFalse
}
}
}

Describe 'Checking if an Author is provided' {
BeforeEach {
[tiPS.PowerShellTip] $ValidTip = [tiPS.PowerShellTip]::new()
$ValidTip.CreatedDate = [DateTime]::Parse('2023-07-16')
$ValidTip.Title = 'Title of the tip'
$ValidTip.TipText = 'Tip Text'
$ValidTip.Example = 'Example'
$ValidTip.Urls = @('https://Url1.com', 'http://Url2.com')
$ValidTip.Category = 'Community'
$ValidTip.ExpiryDate = [DateTime]::MaxValue
$ValidTip.Author = 'Author Name'
}

Context 'Given the PowerShellTip does have an Author' {
It 'Should return true' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Author = 'Author Name'
$tip.AuthorIsProvided | Should -BeTrue
}
}

Context 'Given the PowerShellTip does not have an Author' {
It 'Should return false' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Author = ''
$tip.AuthorIsProvided | Should -BeFalse
}

It 'Should return false when the author is null' {
[tiPS.PowerShellTip] $tip = $ValidTip
$tip.Author = $null
$tip.AuthorIsProvided | Should -BeFalse
}
}
}
Loading

0 comments on commit 1df14b0

Please sign in to comment.