Download src/slack/blocks-input.test.ts from Darochin/openskynet: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/Darochin/openskynet/resolve/main/src/slack/blocks-input.test.ts
- Command line
-
hf download hf://Darochin/openskynet/src/slack/blocks-input.test.ts
-
curl -L -o blocks-input.test.ts https://huggingface.co/Darochin/openskynet/resolve/main/src/slack/blocks-input.test.ts
1.63 kB
| import { describe, expect, it } from "vitest"; | |
| import { parseSlackBlocksInput } from "./blocks-input.js"; | |
| describe("parseSlackBlocksInput", () => { | |
| it("returns undefined when blocks are missing", () => { | |
| expect(parseSlackBlocksInput(undefined)).toBeUndefined(); | |
| expect(parseSlackBlocksInput(null)).toBeUndefined(); | |
| }); | |
| it("accepts blocks arrays", () => { | |
| const parsed = parseSlackBlocksInput([{ type: "divider" }]); | |
| expect(parsed).toEqual([{ type: "divider" }]); | |
| }); | |
| it("accepts JSON blocks strings", () => { | |
| const parsed = parseSlackBlocksInput( | |
| '[{"type":"section","text":{"type":"mrkdwn","text":"hi"}}]', | |
| ); | |
| expect(parsed).toEqual([{ type: "section", text: { type: "mrkdwn", text: "hi" } }]); | |
| }); | |
| it("rejects invalid block payloads", () => { | |
| const cases = [ | |
| { | |
| name: "invalid JSON", | |
| input: "{bad-json", | |
| expectedMessage: /valid JSON/i, | |
| }, | |
| { | |
| name: "non-array payload", | |
| input: { type: "divider" }, | |
| expectedMessage: /must be an array/i, | |
| }, | |
| { | |
| name: "empty array", | |
| input: [], | |
| expectedMessage: /at least one block/i, | |
| }, | |
| { | |
| name: "non-object block", | |
| input: ["not-a-block"], | |
| expectedMessage: /must be an object/i, | |
| }, | |
| { | |
| name: "missing block type", | |
| input: [{}], | |
| expectedMessage: /non-empty string type/i, | |
| }, | |
| ] as const; | |
| for (const testCase of cases) { | |
| expect(() => parseSlackBlocksInput(testCase.input), testCase.name).toThrow( | |
| testCase.expectedMessage, | |
| ); | |
| } | |
| }); | |
| }); | |