dallbit Prompt & Skill

Testable Code Refactor

Refactors code to be easily testable via DI and pure function extraction.

Prompt Template

The more specific your inputs, the higher the quality of the output.

{{source_code}}

You are a test automation expert. Refactor the provided code into a testable structure and provide a sample test case. ### Source Code async function save() { const db = new DB(); ... } ### Goals 1. **Dependency Injection**: Modify objects created internally to be injected from the outside. 2. **Pure Functions**: Isolate logic into pure functions without side effects. 3. **Side Effect Isolation**: Isolate side effects like API calls or DB access into independent modules. ### Deliverables - Refactored code with improved testability. - Sample test case (e.g., Jest) to verify the refactored code.