-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(plugins): add missing tests (#56)
- Loading branch information
1 parent
6464d28
commit 33607a6
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Import Node.js Dependencies | ||
import { after, describe, it } from "node:test"; | ||
import assert from "node:assert"; | ||
|
||
// Import Third-party Dependencies | ||
import { MockAgent, setGlobalDispatcher } from "undici"; | ||
|
||
// Import Internal Dependencies | ||
import { execute } from "../../src/plugins/nodesecure"; | ||
|
||
const kApiUrl = "https://api.securityscorecards.dev"; | ||
|
||
describe("execute()", async() => { | ||
const mockAgent = new MockAgent(); | ||
mockAgent.disableNetConnect(); | ||
|
||
const mockPool = mockAgent.get(kApiUrl); | ||
|
||
setGlobalDispatcher(mockAgent); | ||
|
||
after(async() => { | ||
await mockAgent.close(); | ||
}); | ||
|
||
it("should not add plugin", async() => { | ||
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(404).times(1); | ||
|
||
const repo: any = { name: "ossf-scorecard-sdk", plugins: {}, package_name: null }; | ||
|
||
await execute("NodeSecure", repo); | ||
assert.equal(repo.package_name, null); | ||
}); | ||
|
||
it("should add plugin", async() => { | ||
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(200, { foo: "bar" }, { | ||
headers: { "Content-Type": "application/json" } | ||
}).times(1); | ||
|
||
const repo: any = { name: "cli", plugins: {}, package_name: "@nodesecure/cli" }; | ||
|
||
await execute("NodeSecure", repo); | ||
assert.equal(repo.plugins.nodesecure.foo, "bar"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Import Node.js Dependencies | ||
import { after, describe, it } from "node:test"; | ||
import assert from "node:assert"; | ||
|
||
// Import Third-party Dependencies | ||
import { MockAgent, setGlobalDispatcher } from "undici"; | ||
|
||
// Import Internal Dependencies | ||
import { execute } from "../../src/plugins/scorecard"; | ||
|
||
const kApiUrl = "https://api.securityscorecards.dev"; | ||
|
||
describe("execute()", async() => { | ||
const mockAgent = new MockAgent(); | ||
mockAgent.disableNetConnect(); | ||
|
||
const mockPool = mockAgent.get(kApiUrl); | ||
|
||
setGlobalDispatcher(mockAgent); | ||
|
||
after(async() => { | ||
await mockAgent.close(); | ||
}); | ||
|
||
it("should fetch scorecard", async() => { | ||
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(200, { foo: "bar" }, { | ||
headers: { "Content-Type": "application/json" } | ||
}).times(1); | ||
|
||
const repo: any = { name: "ossf-scorecard-sdk", plugins: {} }; | ||
|
||
await execute("NodeSecure", repo); | ||
assert.equal(repo.plugins.scorecard.foo, "bar"); | ||
}); | ||
|
||
it("should return null", async() => { | ||
mockPool.intercept({ path: "/projects/github.com/NodeSecure/cli" }).reply(404).times(1); | ||
|
||
const repo: any = { name: "cli", plugins: {} }; | ||
|
||
await execute("NodeSecure", repo); | ||
assert.equal(repo.plugins.scorecard, null); | ||
}); | ||
}); | ||
|
||
|