Skip to content

Commit 404abb8

Browse files
Merge pull request #6378 from Shopify/show-org-ids
Show org ids when there are duplicated names
2 parents 1c285fc + 9608c3f commit 404abb8

File tree

3 files changed

+133
-2
lines changed

3 files changed

+133
-2
lines changed

.changeset/heavy-berries-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': patch
3+
---
4+
5+
Show IDs next to organization names when there are duplicates

packages/app/src/cli/utilities/developer-platform-client/app-management-client.test.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import {AppAccessSpecIdentifier} from '../../models/extensions/specifications/ap
3030
import {MinimalAppIdentifiers} from '../../models/organization.js'
3131
import {CreateAssetUrl} from '../../api/graphql/app-management/generated/create-asset-url.js'
3232
import {SourceExtension} from '../../api/graphql/app-management/generated/types.js'
33+
import {ListOrganizations} from '../../api/graphql/business-platform-destinations/generated/organizations.js'
3334
import {describe, expect, test, vi} from 'vitest'
3435
import {CLI_KIT_VERSION} from '@shopify/cli-kit/common/version'
3536
import {fetch} from '@shopify/cli-kit/node/http'
3637
import {
3738
businessPlatformOrganizationsRequest,
3839
businessPlatformOrganizationsRequestDoc,
40+
businessPlatformRequestDoc,
3941
} from '@shopify/cli-kit/node/api/business-platform'
4042
import {appManagementRequestDoc} from '@shopify/cli-kit/node/api/app-management'
4143
import {BugError} from '@shopify/cli-kit/node/error'
@@ -1528,3 +1530,124 @@ describe('appExtensionRegistrations', () => {
15281530
})
15291531
})
15301532
})
1533+
1534+
describe('organizations', () => {
1535+
test('returns empty array when currentUserAccount is null', async () => {
1536+
// Given
1537+
const client = new AppManagementClient()
1538+
client.businessPlatformToken = () => Promise.resolve('business-platform-token')
1539+
1540+
vi.mocked(businessPlatformRequestDoc).mockResolvedValueOnce({
1541+
currentUserAccount: null,
1542+
})
1543+
1544+
// When
1545+
const result = await client.organizations()
1546+
1547+
// Then
1548+
expect(result).toEqual([])
1549+
expect(businessPlatformRequestDoc).toHaveBeenCalledWith(
1550+
expect.objectContaining({
1551+
query: ListOrganizations,
1552+
token: 'business-platform-token',
1553+
}),
1554+
)
1555+
})
1556+
1557+
test('returns organizations with unique names', async () => {
1558+
// Given
1559+
const client = new AppManagementClient()
1560+
client.businessPlatformToken = () => Promise.resolve('business-platform-token')
1561+
const mockResponse = {
1562+
currentUserAccount: {
1563+
uuid: 'user-123',
1564+
organizationsWithAccessToDestination: {
1565+
nodes: [
1566+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMQ==', name: 'Org One'},
1567+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMg==', name: 'Org Two'},
1568+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMw==', name: 'Org Three'},
1569+
],
1570+
},
1571+
},
1572+
}
1573+
vi.mocked(businessPlatformRequestDoc).mockResolvedValueOnce(mockResponse)
1574+
1575+
// When
1576+
const result = await client.organizations()
1577+
1578+
// Then
1579+
expect(result).toEqual([
1580+
{id: '1', businessName: 'Org One', source: 'BusinessPlatform'},
1581+
{id: '2', businessName: 'Org Two', source: 'BusinessPlatform'},
1582+
{id: '3', businessName: 'Org Three', source: 'BusinessPlatform'},
1583+
])
1584+
})
1585+
1586+
test('appends ID to businessName when organizations have duplicate names', async () => {
1587+
// Given
1588+
const client = new AppManagementClient()
1589+
client.businessPlatformToken = () => Promise.resolve('business-platform-token')
1590+
const mockResponse = {
1591+
currentUserAccount: {
1592+
uuid: 'user-123',
1593+
organizationsWithAccessToDestination: {
1594+
nodes: [
1595+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMQ==', name: 'My Org'},
1596+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMg==', name: 'My Org'},
1597+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vMw==', name: 'Other Org'},
1598+
{id: 'Z2lkOi8vQnVzaW5lc3NQbGF0Zm9ybS9Pcmdhbml6YXRpb24vNA==', name: 'My Org'},
1599+
],
1600+
},
1601+
},
1602+
}
1603+
vi.mocked(businessPlatformRequestDoc).mockResolvedValueOnce(mockResponse)
1604+
1605+
// When
1606+
const result = await client.organizations()
1607+
1608+
// Then
1609+
expect(result).toEqual([
1610+
{
1611+
id: '1',
1612+
businessName: 'My Org (1)',
1613+
source: 'BusinessPlatform',
1614+
},
1615+
{
1616+
id: '2',
1617+
businessName: 'My Org (2)',
1618+
source: 'BusinessPlatform',
1619+
},
1620+
{
1621+
id: '3',
1622+
businessName: 'Other Org (3)',
1623+
source: 'BusinessPlatform',
1624+
},
1625+
{
1626+
id: '4',
1627+
businessName: 'My Org (4)',
1628+
source: 'BusinessPlatform',
1629+
},
1630+
])
1631+
})
1632+
1633+
test('returns empty array when organizationsWithAccessToDestination is empty', async () => {
1634+
// Given
1635+
const client = new AppManagementClient()
1636+
client.businessPlatformToken = () => Promise.resolve('business-platform-token')
1637+
const mockResponse = {
1638+
currentUserAccount: {
1639+
uuid: 'user-123',
1640+
organizationsWithAccessToDestination: {
1641+
nodes: [],
1642+
},
1643+
},
1644+
}
1645+
vi.mocked(businessPlatformRequestDoc).mockResolvedValueOnce(mockResponse)
1646+
1647+
// When
1648+
const result = await client.organizations()
1649+
1650+
// Then
1651+
expect(result).toEqual([])
1652+
})
1653+
})

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ export class AppManagementClient implements DeveloperPlatformClient {
361361
async organizations(): Promise<Organization[]> {
362362
const organizationsResult = await this.businessPlatformRequest({query: ListOrganizations})
363363
if (!organizationsResult.currentUserAccount) return []
364-
return organizationsResult.currentUserAccount.organizationsWithAccessToDestination.nodes.map((org) => ({
364+
const orgs = organizationsResult.currentUserAccount.organizationsWithAccessToDestination.nodes
365+
const uniqueNames = new Set(orgs.map((org) => org.name))
366+
const duplicatedNames = uniqueNames.size < orgs.length
367+
return orgs.map((org) => ({
365368
id: idFromEncodedGid(org.id),
366-
businessName: `${org.name} (Dev Dashboard)`,
369+
businessName: duplicatedNames ? `${org.name} (${idFromEncodedGid(org.id)})` : org.name,
367370
source: this.organizationSource,
368371
}))
369372
}

0 commit comments

Comments
 (0)