MCPcopy Create free account
hub / github.com/TanStack/ai / createMockVideoAdapter

Function createMockVideoAdapter

packages/ai/tests/stream-generation.test.ts:159–210  ·  view source on GitHub ↗
(options?: {
    pollsBeforeComplete?: number
    failOnPoll?: number
  })

Source from the content-addressed store, hash-verified

157
158describe('generateVideo({ stream: true })', () => {
159 function createMockVideoAdapter(options?: {
160 pollsBeforeComplete?: number
161 failOnPoll?: number
162 }) {
163 const pollsBeforeComplete = options?.pollsBeforeComplete ?? 2
164 const failOnPoll = options?.failOnPoll
165 let pollCount = 0
166
167 return {
168 kind: 'video' as const,
169 name: 'test-video',
170 model: 'test-model',
171 '~types': {} as any,
172
173 availableDurations: () => ({ kind: 'none' as const }),
174 snapDuration: () => undefined,
175
176 createVideoJob: vi.fn(async () => ({
177 jobId: 'job-123',
178 model: 'test-model',
179 })),
180
181 getVideoStatus: vi.fn(async (): Promise<VideoStatusResult> => {
182 pollCount++
183 if (failOnPoll && pollCount >= failOnPoll) {
184 return {
185 jobId: 'job-123',
186 status: 'failed',
187 error: 'Video processing error',
188 }
189 }
190 if (pollCount >= pollsBeforeComplete) {
191 return {
192 jobId: 'job-123',
193 status: 'completed',
194 progress: 100,
195 }
196 }
197 return {
198 jobId: 'job-123',
199 status: 'processing',
200 progress: Math.round((pollCount / pollsBeforeComplete) * 100),
201 }
202 }),
203
204 getVideoUrl: vi.fn(async () => ({
205 jobId: 'job-123',
206 url: 'https://example.com/video.mp4',
207 expiresAt: new Date('2030-01-01'),
208 })),
209 }
210 }
211
212 it('should emit job lifecycle events until completion', async () => {
213 const adapter = createMockVideoAdapter({ pollsBeforeComplete: 2 })

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected