| 1 | import { AccountType } from '@yikart/common' |
| 2 | import { describe, expect, it, vi } from 'vitest' |
| 3 | import { CreateChannelPublishFlowSchema, RequestChannelPublishUpdateSchema } from './channels-mcp.schema' |
| 4 | |
| 5 | vi.mock('@yikart/mongodb', () => ({ |
| 6 | PublishRecordSource: { |
| 7 | Mcp: 'mcp', |
| 8 | Web: 'web', |
| 9 | }, |
| 10 | PublishStatus: { |
| 11 | Failed: -1, |
| 12 | WaitingForPublish: 0, |
| 13 | Published: 1, |
| 14 | Publishing: 2, |
| 15 | PlatformScheduled: 7, |
| 16 | WaitingForUserAction: 8, |
| 17 | Canceled: 9, |
| 18 | }, |
| 19 | PublishType: { |
| 20 | VIDEO: 'video', |
| 21 | ARTICLE: 'article', |
| 22 | }, |
| 23 | })) |
| 24 | |
| 25 | describe('requestChannelPublishUpdateSchema', () => { |
| 26 | it('accepts structured update data', () => { |
| 27 | expect(RequestChannelPublishUpdateSchema.parse({ |
| 28 | taskId: 'task-1', |
| 29 | platform: AccountType.Facebook, |
| 30 | accountId: 'account-1', |
| 31 | data: { |
| 32 | content: { |
| 33 | title: 'updated title', |
| 34 | body: 'updated body', |
| 35 | media: [{ url: 'https://assets.example.test/image.jpg' }], |
| 36 | }, |
| 37 | option: { |
| 38 | content_category: 'post', |
| 39 | }, |
| 40 | }, |
| 41 | })).toMatchObject({ |
| 42 | taskId: 'task-1', |
| 43 | data: { |
| 44 | content: { |
| 45 | title: 'updated title', |
| 46 | body: 'updated body', |
| 47 | media: [{ url: 'https://assets.example.test/image.jpg' }], |
| 48 | }, |
| 49 | option: { |
| 50 | content_category: 'post', |
| 51 | }, |
| 52 | }, |
| 53 | }) |
| 54 | }) |
| 55 | |
| 56 | it('rejects unstructured update data', () => { |
| 57 | expect(() => RequestChannelPublishUpdateSchema.parse({ |
| 58 | taskId: 'task-1', |
| 59 | platform: AccountType.Facebook, |
| 60 | accountId: 'account-1', |
| 61 | data: { |
| 62 | arbitrary: 'value', |
| 63 | }, |
| 64 | })).toThrow() |
| 65 | }) |
| 66 | }) |
| 67 | |
| 68 | describe('createChannelPublishFlowSchema', () => { |
| 69 | it('strips context media fields from MCP publish flow input', () => { |
| 70 | const result = CreateChannelPublishFlowSchema.parse({ |
| 71 | content: { |
| 72 | body: 'Body', |
| 73 | media: [{ url: 'https://assets.example.test/video.mp4' }], |
| 74 | }, |
| 75 | publishAt: '2026-05-22T10:00:00.000Z', |
| 76 | context: { |
| 77 | type: 'video', |
| 78 | taskId: 'task-1', |
| 79 | source: 'web', |
| 80 | videoUrl: 'https://assets.example.test/wrong-video.mp4', |
| 81 | imgUrlList: ['https://assets.example.test/wrong-image.jpg'], |
| 82 | }, |
| 83 | items: [{ |
| 84 | accountId: 'account-1', |
| 85 | platform: AccountType.YouTube, |
| 86 | }], |
| 87 | }) |
| 88 | |
| 89 | expect(result.context).toEqual({ |
| 90 | taskId: 'task-1', |
| 91 | }) |
| 92 | }) |
| 93 | }) |
| 94 |