refactor!: rename chat providers to channels
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const listProviderPairingRequests = vi.fn();
|
||||
const approveProviderPairingCode = vi.fn();
|
||||
const listChannelPairingRequests = vi.fn();
|
||||
const approveChannelPairingCode = vi.fn();
|
||||
const notifyPairingApproved = vi.fn();
|
||||
const pairingIdLabels: Record<string, string> = {
|
||||
telegram: "telegramUserId",
|
||||
discord: "discordUserId",
|
||||
};
|
||||
const requirePairingAdapter = vi.fn((provider: string) => ({
|
||||
idLabel: pairingIdLabels[provider] ?? "userId",
|
||||
const requirePairingAdapter = vi.fn((channel: string) => ({
|
||||
idLabel: pairingIdLabels[channel] ?? "userId",
|
||||
}));
|
||||
const listPairingProviders = vi.fn(() => ["telegram", "discord"]);
|
||||
const resolvePairingProvider = vi.fn((raw: string) => raw);
|
||||
const listPairingChannels = vi.fn(() => ["telegram", "discord"]);
|
||||
const resolvePairingChannel = vi.fn((raw: string) => raw);
|
||||
|
||||
vi.mock("../pairing/pairing-store.js", () => ({
|
||||
listProviderPairingRequests,
|
||||
approveProviderPairingCode,
|
||||
listChannelPairingRequests,
|
||||
approveChannelPairingCode,
|
||||
}));
|
||||
|
||||
vi.mock("../providers/plugins/pairing.js", () => ({
|
||||
listPairingProviders,
|
||||
resolvePairingProvider,
|
||||
vi.mock("../channels/plugins/pairing.js", () => ({
|
||||
listPairingChannels,
|
||||
resolvePairingChannel,
|
||||
notifyPairingApproved,
|
||||
requirePairingAdapter,
|
||||
}));
|
||||
@@ -33,7 +33,7 @@ vi.mock("../config/config.js", () => ({
|
||||
describe("pairing cli", () => {
|
||||
it("labels Telegram ids as telegramUserId", async () => {
|
||||
const { registerPairingCli } = await import("./pairing-cli.js");
|
||||
listProviderPairingRequests.mockResolvedValueOnce([
|
||||
listChannelPairingRequests.mockResolvedValueOnce([
|
||||
{
|
||||
id: "123",
|
||||
code: "ABC123",
|
||||
@@ -47,7 +47,7 @@ describe("pairing cli", () => {
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerPairingCli(program);
|
||||
await program.parseAsync(["pairing", "list", "--provider", "telegram"], {
|
||||
await program.parseAsync(["pairing", "list", "--channel", "telegram"], {
|
||||
from: "user",
|
||||
});
|
||||
expect(log).toHaveBeenCalledWith(
|
||||
@@ -55,21 +55,21 @@ describe("pairing cli", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts provider as positional for list", async () => {
|
||||
it("accepts channel as positional for list", async () => {
|
||||
const { registerPairingCli } = await import("./pairing-cli.js");
|
||||
listProviderPairingRequests.mockResolvedValueOnce([]);
|
||||
listChannelPairingRequests.mockResolvedValueOnce([]);
|
||||
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerPairingCli(program);
|
||||
await program.parseAsync(["pairing", "list", "telegram"], { from: "user" });
|
||||
|
||||
expect(listProviderPairingRequests).toHaveBeenCalledWith("telegram");
|
||||
expect(listChannelPairingRequests).toHaveBeenCalledWith("telegram");
|
||||
});
|
||||
|
||||
it("labels Discord ids as discordUserId", async () => {
|
||||
const { registerPairingCli } = await import("./pairing-cli.js");
|
||||
listProviderPairingRequests.mockResolvedValueOnce([
|
||||
listChannelPairingRequests.mockResolvedValueOnce([
|
||||
{
|
||||
id: "999",
|
||||
code: "DEF456",
|
||||
@@ -83,7 +83,7 @@ describe("pairing cli", () => {
|
||||
const program = new Command();
|
||||
program.name("test");
|
||||
registerPairingCli(program);
|
||||
await program.parseAsync(["pairing", "list", "--provider", "discord"], {
|
||||
await program.parseAsync(["pairing", "list", "--channel", "discord"], {
|
||||
from: "user",
|
||||
});
|
||||
expect(log).toHaveBeenCalledWith(
|
||||
@@ -91,9 +91,9 @@ describe("pairing cli", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts provider as positional for approve (npm-run compatible)", async () => {
|
||||
it("accepts channel as positional for approve (npm-run compatible)", async () => {
|
||||
const { registerPairingCli } = await import("./pairing-cli.js");
|
||||
approveProviderPairingCode.mockResolvedValueOnce({
|
||||
approveChannelPairingCode.mockResolvedValueOnce({
|
||||
id: "123",
|
||||
entry: {
|
||||
id: "123",
|
||||
@@ -111,8 +111,8 @@ describe("pairing cli", () => {
|
||||
from: "user",
|
||||
});
|
||||
|
||||
expect(approveProviderPairingCode).toHaveBeenCalledWith({
|
||||
provider: "telegram",
|
||||
expect(approveChannelPairingCode).toHaveBeenCalledWith({
|
||||
channel: "telegram",
|
||||
code: "ABCDEFGH",
|
||||
});
|
||||
expect(log).toHaveBeenCalledWith(expect.stringContaining("Approved"));
|
||||
|
||||
Reference in New Issue
Block a user