import type { TestProject } from "vitest/node";
import { show, listMachineUsers, getMachineUserToken } from "@tailor-platform/sdk/cli";

declare module "vitest" {
  export interface ProvidedContext {
    url: string;
    token: string;
  }
}

export async function setup(project: TestProject) {
  const app = await show();
  const url = app.url;

  const machineUsers = await listMachineUsers();
  const tokens = await getMachineUserToken({ name: machineUsers[0].name });
  const token = tokens.accessToken;

  project.provide("url", url);
  project.provide("token", token);
}
