1
import { describe, it, expect, vi, beforeEach } from 'vitest';
2
import { mockClient } from '../utils/mocks/client.mock';
3
-import { ConnectedAccounts } from '../../src/models/ConnectedAccounts';
3
+import { ConnectedAccounts, experimental_updateAcl } from '../../src/models/ConnectedAccounts';
4
import ComposioClient from '@composio/client';
5
import { ConnectedAccountRetrieveResponse } from '@composio/client/resources/connected-accounts.mjs';
6
import {
1521
});
1522
});
1523
1524
- describe('link with accountType + ACL', () => {
1524
+ describe('link with experimental block (SHARED + ACL)', () => {
1525
beforeEach(() => {
1526
extendedMockClient.connectedAccounts.list.mockResolvedValue({
1527
items: [],
1534
});
1535
});
1536
1537
- it('forwards accountType=SHARED + nested aclConfigForShared to client.link.create', async () => {
1537
+ it('forwards experimental block with accountType + aclConfigForShared to client.link.create', async () => {
1538
await connectedAccounts.link('user_123', 'auth_config_123', {
1539
- accountType: 'SHARED',
1540
- aclConfigForShared: {
1541
- allowAllUsers: true,
1542
- notAllowedUserIds: ['user_bob'],
1539
+ experimental: {
1540
+ accountType: 'SHARED',
1541
+ aclConfigForShared: {
1542
+ allowAllUsers: true,
1543
+ notAllowedUserIds: ['user_bob'],
1544
+ },
1545
},
1546
});
1547
1548
expect(extendedMockClient.link.create).toHaveBeenCalledWith({
1549
auth_config_id: 'auth_config_123',
1550
user_id: 'user_123',
1549
- account_type: 'SHARED',
1550
- acl_config_for_shared: {
1551
- allow_all_users: true,
1552
- not_allowed_user_ids: ['user_bob'],
1551
+ experimental: {
1552
+ account_type: 'SHARED',
1553
+ acl_config_for_shared: {
1554
+ allow_all_users: true,
1555
+ not_allowed_user_ids: ['user_bob'],
1556
+ },
1557
},
1558
});
1559
});
1560
1557
- it('omits acl_config_for_shared when aclConfigForShared is undefined', async () => {
1558
- await connectedAccounts.link('user_123', 'auth_config_123', { accountType: 'SHARED' });
1561
+ it('omits the inner acl block when aclConfigForShared is undefined', async () => {
1562
+ await connectedAccounts.link('user_123', 'auth_config_123', {
1563
+ experimental: { accountType: 'SHARED' },
1564
+ });
1565
+
1566
+ const body = extendedMockClient.link.create.mock.calls[0][0];
1567
+ expect(body.experimental).toEqual({ account_type: 'SHARED' });
1568
+ expect('acl_config_for_shared' in body.experimental).toBe(false);
1569
+ });
1570
+
1571
+ it('omits the experimental block entirely when not provided', async () => {
1572
+ await connectedAccounts.link('user_123', 'auth_config_123');
1573
1574
const body = extendedMockClient.link.create.mock.calls[0][0];
1561
- expect(body.account_type).toBe('SHARED');
1562
- expect('acl_config_for_shared' in body).toBe(false);
1575
+ expect('experimental' in body).toBe(false);
1576
});
1577
1565
- it('serializes only the fields the caller provided (PATCH-style on inner block)', async () => {
1578
+ it('serializes only the inner ACL fields the caller provided', async () => {
1579
await connectedAccounts.link('user_123', 'auth_config_123', {
1567
- accountType: 'SHARED',
1568
- aclConfigForShared: { allowedUserIds: ['user_alice'] },
1580
+ experimental: {
1581
+ accountType: 'SHARED',
1582
+ aclConfigForShared: { allowedUserIds: ['user_alice'] },
1583
+ },
1584
});
1585
1586
expect(extendedMockClient.link.create).toHaveBeenCalledWith({
1587
auth_config_id: 'auth_config_123',
1588
user_id: 'user_123',
1574
- account_type: 'SHARED',
1575
- acl_config_for_shared: { allowed_user_ids: ['user_alice'] },
1589
+ experimental: {
1590
+ account_type: 'SHARED',
1591
+ acl_config_for_shared: { allowed_user_ids: ['user_alice'] },
1592
+ },
1593
});
1594
});
1595
1596
it('preserves explicit empty arrays in the serialized body', async () => {
1597
await connectedAccounts.link('user_123', 'auth_config_123', {
1581
- accountType: 'SHARED',
1582
- aclConfigForShared: { allowedUserIds: [], notAllowedUserIds: [] },
1598
+ experimental: {
1599
+ accountType: 'SHARED',
1600
+ aclConfigForShared: { allowedUserIds: [], notAllowedUserIds: [] },
1601
+ },
1602
});
1603
1604
expect(extendedMockClient.link.create).toHaveBeenCalledWith({
1605
auth_config_id: 'auth_config_123',
1606
user_id: 'user_123',
1588
- account_type: 'SHARED',
1589
- acl_config_for_shared: {
1590
- allowed_user_ids: [],
1591
- not_allowed_user_ids: [],
1607
+ experimental: {
1608
+ account_type: 'SHARED',
1609
+ acl_config_for_shared: {
1610
+ allowed_user_ids: [],
1611
+ not_allowed_user_ids: [],
1612
+ },
1613
},
1614
});
1615
});
1617
it('maps 400 AclOnlyForShared to ComposioAclOnlyForSharedError', async () => {
1618
extendedMockClient.link.create.mockReset();
1619
extendedMockClient.link.create.mockRejectedValueOnce(
1599
- Object.assign(new BadRequestError(400, undefined, 'acl_config_for_shared is only valid on SHARED connections.', {}), {})
1620
+ Object.assign(
1621
+ new BadRequestError(
1622
+ 400,
1623
+ undefined,
1624
+ 'acl_config_for_shared is only valid on SHARED connections.',
1625
+ {}
1626
+ ),
1627
+ {}
1628
+ )
1629
);
1630
1631
await expect(
1632
connectedAccounts.link('user_123', 'auth_config_123', {
1604
- accountType: 'PRIVATE',
1605
- aclConfigForShared: { allowAllUsers: true },
1633
+ experimental: {
1634
+ accountType: 'PRIVATE',
1635
+ aclConfigForShared: { allowAllUsers: true },
1636
+ },
1637
})
1638
).rejects.toBeInstanceOf(ComposioAclOnlyForSharedError);
1639
});
1648
});
1649
});
1650
1620
- describe('updateAcl', () => {
1621
- it('serializes PATCH body with nested acl_config_for_shared', async () => {
1651
+ describe('list with accountType filter', () => {
1652
+ it('forwards accountType to the wire as a flat query param', async () => {
1653
+ extendedMockClient.connectedAccounts.list.mockResolvedValue({
1654
+ items: [],
1655
+ next_cursor: null,
1656
+ total_pages: 0,
1657
+ });
1658
+
1659
+ await connectedAccounts.list({ accountType: 'SHARED', userIds: ['user_creator'] });
1660
+
1661
+ const callArg = extendedMockClient.connectedAccounts.list.mock.calls[0][0];
1662
+ expect(callArg.account_type).toBe('SHARED');
1663
+ expect(callArg.user_ids).toEqual(['user_creator']);
1664
+ });
1665
+
1666
+ it('omits account_type when accountType is not provided', async () => {
1667
+ extendedMockClient.connectedAccounts.list.mockResolvedValue({
1668
+ items: [],
1669
+ next_cursor: null,
1670
+ total_pages: 0,
1671
+ });
1672
+
1673
+ await connectedAccounts.list({ userIds: ['user_creator'] });
1674
+
1675
+ const callArg = extendedMockClient.connectedAccounts.list.mock.calls[0][0];
1676
+ expect('account_type' in callArg).toBe(false);
1677
+ });
1678
+ });
1679
+
1680
+ describe('experimental_updateAcl', () => {
1681
+ let composioHandle: { getClient: () => typeof extendedMockClient };
1682
+
1683
+ beforeEach(() => {
1684
+ composioHandle = { getClient: () => extendedMockClient };
1685
+ });
1686
+
1687
+ it('serializes PATCH body under experimental.acl_config_for_shared', async () => {
1688
extendedMockClient.connectedAccounts.patch.mockResolvedValueOnce({
1689
id: 'ca_abc',
1690
status: 'ACTIVE',
1691
success: true,
1692
});
1693
1628
- const result = await connectedAccounts.updateAcl('ca_abc', {
1694
+ const result = await experimental_updateAcl(composioHandle, 'ca_abc', {
1695
allowAllUsers: true,
1696
notAllowedUserIds: ['user_bob'],
1697
});
1698
1699
expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith('ca_abc', {
1634
- acl_config_for_shared: {
1635
- allow_all_users: true,
1636
- not_allowed_user_ids: ['user_bob'],
1700
+ experimental: {
1701
+ acl_config_for_shared: {
1702
+ allow_all_users: true,
1703
+ not_allowed_user_ids: ['user_bob'],
1704
+ },
1705
},
1706
});
1707
expect(result).toEqual({ id: 'ca_abc', status: 'ACTIVE', success: true });
1714
success: true,
1715
});
1716
1649
- await connectedAccounts.updateAcl('ca_abc', { allowedUserIds: ['user_alice'] });
1717
+ await experimental_updateAcl(composioHandle, 'ca_abc', { allowedUserIds: ['user_alice'] });
1718
1719
expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith('ca_abc', {
1652
- acl_config_for_shared: { allowed_user_ids: ['user_alice'] },
1720
+ experimental: {
1721
+ acl_config_for_shared: { allowed_user_ids: ['user_alice'] },
1722
+ },
1723
});
1724
});
1725
1730
success: true,
1731
});
1732
1663
- await connectedAccounts.updateAcl('ca_abc', { allowedUserIds: [] });
1733
+ await experimental_updateAcl(composioHandle, 'ca_abc', { allowedUserIds: [] });
1734
1735
expect(extendedMockClient.connectedAccounts.patch).toHaveBeenCalledWith('ca_abc', {
1666
- acl_config_for_shared: { allowed_user_ids: [] },
1736
+ experimental: { acl_config_for_shared: { allowed_user_ids: [] } },
1737
});
1738
});
1739
1740
it('rejects an empty params object via the refine', async () => {
1671
- await expect(connectedAccounts.updateAcl('ca_abc', {})).rejects.toMatchObject({
1741
+ await expect(experimental_updateAcl(composioHandle, 'ca_abc', {})).rejects.toMatchObject({
1742
name: 'ValidationError',
1743
});
1744
expect(extendedMockClient.connectedAccounts.patch).not.toHaveBeenCalled();
1746
1747
it('maps 400 AclOnlyForShared to ComposioAclOnlyForSharedError', async () => {
1748
extendedMockClient.connectedAccounts.patch.mockRejectedValueOnce(
1679
- new BadRequestError(400, undefined, 'acl_config_for_shared is only valid on SHARED connections.', {})
1749
+ new BadRequestError(
1750
+ 400,
1751
+ undefined,
1752
+ 'acl_config_for_shared is only valid on SHARED connections.',
1753
+ {}
1754
+ )
1755
);
1756
1757
await expect(
1683
- connectedAccounts.updateAcl('ca_abc', { allowAllUsers: true })
1758
+ experimental_updateAcl(composioHandle, 'ca_abc', { allowAllUsers: true })
1759
).rejects.toBeInstanceOf(ComposioAclOnlyForSharedError);
1760
});
1761
1764
extendedMockClient.connectedAccounts.patch.mockRejectedValueOnce(otherError);
1765
1766
await expect(
1692
- connectedAccounts.updateAcl('ca_abc', { allowAllUsers: true })
1767
+ experimental_updateAcl(composioHandle, 'ca_abc', { allowAllUsers: true })
1768
).rejects.toBe(otherError);
1769
});
1770
});