Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
8 changes: 5 additions & 3 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Deno app build and testing

on:
push:
branches: [ main ]
branches:
- main
pull_request:
branches: [ main ]
branches:
- main

jobs:
deno:
Expand All @@ -18,7 +20,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
deno-version: v2.x

- name: Verify formatting
run: deno fmt --check
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
dist
package
.DS_Store
.slack/apps.dev.json
2 changes: 2 additions & 0 deletions .slack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apps.dev.json
cache/
1 change: 0 additions & 1 deletion .slack/apps.json

This file was deleted.

File renamed without changes.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ $ slack activity --tail
Contains `apps.dev.json` and `apps.json`, which include installation details for
development and deployed apps.

Contains `hooks.json` used by the CLI to interact with the project's SDK
dependencies. It contains script hooks that are executed by the CLI and
implemented by the SDK.

### `datastores/`

[Datastores](https://api.slack.com/automation/datastores) securely store data
Expand Down Expand Up @@ -189,11 +193,6 @@ continuing to the next step.
The [app manifest](https://api.slack.com/automation/manifest) contains the app's
configuration. This file defines attributes like app name and description.

### `slack.json`

Used by the CLI to interact with the project's SDK dependencies. It contains
script hooks that are executed by the CLI and implemented by the SDK.

## Resources

To learn more about developing automations on Slack, visit the following:
Expand Down
11 changes: 8 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"$schema": "https://raw.githubusercontent.com/denoland/deno/main/cli/schemas/config-file.v1.json",
"fmt": {
"include": [
"README.md",
Expand All @@ -13,7 +13,6 @@
"workflows"
]
},
"importMap": "import_map.json",
"lint": {
"include": [
"datastores",
Expand All @@ -28,6 +27,12 @@
},
"lock": false,
"tasks": {
"test": "deno fmt --check && deno lint && deno test --allow-read --allow-none"
"test": "deno fmt --check && deno lint && deno test --allow-read"
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.13",
"@std/testing": "jsr:@std/testing@^1.0.12",
"deno-slack-sdk/": "https://deno.land/x/[email protected]/",
"deno-slack-api/": "https://deno.land/x/[email protected]/"
}
}
2 changes: 1 addition & 1 deletion functions/send_time_off_request_to_manager/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function timeOffRequestHeaderBlocks(inputs: any): any[] {
type: "header",
text: {
type: "plain_text",
text: `A new time-off request has been submitted`,
text: "A new time-off request has been submitted",
},
},
{
Expand Down
10 changes: 5 additions & 5 deletions functions/send_time_off_request_to_manager/blocks_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "@std/assert";
import timeOffRequestHeaderBlocks from "./blocks.ts";

Deno.test("timeOffRequestHeaderBlocks generates valid blocks for inputs without reason", async () => {
Deno.test("timeOffRequestHeaderBlocks generates valid blocks for inputs without reason", () => {
const expectedBlocks = [
{
type: "header",
Expand All @@ -17,15 +17,15 @@ Deno.test("timeOffRequestHeaderBlocks generates valid blocks for inputs without
},
{ type: "section", text: { type: "mrkdwn", text: "*Reason:* N/A" } },
];
const blocks = await timeOffRequestHeaderBlocks({
const blocks = timeOffRequestHeaderBlocks({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Great catch!

employee: "U12345",
start_date: "2022-03-01",
end_date: "2022-03-10",
});
assertEquals(blocks, expectedBlocks);
});

Deno.test("timeOffRequestHeaderBlocks generates valid blocks for full inputs", async () => {
Deno.test("timeOffRequestHeaderBlocks generates valid blocks for full inputs", () => {
const expectedBlocks = [
{
type: "header",
Expand All @@ -44,7 +44,7 @@ Deno.test("timeOffRequestHeaderBlocks generates valid blocks for full inputs", a
text: { type: "mrkdwn", text: "*Reason:* On vacation!" },
},
];
const blocks = await timeOffRequestHeaderBlocks({
const blocks = timeOffRequestHeaderBlocks({
employee: "U12345",
start_date: "2022-03-01",
end_date: "2022-03-10",
Expand Down
51 changes: 29 additions & 22 deletions functions/send_time_off_request_to_manager/mod_test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import * as mf from "https://deno.land/x/[email protected]/mod.ts";
import { stub } from "@std/testing/mock";
import { SlackFunctionTester } from "deno-slack-sdk/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { assertEquals } from "@std/assert";
import handler from "./mod.ts";

// Replaces globalThis.fetch with the mocked copy
mf.install();

mf.mock("POST@/api/chat.postMessage", async (req) => {
const body = await req.formData();
if (body.get("channel")?.toString() !== "U22222") {
return new Response(`{"ok": false, "error": "unexpected channel ID"}`, {
status: 200,
});
}
if (body.get("blocks") === undefined) {
return new Response(`{"ok": false, "error": "blocks are missing!"}`, {
status: 200,
});
}
return new Response(`{"ok": true, "message": {"ts": "111.222"}}`, {
status: 200,
});
});

const { createContext } = SlackFunctionTester("my-function");

Deno.test("SendTimeOffRequestToManagerFunction runs successfully", async () => {
// Replaces globalThis.fetch with the mocked copy
using _fetchStub = stub(
globalThis,
"fetch",
async (url: string | URL | Request, options?: RequestInit) => {
const request = url instanceof Request ? url : new Request(url, options);

assertEquals(request.method, "POST");
assertEquals(request.url, "https://slack.com/api/chat.postMessage");

const body = await request.formData();
if (body.get("channel")?.toString() !== "U22222") {
return new Response(`{"ok": false, "error": "unexpected channel ID"}`, {
status: 200,
});
}
if (body.get("blocks") === undefined) {
return new Response(`{"ok": false, "error": "blocks are missing!"}`, {
status: 200,
});
}
return new Response(`{"ok": true, "message": {"ts": "111.222"}}`, {
status: 200,
});
},
);

const inputs = {
employee: "U11111",
manager: "U22222",
Expand Down
6 changes: 0 additions & 6 deletions import_map.json

This file was deleted.

2 changes: 1 addition & 1 deletion triggers/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trigger } from "deno-slack-sdk/types.ts";
import type { Trigger } from "deno-slack-sdk/types.ts";
import { TriggerContextData, TriggerTypes } from "deno-slack-api/mod.ts";

const trigger: Trigger = {
Expand Down