LibreChat/api/server/routes/agents/__tests__/channels-config.spec.js
Dustin Healy cd4652279c
🌐 feat: Connect Organization Slack Workspaces to Agents (#17811)
* feat: Route shared Slack installations through durable channel workers

* fix: Retain workspace metadata projection after helper cleanup

* fix: Honor configured proxy for Slack credential verification

* feat: Complete Shared Slack Workspace Setup and Routing

* fix: Integrate Shared Routing Retirement and Helm Startup

* fix: Cache Gateway Preparation and Recover OAuth Notifications

* fix: Route Organization-Owned Slack Apps Through the Shared Gateway

* 🔒 fix: Close Shared Slack Lifecycle and Retry Boundaries

* test: Isolate Channel Policy Route From Workspace Startup
2026-11-10 21:04:10 -08:00

57 lines
2.1 KiB
JavaScript

const express = require('express');
const request = require('supertest');
const mockReadConfig = jest.fn(async () => ({
endpoints: { agents: { channels: { enabled: true } } },
}));
let mockPolicy;
jest.mock('@librechat/api', () => ({
...jest.requireActual('@librechat/api'),
generateCheckAccess: () => (_req, _res, next) => next(),
}));
jest.mock('~/models', () => ({ getRoleByName: jest.fn() }));
jest.mock(
'~/server/controllers/agents/v1',
() => new Proxy({}, { get: () => (_req, res) => res.sendStatus(204) }),
);
jest.mock('~/server/middleware', () => ({
configMiddleware: async (req, _res, next) => {
req.config = await mockReadConfig();
next();
},
canAccessAgentResource: () => (_req, _res, next) => next(),
requireSameOrigin: (_req, _res, next) => next(),
}));
jest.mock('../middleware', () => ({ checkRemoteAgentsFeature: (_req, _res, next) => next() }));
jest.mock('../actions', () => require('express').Router());
jest.mock('../tools', () => require('express').Router());
jest.mock('~/server/services/SlackWorkspaceBindings', () => ({
create: (_req, res) => res.sendStatus(204),
read: (_req, res) => res.sendStatus(204),
assign: (_req, res) => res.sendStatus(204),
remove: (_req, res) => res.sendStatus(204),
}));
jest.mock(
'~/server/services/Channels',
() =>
new Proxy({}, { get: () => async (req, res) => res.json(await mockPolicy.requestConfig(req)) }),
);
it('resolves strict effective management configuration once through the actual v1 mount', async () => {
const { createChannelApplicationPolicy } = jest.requireActual('@librechat/api');
mockPolicy = createChannelApplicationPolicy({
readAppConfig: mockReadConfig,
findUser: jest.fn(),
isPrincipalActive: async () => true,
});
const app = express();
app.use((req, _res, next) => {
req.user = { id: 'owner', _id: 'owner', role: 'USER' };
next();
});
app.use('/agents', require('../v1').v1);
await request(app).get('/agents/agent/channels').expect(200);
expect(mockReadConfig).toHaveBeenCalledTimes(1);
expect(mockReadConfig).toHaveBeenCalledWith(
expect.objectContaining({ userId: 'owner', failClosed: true }),
);
});