Skip to content

Commit

Permalink
don't check the productMap for translations (github#25589)
Browse files Browse the repository at this point in the history
* don't check the productMap for translations

* fix breaking test
  • Loading branch information
peterbe authored Feb 24, 2022
1 parent d2f07b8 commit 16113fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
29 changes: 17 additions & 12 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,23 @@ class Page {
// Get array of versions that the page is available in for fast lookup
this.applicableVersions = getApplicableVersions(this.versions, this.fullPath)

// a page should only be available in versions that its parent product is available in
const versionsParentProductIsNotAvailableIn = this.applicableVersions
// only the homepage will not have this.parentProduct
.filter(
(availableVersion) =>
this.parentProduct && !this.parentProduct.versions.includes(availableVersion)
)

if (versionsParentProductIsNotAvailableIn.length) {
throw new Error(
`\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`
)
// Only check the parent product ID for English because if a top-level
// product is edited in English, it will fail for translations until
// the next translation pipeline PR gets a chance to catch up.
if (this.languageCode === 'en') {
// a page should only be available in versions that its parent product is available in
const versionsParentProductIsNotAvailableIn = this.applicableVersions
// only the homepage will not have this.parentProduct
.filter(
(availableVersion) =>
this.parentProduct && !this.parentProduct.versions.includes(availableVersion)
)

if (versionsParentProductIsNotAvailableIn.length) {
throw new Error(
`\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!`
)
}
}

// derive array of Permalink objects
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,6 @@ describe('catches errors thrown in Page class', () => {
expect(getPage).rejects.toThrowError(/`versions` frontmatter.*? product is not available in/)
})

test('non-English page with a version in frontmatter that its parent product is not available in', async () => {
async function getPage() {
return await Page.init({
relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md',
basePath: path.join(__dirname, '../fixtures/products'),
languageCode: 'es',
})
}

await expect(getPage).rejects.toThrowError(
/`versions` frontmatter.*? product is not available in/
)
})

describe('versionining optional attributes', () => {
test("re-rendering set appropriate 'product', 'permissions', 'learningTracks'", async () => {
const page = await Page.init({
Expand Down

0 comments on commit 16113fd

Please sign in to comment.