-
-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...rc/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/isSafeToArchive.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { isSafeToArchive } from './isSafeToArchive'; // Update the import path accordingly | ||
import { subDays } from 'date-fns'; | ||
|
||
describe('isSafeToArchive', () => { | ||
it('should return true if all environments were last seen more than two days ago', () => { | ||
const now = new Date(); | ||
const environments = [ | ||
{ name: 'Production', lastSeenAt: subDays(now, 3).toISOString() }, | ||
{ name: 'Staging', lastSeenAt: subDays(now, 4).toISOString() }, | ||
]; | ||
|
||
const result = isSafeToArchive(environments); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false if any environment was seen within the last two days', () => { | ||
const now = new Date(); | ||
const environments = [ | ||
{ name: 'Production', lastSeenAt: subDays(now, 3).toISOString() }, | ||
{ name: 'Staging', lastSeenAt: subDays(now, 1).toISOString() }, | ||
]; | ||
|
||
const result = isSafeToArchive(environments); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if all environments were seen within the last two days', () => { | ||
const now = new Date(); | ||
const environments = [ | ||
{ name: 'Production', lastSeenAt: subDays(now, 0).toISOString() }, | ||
{ name: 'Staging', lastSeenAt: subDays(now, 1).toISOString() }, | ||
]; | ||
|
||
const result = isSafeToArchive(environments); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return true for an empty array of environments', () => { | ||
const environments: Array<{ name: string; lastSeenAt: string }> = []; | ||
|
||
const result = isSafeToArchive(environments); | ||
expect(result).toBe(true); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...end/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/isSafeToArchive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isBefore, parseISO, subDays } from 'date-fns'; | ||
|
||
export function isSafeToArchive( | ||
environments: Array<{ name: string; lastSeenAt: string }>, | ||
) { | ||
const twoDaysAgo = subDays(new Date(), 2); | ||
|
||
return environments.every((env) => { | ||
const lastSeenDate = parseISO(env.lastSeenAt); | ||
|
||
return isBefore(lastSeenDate, twoDaysAgo); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters