Skip to content

Commit

Permalink
only allow one customer account page render
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshen1990 committed Sep 20, 2024
1 parent d71bca9 commit 27aad0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-peas-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': patch
---

Add restriction to only allow one customer account page render per extension
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,39 @@ Please check the configuration in ${uiExtension.configurationPath}`),
err(`Duplicate targets found: EXTENSION::POINT::A
Extension point targets must be unique
Please check the configuration in ${uiExtension.configurationPath}`),
)
})
})

test('returns err(message) when there are both customer-account.order.page.render and customer-account.order.render targets', async () => {
await inTemporaryDirectory(async (tmpDir) => {
// Given
await mkdir(joinPath(tmpDir, 'src'))
await touchFile(joinPath(tmpDir, 'src', 'ExtensionPointA.js'))
await touchFile(joinPath(tmpDir, 'src', 'ExtensionPointB.js'))

const uiExtension = await getTestUIExtension({
directory: tmpDir,
extensionPoints: [
{
target: 'customer-account.order.page.render',
module: './src/ExtensionPointA.js',
},
{
target: 'customer-account.page.render',
module: './src/ExtensionPointB.js',
},
],
})

// When
const result = await uiExtension.validate()

// Then
expect(result).toEqual(
err(`You can't have both 'customer-account.order.page.render' and 'customer-account.page.render'
Please check the configuration in ${uiExtension.configurationPath}`),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Please check the module path for ${target}`.value,
}
}

if (
uniqueTargets.indexOf('customer-account.order.page.render') >= 0 &&
uniqueTargets.indexOf('customer-account.page.render') >= 0
) {
errors.push(`You can't have both 'customer-account.order.page.render' and 'customer-account.page.render'`)
}
if (duplicateTargets.length) {
errors.push(`Duplicate targets found: ${duplicateTargets.join(', ')}\nExtension point targets must be unique`)
}
Expand Down

0 comments on commit 27aad0d

Please sign in to comment.