Personal Telegram developer console for GitHub

test: define workspace validation and recovery UX

davoodmehraban89 committed Oct 4, 2026 at 07:27 UTC 24ff95ebb0b66be02d5468c8277f7d2d0421687c
1 file changed +76
test/workspace-recovery-validation.test.js new
+76
@@ -0,0 +1,76 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { NexaDevBot } from '../src/bot.js';
4 +
5 +const OWNER = 42;
6 +const WORKSPACE_ID = 'Ab12_cdEfG';
7 +const REPO_ID = 123;
8 +
9 +function buttons(markup) {
10 + return markup?.inline_keyboard?.flat() || [];
11 +}
12 +
13 +function makeBot({ routerError, workspace = { id: WORKSPACE_ID, repoId: REPO_ID } } = {}) {
14 + const bot = new NexaDevBot({ TELEGRAM_WEBHOOK_SECRET: 'recovery-test-secret' });
15 + bot.router = {
16 + async dispatchCallback() {
17 + throw routerError || new Error('temporary provider failure');
18 + }
19 + };
20 + bot.workspaceStore = {
21 + async getWorkspace({ ownerId, workspaceId }) {
22 + assert.equal(ownerId, String(OWNER));
23 + assert.equal(workspaceId, WORKSPACE_ID);
24 + return workspace;
25 + }
26 + };
27 + const edits = [];
28 + bot.telegram = {
29 + async answerCallbackQuery() { return { ok: true }; },
30 + async editMessageText(chatId, messageId, text, replyMarkup) {
31 + edits.push({ chatId, messageId, text, replyMarkup });
32 + return { ok: true };
33 + }
34 + };
35 + return { bot, edits };
36 +}
37 +
38 +function query(data) {
39 + return {
40 + id: 'cb-recovery',
41 + data,
42 + from: { id: OWNER },
43 + message: { chat: { id: 7 }, message_id: 9 }
44 + };
45 +}
46 +
47 +test('ready without a commit message shows explicit validation and preserves workspace recovery actions', async () => {
48 + const { bot, edits } = makeBot({ routerError: new Error('Commit message is required') });
49 +
50 + const result = await bot.handleCallbackQuery(query(`wready:${WORKSPACE_ID}`));
51 +
52 + assert.equal(result.ok, false);
53 + assert.equal(edits.length, 1);
54 + assert.match(edits[0].text, /پیام Commit/);
55 + assert.doesNotMatch(edits[0].text, /دریافت اطلاعات از سرویس/);
56 +
57 + const callbacks = buttons(edits[0].replyMarkup).map(button => button.callback_data);
58 + assert.ok(callbacks.includes(`wmsg:${WORKSPACE_ID}`));
59 + assert.ok(callbacks.includes(`ws:${WORKSPACE_ID}`));
60 + assert.ok(callbacks.includes(`repo:${REPO_ID}`));
61 + assert.ok(callbacks.includes('menu:main'));
62 +});
63 +
64 +test('workspace callback failure keeps retry, draft, project and main-menu recovery routes', async () => {
65 + const { bot, edits } = makeBot({ routerError: new Error('temporary provider failure') });
66 +
67 + const result = await bot.handleCallbackQuery(query(`wdiff:${WORKSPACE_ID}`));
68 +
69 + assert.equal(result.ok, false);
70 + assert.equal(edits.length, 1);
71 + const callbacks = buttons(edits[0].replyMarkup).map(button => button.callback_data);
72 + assert.ok(callbacks.includes(`wdiff:${WORKSPACE_ID}`));
73 + assert.ok(callbacks.includes(`ws:${WORKSPACE_ID}`));
74 + assert.ok(callbacks.includes(`repo:${REPO_ID}`));
75 + assert.ok(callbacks.includes('menu:main'));
76 +});