Skip to content

Commit

Permalink
test(plugins): add missing tests (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
abbesAlexandre authored Jul 8, 2023
1 parent 6464d28 commit 33607a6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
File renamed without changes.
44 changes: 44 additions & 0 deletions test/plugins/nodesecure.spec.ts
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");
});
});
46 changes: 46 additions & 0 deletions test/plugins/scorecard.spec.ts
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);
});
});


0 comments on commit 33607a6

Please sign in to comment.