All files / core/application/use-cases GenerateVocabulary.ts

100% Statements 8/8
100% Branches 5/5
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30              6x 6x               6x 2x     4x   3x 1x     2x      
import { VocabularyItem } from '@/core/domain/VocabularyItem'
import { IVocabularyRepository } from '../interfaces/IVocabularyRepository'
 
/**
 * GenerateVocabularyUseCase
 * Application use case that orchestrates fetching vocabulary items from the repository.
 */
export class GenerateVocabularyUseCase {
  constructor(private readonly repository: IVocabularyRepository) {}
 
  /**
   * Executes the use case to generate vocabulary items
   * @param count - Number of vocabulary items to generate (default: 5)
   * @returns Promise resolving to an array of VocabularyItems
   */
  async execute(count: number = 5): Promise<VocabularyItem[]> {
    if (count < 1 || count > 10) {
      throw new Error('Count must be between 1 and 10')
    }
 
    const items = await this.repository.getVocabularyItems(count)
    
    if (items.length !== count) {
      throw new Error(`Expected ${count} items but received ${items.length}`)
    }
 
    return items
  }
}