|
1 | 1 | import assert from "node:assert"; |
2 | 2 | import { beforeEach, describe, it } from "node:test"; |
| 3 | +import webapi from "@slack/web-api"; |
| 4 | +import sinon from "sinon"; |
3 | 5 | import Config from "../src/config.js"; |
4 | 6 | import SlackError from "../src/errors.js"; |
5 | 7 | import send from "../src/send.js"; |
@@ -158,6 +160,46 @@ describe("config", () => { |
158 | 160 | }); |
159 | 161 | }); |
160 | 162 |
|
| 163 | + describe("instrument", () => { |
| 164 | + it("adds metadata to webapi with package name and version", async () => { |
| 165 | + const stub = sinon.stub(); |
| 166 | + const original = Object.getOwnPropertyDescriptor( |
| 167 | + webapi, |
| 168 | + "addAppMetadata", |
| 169 | + ); |
| 170 | + Object.defineProperty(webapi, "addAppMetadata", { |
| 171 | + value: stub, |
| 172 | + configurable: true, |
| 173 | + }); |
| 174 | + try { |
| 175 | + mocks.core.getInput.withArgs("method").returns("chat.postMessage"); |
| 176 | + mocks.core.getInput.withArgs("token").returns("xoxb-example"); |
| 177 | + new Config(mocks.core); |
| 178 | + assert.ok(stub.calledOnce); |
| 179 | + const { name, version } = stub.firstCall.args[0]; |
| 180 | + assert.equal(name, "@slack/slack-github-action"); |
| 181 | + assert.ok(version); |
| 182 | + } finally { |
| 183 | + Object.defineProperty(webapi, "addAppMetadata", original); |
| 184 | + } |
| 185 | + }); |
| 186 | + |
| 187 | + it("adds metadata to webhook with package name and version", async () => { |
| 188 | + mocks.core.getInput.withArgs("method").returns("chat.postMessage"); |
| 189 | + mocks.core.getInput.withArgs("token").returns("xoxb-example"); |
| 190 | + const config = new Config(mocks.core); |
| 191 | + assert.ok( |
| 192 | + config.axios.defaults.headers.common["User-Agent"].startsWith( |
| 193 | + "@slack:slack-github-action/", |
| 194 | + ), |
| 195 | + ); |
| 196 | + assert.ok( |
| 197 | + config.axios.defaults.headers.common["User-Agent"].length > |
| 198 | + "@slack:slack-github-action/".length, |
| 199 | + ); |
| 200 | + }); |
| 201 | + }); |
| 202 | + |
161 | 203 | describe("mask", async () => { |
162 | 204 | it("treats the provided token as a secret", async () => { |
163 | 205 | mocks.core.getInput.withArgs("token").returns("xoxb-example"); |
|
0 commit comments