All files / src/commands test-commands.ts

44.04% Statements 37/84
100% Branches 0/0
100% Functions 0/0
44.04% Lines 37/84

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 851x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                               1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x  
import * as vscode from "vscode";
import { fetchSuggestions } from "../api/suggestion-api";
import { getIncorrectChoices } from "../services/incorrect-tracker-service";
import { checkUserSignIn } from "../services/auth-service";
 
 
/**
 * Registers a debug command to manually test suggestion generation.
 *
 * Prompts the user for a custom input prompt, fetches AI suggestions,
 * and displays the results in an information message.
 */
export const testFetchCommand = vscode.commands.registerCommand(
  "clover.testFetch",
  async () => {
    const userInput = await vscode.window.showInputBox({
      prompt: "Enter prompt for suggestion.",
    });
    console.log('Test Fetch: "' + userInput + '"');

    if (userInput) {
      try {
        const { suggestions, error } = await fetchSuggestions(userInput);

        if (error) {
          vscode.window.showErrorMessage(`Error: ${error}`);
          return;
        }

        if (!suggestions) {
          vscode.window.showErrorMessage("No suggestions received.");
          return;
        }

        vscode.window.showInformationMessage(
          `Suggestions: ${suggestions.join(", ")}`
        );

        console.log("Suggestions: ", suggestions);
      } catch (error) {
        console.log(error);
        vscode.window.showErrorMessage(`Error: ${error}`);
      }
    }
  }
);
 
/**
 * Registers a debug command to view the incorrect suggestions selected by a user.
 *
 * Retrieves stored incorrect choices and displays them in an information message.
 * (Currently uses a hardcoded test user ID.)
 */
export const incorrectChoicesCommand = vscode.commands.registerCommand(
  "clover.viewIncorrectChoices",
  async () => {
    const userId = "12345";
    const incorrectChoices = getIncorrectChoices(userId);

    if (incorrectChoices.length === 0) {
      vscode.window.showInformationMessage(
        "User does has not chosen an incorrect code suggestion."
      );
    } else {
      vscode.window.showInformationMessage(
        `Incorrect Choices:\n${incorrectChoices
          .map((choice) => `- ${choice.suggestion}`)
          .join("\n")}`
      );
    }
  }
);
 
/**
 * Registers a debug command to force a check of the user's authentication status.
 *
 * Useful for verifying if a user session is active or prompting reauthentication.
 */
export const fetchSettingsCommand = vscode.commands.registerCommand(
  "clover.fetchSettings",
  async () => {
    await checkUserSignIn();
  }
);