|
| 1 | +/** @vitest-environment node */ |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { |
| 4 | + type OrganizationAccountsSettings, |
| 5 | + updateOrganizationAccountsContract, |
| 6 | +} from '@/lib/api/contracts/organization-accounts' |
| 7 | +import { getOrganizationAccountUpdateOptions } from '@/lib/credential-groups/organization-account-options' |
| 8 | +import { CREDENTIAL_GROUP_STANDARD_OAUTH_PROVIDER_IDS } from '@/lib/credential-groups/providers' |
| 9 | + |
| 10 | +describe('organization account update options', () => { |
| 11 | + it.each([undefined, '12345678-1234-4123-8123-123456789012'])( |
| 12 | + 'satisfies the update contract with stored Slack scopes and bot %s', |
| 13 | + (slackBotCredentialId) => { |
| 14 | + const group: NonNullable<OrganizationAccountsSettings['credentialGroup']> = { |
| 15 | + id: 'group-1', |
| 16 | + workspaceId: null, |
| 17 | + organizationId: 'org-1', |
| 18 | + name: 'Connected accounts', |
| 19 | + description: null, |
| 20 | + mcpServers: [], |
| 21 | + status: 'active', |
| 22 | + createdAt: '2026-01-01T00:00:00Z', |
| 23 | + updatedAt: '2026-01-01T00:00:00Z', |
| 24 | + options: [ |
| 25 | + ...CREDENTIAL_GROUP_STANDARD_OAUTH_PROVIDER_IDS.map((provider) => ({ |
| 26 | + id: `${provider}-option`, |
| 27 | + provider, |
| 28 | + label: provider, |
| 29 | + required: false, |
| 30 | + status: 'active' as const, |
| 31 | + configurationStatus: 'ready' as const, |
| 32 | + })), |
| 33 | + { |
| 34 | + id: 'slack-option', |
| 35 | + provider: 'slack', |
| 36 | + label: 'Slack', |
| 37 | + required: true, |
| 38 | + status: 'active', |
| 39 | + configurationStatus: 'ready', |
| 40 | + slackBotCredentialId, |
| 41 | + requiredScopes: ['search:read', 'channels:history'], |
| 42 | + }, |
| 43 | + ], |
| 44 | + } |
| 45 | + |
| 46 | + const options = getOrganizationAccountUpdateOptions(group) |
| 47 | + const result = updateOrganizationAccountsContract.body.parse({ options }) |
| 48 | + |
| 49 | + expect(result.options).toEqual(options) |
| 50 | + expect(result.options?.map(({ id }) => id)).toEqual(group.options.map(({ id }) => id)) |
| 51 | + expect(result.options?.at(-1)).toEqual({ |
| 52 | + id: 'slack-option', |
| 53 | + provider: 'slack', |
| 54 | + label: 'Slack', |
| 55 | + required: true, |
| 56 | + slackBotCredentialId, |
| 57 | + }) |
| 58 | + expect(group.options.at(-1)).toHaveProperty('requiredScopes', [ |
| 59 | + 'search:read', |
| 60 | + 'channels:history', |
| 61 | + ]) |
| 62 | + } |
| 63 | + ) |
| 64 | +}) |
0 commit comments