Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.3 KB
Raw Blame
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
import { uninstallPlugin } from './plugins'

const { mockUninstallPost } = vi.hoisted(() => ({
  mockUninstallPost: vi.fn(),
}))

vi.mock('./base', () => ({
  get: vi.fn(),
  getMarketplace: vi.fn(),
  post: vi.fn(),
  upload: vi.fn(),
}))

vi.mock('@/service/console', () => ({
  consoleClient: {
    workspaces: {
      current: {
        plugin: {
          uninstall: {
            post: mockUninstallPost,
          },
        },
      },
    },
  },
}))

describe('uninstallPlugin', () => {
  beforeEach(() => {
    mockUninstallPost.mockReset().mockResolvedValue({ success: true })
  })

  it('should delete credentials for an ordinary uninstall by default', async () => {
    await uninstallPlugin('installation-id')

    expect(mockUninstallPost).toHaveBeenCalledWith({
      body: {
        plugin_installation_id: 'installation-id',
        preserve_credentials: false,
      },
    })
  })

  it('should preserve credentials when requested for a replacement', async () => {
    await uninstallPlugin('installation-id', { preserveCredentials: true })

    expect(mockUninstallPost).toHaveBeenCalledWith({
      body: {
        plugin_installation_id: 'installation-id',
        preserve_credentials: true,
      },
    })
  })
})