Skip to content

Commit

Permalink
helloworld: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hakatashi committed Oct 9, 2024
1 parent a07f692 commit 7a1959d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
38 changes: 34 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@
"version": "0.2.0",
"configurations": [
{
"name": "Slackbot起動",
"type": "node",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"dev",
"--",
"--only",
"${input:onlyArgument}"
],
"request": "launch",
"name": "Slackbot起動",
"skipFiles": [
"<node_internals>/**"
],
"console": "internalConsole",
"outputCapture": "std"
},
{
"name": "ユニットテストの実行",
"type": "node",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script", "dev", "--", "--only", "${input:onlyArgument}"
]
"args": [
"run-script",
"test",
"--",
"${input:testFilterArgument}"
],
"internalConsoleOptions": "openOnSessionStart",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"console": "internalConsole",
"outputCapture": "std"
}
],
"inputs": [
Expand All @@ -20,6 +44,12 @@
"type": "promptString",
"description": "起動するBOTの種類",
"default": "helloworld"
},
{
"id": "testFilterArgument",
"type": "promptString",
"description": "実行するユニットテストの正規表現フィルタ",
"default": "**/*.{js,ts}"
}
]
}
2 changes: 1 addition & 1 deletion helloworld/HelloWorld.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('helloworld', () => {
elements: [
{
type: 'plain_text',
text: '⚠この値は再起動後も保存されますが、再起動前に投稿されたメッセージの数字は更新されなくなります。ボタンを押すとエラーが出る場合は、「Slackbotを作ろう」ページの「WebSocketトンネルをセットアップする」などを参考に Event API のセットアップが正常にできているかもう一度確認してください。',
text: '⚠この値は再起動後も保存されます。前回このメッセージを投稿してから60分以上経っている場合はメッセージが再投稿されますが、以前のメッセージの数字は更新されなくなります。ボタンを押すとエラーが出る場合は、「Slackbotを作ろう」ページの「WebSocketトンネルをセットアップする」などを参考に Event API のセットアップが正常にできているかもう一度確認してください。',
emoji: true,
},
],
Expand Down
22 changes: 11 additions & 11 deletions helloworld/HelloWorld.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {randomUUID} from 'crypto';
import { randomUUID } from 'crypto';
import type EventEmitter from 'events';
import os from 'os';
import type {BlockAction, ViewSubmitAction} from '@slack/bolt';
import type {SlackMessageAdapter} from '@slack/interactive-messages';
import type {MessageEvent, WebClient} from '@slack/web-api';
import {Mutex} from 'async-mutex';
import type { BlockAction, ViewSubmitAction } from '@slack/bolt';
import type { SlackMessageAdapter } from '@slack/interactive-messages';
import type { MessageEvent, WebClient } from '@slack/web-api';
import { Mutex } from 'async-mutex';
import logger from '../lib/logger';
import type {SlackInterface} from '../lib/slack';
import {extractMessage} from '../lib/slackUtils';
import type { SlackInterface } from '../lib/slack';
import { extractMessage } from '../lib/slackUtils';
import State from '../lib/state';
import counterEditDialog from './views/counterEditDialog';
import helloWorldMessage from './views/helloWorldMessage';

export interface StateObj {
uuid: string,
counter: number,
latestStatusMessage: {ts: string, channel: string} | null,
latestStatusMessage: { ts: string, channel: string } | null,
}

const mutex = new Mutex();

const log = logger.child({bot: 'helloworld'});
const log = logger.child({ bot: 'helloworld' });

export class HelloWorld {
#slack: WebClient;
Expand Down Expand Up @@ -110,7 +110,7 @@ export class HelloWorld {

// 「Hello, World!」メッセージを#sandboxに送信する
async postHelloWorld() {
if (this.#state.latestStatusMessage.channel === this.#SANDBOX_ID) {
if (this.#state.latestStatusMessage?.channel === this.#SANDBOX_ID) {
const timestamp = new Date(parseInt(this.#state.latestStatusMessage.ts) * 1000);
const elapsed = (Date.now() - timestamp.getTime()) / 1000;
if (elapsed < 60 * 60) {
Expand Down Expand Up @@ -152,7 +152,7 @@ export class HelloWorld {
}

// カウンター編集ダイアログを表示する
private async showCounterEditDialog({triggerId}: {triggerId: string}) {
private async showCounterEditDialog({ triggerId }: { triggerId: string }) {
log.info('Showing counter edit dialog');

await this.#slack.views.open({
Expand Down

0 comments on commit 7a1959d

Please sign in to comment.