> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devinenterprise.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fügen Sie Unit-Tests zu Ihrem Payment-Service hinzu

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="Fügen Sie Ihrem Payment-Service Unit-Tests hinzu" description="Erstellen Sie ein Playbook zum Schreiben von Tests für die Zahlungsabwicklung und lassen Sie Devin Zahlungsflüsse, Erstattungslogik und Webhook-Handler mit umfassenden Unit-Tests abdecken." prompt="Schreiben Sie Unit-Tests für alle ungetesteten Funktionen in src/services/PaymentService.ts. Decken Sie processCharge, issueRefund und handleWebhook ab. Mocken Sie das Stripe SDK und die Datenbankaufrufe. Jede Funktion benötigt Tests für Erfolgs-, Fehler- und Randfälle wie doppelte Belastungen und Teilerstattungen. Ziel sind 90 % Zeilenabdeckung." category="Codequalität" features="Playbooks" />

<div className="uc-detail-wrapper">
  <Tip>Möchten Sie dies nicht manuell einrichten? Fügen Sie einen Link zu dieser Seite in eine Devin-Sitzung ein und bitten Sie Devin, alles für Sie einzurichten.</Tip>

  <Steps>
    <Step title="Erstellen Sie ein zahlungsspezifisches Test-Playbook">
      Ein [Playbook](/de/product-guides/creating-playbooks) hält die Testkonventionen Ihres Teams fest, sodass Devin Tests so schreibt, wie Ihre Engineers es tun. Code für Zahlungsabwicklung hat besondere Anforderungen – Idempotenz, Währungsgenauigkeit, Gateway-Retries, PCI-sicheres Mocking – daher erkennt ein auf Payments fokussiertes Playbook Probleme, die einem generischen entgehen würden.

      **Option 1: Schreiben Sie das Playbook selbst.** Öffnen Sie [**Settings > Playbooks > Create playbook**](https://app.devin.ai/settings/playbooks/create?utm_source=docs\&utm_medium=use-case-gallery) und definieren Sie Ihre Standards:

      <PromptBlock type="playbook">
        ```txt Payments Test Playbook theme={null}
        ## Procedure
        1. Read the target payment module and identify all exported functions
        2. Study existing test files in src/services/__tests__/ for patterns
        3. Create a test file named {Module}.test.ts in __tests__/ next to the source
        4. Write tests using the AAA pattern (Arrange, Act, Assert)
        5. Mock the Stripe SDK with jest.mock('stripe') — never call real payment APIs
        6. Mock database calls with the helpers from src/test/helpers.ts
        7. Use integer cents for all currency values — never floating-point dollars
        8. Test idempotency: calling processCharge twice with the same idempotency key must not create duplicate charges
        9. Cover success paths, error paths, and edge cases for every function
        10. Run `npm test -- --coverage` and verify 90%+ line coverage for the file

        ## Specifications
        - Framework: Jest with TypeScript
        - Mocking: jest.mock() for Stripe SDK, jest.spyOn() for internal methods
        - Currency: Always use integer cents (e.g., 2999 not 29.99)
        - Assertions: Prefer specific matchers (toHaveBeenCalledWith, toThrow)
        - Naming: describe('PaymentService') > describe('processCharge') > it('charges a valid card')

        ## Forbidden Actions
        - Do not call real Stripe, PayPal, or any live payment gateway in tests
        - Do not use floating-point arithmetic for currency calculations
        - Do not modify the source module to make it easier to test
        - Do not skip idempotency or retry-logic edge cases
        ```
      </PromptBlock>

      **Option 2: Lassen Sie Devin das Playbook für Sie erstellen.** Beschreiben Sie Ihre Testkonventionen, und Devin generiert ein vollständiges Playbook:

      <PromptBlock agent="advanced">
        ```txt Generate a payments test playbook theme={null}
        Create a playbook for writing unit tests for our payment modules in
        src/services/. We use Jest with TypeScript, mock the Stripe SDK with
        jest.mock('stripe'), and use integer cents for all currency values.
        Look at our existing tests in src/services/__tests__/ to learn our
        patterns (AAA style, specific matchers, describe/it naming). The
        playbook should cover mocking strategy, idempotency testing, currency
        precision rules, and forbidden actions like calling real payment APIs.
        ```
      </PromptBlock>

      Fügen Sie dann Ihre beste bestehende Testdatei (z. B. `src/services/__tests__/UserService.test.ts`) als [Knowledge](/de/product-guides/knowledge)-Eintrag hinzu, damit Devin ein konkretes Beispiel für den Stil Ihres Teams hat.
    </Step>

    <Step title="Nicht getesteten Zahlungscode erkennen">
      Bevor Sie Devin auf bestimmte Dateien ansetzen, ermitteln Sie, wo die größten Lücken in Ihren Zahlungsmodulen sind. Bitten Sie Devin, Ihr Coverage-Tool auszuführen und Ihnen die größten Problemstellen zu zeigen:

      <PromptBlock>
        ```txt Analysiere die Abdeckung des Zahlungsmoduls theme={null}
        Führe npm test -- --coverage aus und liste jede Datei unter src/services/
        auf, die Zahlungen, Abrechnung oder Abonnements verarbeitet und weniger als 80%
        Zeilenabdeckung hat. Sortiere nach aufsteigender Abdeckung, damit ich die größten
        Lücken zuerst sehen kann.
        ```
      </PromptBlock>

      Devin führt die Test-Suite in seinem Terminal aus, wertet den Coverage-Bericht aus und liefert Ihnen eine priorisierte Liste:

      ```
      File                                | Lines | Uncovered functions
      ------------------------------------|-------|------------------------------
      src/services/PaymentService.ts      |  34%  | processCharge, issueRefund, handleWebhook
      src/services/SubscriptionService.ts |  41%  | renewSubscription, cancelTrial, proratePlan
      src/services/InvoiceService.ts      |  52%  | generateInvoice, applyPromoCode, calculateTax
      src/services/PayoutService.ts       |  58%  | initiateTransfer, reconcileSettlement
      ```
    </Step>

    <Step title="Lassen Sie Devin Tests für PaymentService erstellen">
      Starte eine neue Session, hänge dein Zahlungs-Test-Playbook an (du siehst einen blauen Pillen-Indikator, der bestätigt, dass es angehängt ist), und sag Devin, welches Modul abgedeckt werden soll:

      <PromptBlock>
        ```txt Write tests for PaymentService theme={null}
        Write unit tests for all untested functions in
        src/services/PaymentService.ts. Focus on processCharge,
        issueRefund, and handleWebhook. Each function needs tests for
        success, error, and edge cases. Mock the Stripe SDK — never call
        real APIs. Use integer cents for all currency values. Run the
        tests and verify 90%+ line coverage for this file.
        ```
      </PromptBlock>

      Devin liest das Modul, analysiert deine bestehenden Tests auf Muster, schreibt eine umfassende Testdatei gemäß deinem Playbook und führt sie aus:

      ```
      PASS src/services/__tests__/PaymentService.test.ts
        PaymentService
          processCharge
            ✓ charges a valid credit card and returns a receipt (14ms)
            ✓ uses integer cents to avoid floating-point errors (6ms)
            ✓ rejects duplicate charges with the same idempotency key (5ms)
            ✓ retries on Stripe gateway timeout up to 3 times (18ms)
            ✓ throws InsufficientFundsError for declined cards (4ms)
          issueRefund
            ✓ refunds full amount for a completed charge (8ms)
            ✓ refunds partial amount in cents when specified (6ms)
            ✓ prevents refund exceeding the original charge amount (3ms)
            ✓ throws AlreadyRefundedError on duplicate refund attempts (4ms)
          handleWebhook
            ✓ processes charge.succeeded events and updates order status (7ms)
            ✓ processes charge.refunded events and credits the customer (6ms)
            ✓ verifies Stripe webhook signature before processing (3ms)
            ✓ ignores unrecognized event types without error (2ms)

      Coverage: 94% lines | 91% branches | 100% functions
      ```

      Devin eröffnet einen Pull Request (PR) mit der Testdatei und einer Zusammenfassung der Testabdeckung im Beschreibungstext.
    </Step>

    <Step title="Bearbeiten Sie die restlichen Zahlungsmodule">
      Überprüfen Sie den ersten Pull Request (PR). Wenn die Mock-Strategie oder der Assertionsstil noch nicht ganz passt, aktualisieren Sie Ihr Playbook, bevor Sie es auf weitere Module anwenden — eine Feedback-Runde erspart Ihnen, denselben Fehler in mehreren PRs korrigieren zu müssen.

      Arbeiten Sie dann Ihre Lückenliste ab:

      <PromptBlock>
        ```txt SubscriptionService abdecken theme={null}
        Tests für src/services/SubscriptionService.ts mit demselben
        Playbook schreiben. Fokus auf renewSubscription, cancelTrial
        und proratePlan. Prorationslogik mit ganzzahligen Cents testen.
        Ziel: über 90 % Zeilenabdeckung.
        ```
      </PromptBlock>

      Um schneller zu sein, bitten Sie Devin, parallele Sitzungen zu starten — eine pro Zahlungsmodul —, die alle demselben Playbook folgen. Oder [planen](/de/product-guides/scheduled-sessions) Sie eine wöchentliche Sitzung ein, die alle Zahlungsmodule findet, deren Testabdeckung unter Ihren Schwellenwert gefallen ist, und automatisch Tests dafür schreibt.
    </Step>
  </Steps>
</div>
