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/
File renamed without changes.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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 @@ -185,11 +189,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/deno_slack_sdk@2.15.0/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.8.0/"
}
}
6 changes: 3 additions & 3 deletions functions/sample_function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import SampleObjectDatastore from "../datastores/sample_datastore.ts";
import type SampleObjectDatastore from "../datastores/sample_datastore.ts";

/**
* Functions are reusable building blocks of automation that accept
Expand Down Expand Up @@ -49,8 +49,8 @@ export default SlackFunction(

// inputs.user is set from the interactivity_context defined in sample_trigger.ts
// https://api.slack.com/automation/forms#add-interactivity
const updatedMsg = `:wave: ` + `<@${inputs.user}>` +
` submitted the following message: \n\n>${inputs.message}`;
const updatedMsg =
`:wave: <@${inputs.user}> submitted the following message: \n\n>${inputs.message}`;
Comment on lines +52 to +53
Copy link
Member

Choose a reason for hiding this comment

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


const sampleObject = {
original_msg: inputs.message,
Expand Down
64 changes: 38 additions & 26 deletions functions/sample_function_test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { SlackFunctionTester } from "deno-slack-sdk/mod.ts";
import {
assertEquals,
assertExists,
assertStringIncludes,
} from "std/testing/asserts.ts";
import { assertEquals, assertExists, assertStringIncludes } from "@std/assert";
import { stub } from "@std/testing/mock";
import SampleFunction from "./sample_function.ts";
import * as mf from "mock-fetch/mod.ts";

const { createContext } = SlackFunctionTester("sample_function");

// Replaces globalThis.fetch with the mocked copy
mf.install();
Deno.test("Sample function test", async () => {
// Replaces globalThis.fetch with the mocked copy
using _stubFetch = 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/apps.datastore.put");

// Shared mocks can be defined at the top level of tests
mf.mock("POST@/api/apps.datastore.put", async (args) => {
const body = await args.formData();
const datastore = body.get("datastore");
const item = body.get("item");
const body = await request.formData();
const datastore = body.get("datastore");
const item = body.get("item");

return new Response(
`{"ok": true, "datastore": "${datastore}", "item": ${item}}`,
{
status: 200,
return new Response(
`{"ok": true, "datastore": "${datastore}", "item": ${item}}`,
{
status: 200,
},
);
},
);
});

Deno.test("Sample function test", async () => {
const inputs = { message: "Hello, World!", user: "U01234567" };
const { outputs, error } = await SampleFunction(createContext({ inputs }));

Expand All @@ -38,12 +39,23 @@ Deno.test("Sample function test", async () => {
});

Deno.test("Sample function datastore error handling", async () => {
// Mocks specific to a test can be overriden within a test
mf.mock("POST@/api/apps.datastore.put", () => {
return new Response(`{"ok": false, "error": "datastore_error"}`, {
status: 200,
});
});
// Replaces globalThis.fetch with the mocked copy
using _stubFetch = stub(
globalThis,
"fetch",
(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/apps.datastore.put");

return Promise.resolve(
new Response(`{"ok": false, "error": "datastore_error"}`, {
status: 200,
}),
);
},
);

const inputs = { message: "Hello, World!", user: "U01234567" };
const { outputs, error } = await SampleFunction(createContext({ inputs }));
Expand Down
8 changes: 0 additions & 8 deletions import_map.json

This file was deleted.

2 changes: 1 addition & 1 deletion triggers/sample_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";
import SampleWorkflow from "../workflows/sample_workflow.ts";
/**
Expand Down