feat: filter SMS routes by channel sensitive words
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { ChannelSensitiveWordsService, validateChannelWord } from './channel-sensitive-words.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
const valid = { channelId: 'a', word: ' 贷 款 ', status: 'active', remark: '' };
|
||||
describe('channel word administration', () => {
|
||||
it('trims only outer whitespace and requires a version for editing', () => {
|
||||
expect(validateChannelWord(valid).word).toBe('贷 款');
|
||||
expect(() => validateChannelWord(valid, true)).toThrow('版本');
|
||||
expect(validateChannelWord({ ...valid, version: 3 }, true).version).toBe(3);
|
||||
});
|
||||
it.each([
|
||||
null,
|
||||
[],
|
||||
{ ...valid, word: ' ' },
|
||||
{ ...valid, word: 'a'.repeat(201) },
|
||||
{ ...valid, channelId: '' },
|
||||
{ ...valid, status: 'deleted' },
|
||||
{ ...valid, remark: 'a'.repeat(501) },
|
||||
{ ...valid, operatorId: 'spoof' },
|
||||
])('rejects invalid runtime data %#', (data) => expect(() => validateChannelWord(data)).toThrow());
|
||||
it('checks active platform admin permission before data access', async () => {
|
||||
const prisma = {
|
||||
user: { findFirst: jest.fn().mockResolvedValue(null) },
|
||||
channelSensitiveWord: { findMany: jest.fn() },
|
||||
};
|
||||
const service = new ChannelSensitiveWordsService(prisma as unknown as PrismaService);
|
||||
await expect(service.list('client-user', {})).rejects.toMatchObject({ status: 403 });
|
||||
expect(prisma.channelSensitiveWord.findMany).not.toHaveBeenCalled();
|
||||
expect(prisma.user.findFirst).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: expect.objectContaining({ deletedAt: null, roles: { some: { role: { code: 'platform_admin' } } } }),
|
||||
}),
|
||||
);
|
||||
});
|
||||
it('rejects invalid pagination before querying rules', async () => {
|
||||
const prisma = { user: { findFirst: jest.fn().mockResolvedValue({ id: 'admin' }) } };
|
||||
const service = new ChannelSensitiveWordsService(prisma as unknown as PrismaService);
|
||||
for (const query of [{ page: '0' }, { pageSize: '101' }, { page: '1.5' }, { status: 'deleted' }])
|
||||
await expect(service.list('admin', query)).rejects.toMatchObject({ status: 400 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user