feat: add polar x tts and storage integration adapters with tests
This commit is contained in:
80
test/x-client-integration.test.js
Normal file
80
test/x-client-integration.test.js
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { createXAdapter, findParentReplyId } = require("../src/integrations/x-client");
|
||||
|
||||
test("findParentReplyId returns replied_to reference id", () => {
|
||||
const id = findParentReplyId({
|
||||
referenced_tweets: [
|
||||
{ type: "quoted", id: "q1" },
|
||||
{ type: "replied_to", id: "p1" },
|
||||
],
|
||||
});
|
||||
|
||||
assert.equal(id, "p1");
|
||||
});
|
||||
|
||||
test("listMentions fetches mention timeline", async () => {
|
||||
const calls = [];
|
||||
const adapter = createXAdapter({
|
||||
botUserId: "bot-1",
|
||||
client: {
|
||||
v2: {
|
||||
async userMentionTimeline(userId, opts) {
|
||||
calls.push({ userId, opts });
|
||||
return { data: [{ id: "m1" }] };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const mentions = await adapter.listMentions({ sinceId: "100" });
|
||||
assert.equal(mentions.length, 1);
|
||||
assert.equal(calls[0].userId, "bot-1");
|
||||
assert.equal(calls[0].opts.since_id, "100");
|
||||
});
|
||||
|
||||
test("fetchParentPostFromMention resolves parent tweet", async () => {
|
||||
const adapter = createXAdapter({
|
||||
botUserId: "bot-1",
|
||||
client: {
|
||||
v2: {
|
||||
async singleTweet(id) {
|
||||
if (id === "mention-1") {
|
||||
return {
|
||||
data: {
|
||||
id,
|
||||
referenced_tweets: [{ type: "replied_to", id: "parent-1" }],
|
||||
},
|
||||
};
|
||||
}
|
||||
return { data: { id, article: { title: "A", body: "B" } } };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const parent = await adapter.fetchParentPostFromMention("mention-1");
|
||||
assert.equal(parent.id, "parent-1");
|
||||
assert.equal(parent.article.title, "A");
|
||||
});
|
||||
|
||||
test("replyToMention posts a reply", async () => {
|
||||
const calls = [];
|
||||
const adapter = createXAdapter({
|
||||
botUserId: "bot-1",
|
||||
client: {
|
||||
v2: {
|
||||
async reply(text, mentionId) {
|
||||
calls.push({ text, mentionId });
|
||||
return { data: { id: "reply-1" } };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await adapter.replyToMention({ mentionTweetId: "m1", text: "done" });
|
||||
assert.equal(result.data.id, "reply-1");
|
||||
assert.equal(calls[0].mentionId, "m1");
|
||||
});
|
||||
Reference in New Issue
Block a user