AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { describe, expect, it } from 'vitest'
import { mergeConnectionMetadata } from '../../../../src/app/app-connection/app-connection-service/connection-metadata'
describe('mergeConnectionMetadata', () => {
it('returns undefined when there is nothing to store', () => {
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: undefined, accountIdentifier: undefined })).toBeUndefined()
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: null, accountIdentifier: undefined })).toBeUndefined()
})
it('writes the resolved account identifier', () => {
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: undefined, accountIdentifier: '[email protected]' }))
.toStrictEqual({ accountIdentifier: '[email protected]' })
})
it('clears a previously resolved account identifier when resolution misses', () => {
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: { accountIdentifier: '[email protected]' }, accountIdentifier: undefined }))
.toStrictEqual({})
})
it('overwrites a previously resolved account identifier when the account changes', () => {
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: { accountIdentifier: '[email protected]' }, accountIdentifier: '[email protected]' }))
.toStrictEqual({ accountIdentifier: '[email protected]' })
})
it('keeps unrelated existing metadata keys', () => {
expect(mergeConnectionMetadata({ requestMetadata: undefined, existingMetadata: { pinned: true, accountIdentifier: '[email protected]' }, accountIdentifier: undefined }))
.toStrictEqual({ pinned: true })
})
it('strips a caller-supplied account identifier', () => {
expect(mergeConnectionMetadata({ requestMetadata: { accountIdentifier: '[email protected]', note: 'x' }, existingMetadata: undefined, accountIdentifier: undefined }))
.toStrictEqual({ note: 'x' })
expect(mergeConnectionMetadata({ requestMetadata: { accountIdentifier: '[email protected]' }, existingMetadata: undefined, accountIdentifier: '[email protected]' }))
.toStrictEqual({ accountIdentifier: '[email protected]' })
})
it('carries the stored identifier through an update that supplies its own metadata', () => {
expect(mergeConnectionMetadata({ requestMetadata: { note: 'x' }, existingMetadata: { accountIdentifier: '[email protected]' }, accountIdentifier: '[email protected]' }))
.toStrictEqual({ note: 'x', accountIdentifier: '[email protected]' })
})
it('drops a forged identifier from an update while keeping the stored one', () => {
expect(mergeConnectionMetadata({ requestMetadata: { accountIdentifier: '[email protected]' }, existingMetadata: { accountIdentifier: '[email protected]' }, accountIdentifier: '[email protected]' }))
.toStrictEqual({ accountIdentifier: '[email protected]' })
})
it('prefers caller metadata over existing metadata', () => {
expect(mergeConnectionMetadata({ requestMetadata: { note: 'new' }, existingMetadata: { note: 'old', pinned: true }, accountIdentifier: '[email protected]' }))
.toStrictEqual({ note: 'new', accountIdentifier: '[email protected]' })
})
})