-
Notifications
You must be signed in to change notification settings - Fork 7
fix(page-status): correctly classify BYOM pages when sourceLastModified is null/absent #369
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
Open
somarc
wants to merge
2
commits into
main
Choose a base branch
from
fix/page-status-byom-no-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,104 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import classifySequenceStatus from '../../../tools/page-status/status.js'; | ||
|
|
||
| const EDIT = '2024-01-01T00:00:00.000Z'; | ||
| const PREVIEW = '2024-01-02T00:00:00.000Z'; | ||
| const PUBLISH = '2024-01-03T00:00:00.000Z'; | ||
|
|
||
| describe('classifySequenceStatus — with source date', () => { | ||
| it('returns Not previewed when only edit exists', () => { | ||
| const { label, positive } = classifySequenceStatus(EDIT, undefined, undefined); | ||
| assert.equal(label, 'Not previewed'); | ||
| assert.equal(positive, true); | ||
| }); | ||
|
|
||
| it('returns Not published when edit and preview exist in sequence', () => { | ||
| const { label, positive } = classifySequenceStatus(EDIT, PREVIEW, undefined); | ||
| assert.equal(label, 'Not published'); | ||
| assert.equal(positive, true); | ||
| }); | ||
|
|
||
| it('returns Pending changes when edit is newer than preview (unpublished edit)', () => { | ||
| const { label, positive } = classifySequenceStatus(PUBLISH, EDIT, undefined); | ||
| assert.equal(label, 'Pending changes'); | ||
| assert.equal(positive, true); | ||
| }); | ||
|
|
||
| it('returns Current when edit → preview → publish are in sequence', () => { | ||
| const { label, positive } = classifySequenceStatus(EDIT, PREVIEW, PUBLISH); | ||
| assert.equal(label, 'Current'); | ||
| assert.equal(positive, true); | ||
| }); | ||
|
|
||
| it('returns Pending changes when preview is newer than publish', () => { | ||
| const { label, positive } = classifySequenceStatus(EDIT, PUBLISH, PREVIEW); | ||
| assert.equal(label, 'Pending changes'); | ||
| assert.equal(positive, true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('classifySequenceStatus — no source for authored content', () => { | ||
| [undefined, null, 'not-a-date'].forEach((noSource) => { | ||
| const label = noSource === null ? 'null' : String(noSource); | ||
|
|
||
| it(`preserves No source warning when only preview exists [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, PREVIEW, undefined); | ||
| assert.equal(result.label, 'No source'); | ||
| assert.equal(result.positive, false); | ||
| }); | ||
|
|
||
| it(`preserves No source warning when preview and publish exist [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, PREVIEW, PUBLISH); | ||
| assert.equal(result.label, 'No source'); | ||
| assert.equal(result.positive, false); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('classifySequenceStatus — no source (BYOM, issue #340)', () => { | ||
| // Both undefined (absent field) and null (explicit API value) must be treated as no source. | ||
| [undefined, null].forEach((noSource) => { | ||
| const label = noSource === null ? 'null' : 'undefined'; | ||
|
|
||
| it(`returns No source (negative) when nothing exists [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, undefined, undefined, { | ||
| allowMissingSourceDate: true, | ||
| }); | ||
| assert.equal(result.label, 'No source'); | ||
| assert.equal(result.positive, false); | ||
| }); | ||
|
|
||
| it(`returns Not published (positive) when only preview exists [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, PREVIEW, undefined, { | ||
| allowMissingSourceDate: true, | ||
| }); | ||
| assert.equal(result.label, 'Not published'); | ||
| assert.equal(result.positive, true); | ||
| }); | ||
|
|
||
| it(`returns Current (positive) when only publish exists [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, undefined, PUBLISH, { | ||
| allowMissingSourceDate: true, | ||
| }); | ||
| assert.equal(result.label, 'Current'); | ||
| assert.equal(result.positive, true); | ||
| }); | ||
|
|
||
| it(`returns Current (positive) when preview and publish are in sequence [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, PREVIEW, PUBLISH, { | ||
| allowMissingSourceDate: true, | ||
| }); | ||
| assert.equal(result.label, 'Current'); | ||
| assert.equal(result.positive, true); | ||
| }); | ||
|
|
||
| it(`returns Pending changes (positive) when preview is newer than publish [edit=${label}]`, () => { | ||
| const result = classifySequenceStatus(noSource, PUBLISH, PREVIEW, { | ||
| allowMissingSourceDate: true, | ||
| }); | ||
| assert.equal(result.label, 'Pending changes'); | ||
| assert.equal(result.positive, true); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,47 @@ | ||
| /** | ||
| * Classifies the sequence status for a resource based on edit, preview, and publish dates. | ||
| * Returns a label and whether the status is considered positive (vs. negative/actionable). | ||
| * @param {string|null|undefined} edit - Source/edit last-modified date. | ||
| * @param {string|null|undefined} preview - Preview last-modified date. | ||
| * @param {string|null|undefined} publish - Publish last-modified date. | ||
| * @param {Object} [options] - Classification options. | ||
| * @param {boolean} [options.allowMissingSourceDate=false] - Whether missing source dates | ||
| * are expected. | ||
| * @returns {{ label: string, positive: boolean }} | ||
| */ | ||
| export default function classifySequenceStatus(edit, preview, publish, options = {}) { | ||
| const { allowMissingSourceDate = false } = options; | ||
| const valid = (d) => !Number.isNaN(d.getTime()); | ||
| // Treat null and undefined as absent — new Date(null) yields epoch which is a valid date. | ||
| const editDate = new Date(edit ?? NaN); | ||
| const previewDate = new Date(preview ?? NaN); | ||
| const publishDate = new Date(publish ?? NaN); | ||
|
|
||
| if (!valid(editDate)) { | ||
| if (!allowMissingSourceDate) { | ||
| return { label: 'No source', positive: false }; | ||
| } | ||
|
|
||
| // BYOM pages have no sourceLastModified from the admin API. Classify by | ||
| // preview/publish state rather than always returning a negative status. | ||
| if (!valid(previewDate) && !valid(publishDate)) { | ||
| return { label: 'No source', positive: false }; | ||
| } | ||
| if (valid(previewDate) && !valid(publishDate)) { | ||
| return { label: 'Not published', positive: true }; | ||
| } | ||
| if (!valid(previewDate) && valid(publishDate)) { | ||
| return { label: 'Current', positive: true }; | ||
| } | ||
| return { label: previewDate <= publishDate ? 'Current' : 'Pending changes', positive: true }; | ||
| } | ||
|
|
||
| if (!valid(previewDate) && !valid(publishDate)) { | ||
| return { label: 'Not previewed', positive: true }; | ||
| } | ||
| if (valid(previewDate) && !valid(publishDate) && editDate <= previewDate) { | ||
| return { label: 'Not published', positive: true }; | ||
| } | ||
| const inSequence = editDate <= previewDate && previewDate <= publishDate; | ||
| return { label: inSequence ? 'Current' : 'Pending changes', positive: true }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the edit date may not be valid for non-byom (sharepoint/gdrive authoring) in those cases, non valid edit date indicates the file was deleted from source, and I think we should try to preserve that warning.