forked from ubiquity-os/ubiquity-os-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ubiquity-os#55 from gentlementlegen/fix/target-bra…
…nch-dispatch chore: added test types and test for configuration
- Loading branch information
Showing
8 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
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,15 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
export class WebhooksMocked { | ||
constructor(_: unknown) {} | ||
verifyAndReceive(_: unknown) { | ||
return Promise.resolve(); | ||
} | ||
onAny(_: unknown) {} | ||
on(_: unknown) {} | ||
onError(_: unknown) {} | ||
removeListener(_: unknown, __: unknown) {} | ||
sign(_: unknown) {} | ||
verify(_: unknown, __: unknown) {} | ||
receive(_: unknown) {} | ||
} |
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,79 @@ | ||
import { afterAll, afterEach, beforeAll, describe, expect, it, mock } from "bun:test"; | ||
import { config } from "dotenv"; | ||
import { server } from "./__mocks__/node"; | ||
import { WebhooksMocked } from "./__mocks__/webhooks"; | ||
import { getConfig } from "../src/github/utils/config"; | ||
import { GitHubContext } from "../src/github/github-context"; | ||
import { GitHubEventHandler } from "../src/github/github-event-handler"; | ||
|
||
config({ path: ".dev.vars" }); | ||
|
||
mock.module("@octokit/webhooks", () => ({ | ||
Webhooks: WebhooksMocked, | ||
})); | ||
|
||
const issueOpened = "issues.opened"; | ||
|
||
beforeAll(() => { | ||
server.listen(); | ||
}); | ||
afterEach(() => { | ||
server.resetHandlers(); | ||
}); | ||
afterAll(() => { | ||
server.close(); | ||
}); | ||
|
||
describe("Configuration tests", () => { | ||
it("Should properly parse the Action path if a branch and workflow are specified", async () => { | ||
const cfg = await getConfig({ | ||
key: issueOpened, | ||
name: issueOpened, | ||
id: "", | ||
payload: { | ||
repository: { | ||
owner: { login: "ubiquity" }, | ||
name: "conversation-rewards", | ||
}, | ||
} as unknown as GitHubContext<"issues.closed">["payload"], | ||
octokit: { | ||
rest: { | ||
repos: { | ||
getContent() { | ||
return { | ||
data: ` | ||
plugins: | ||
'issues.labeled': | ||
- uses: | ||
- plugin: ubiquity/user-activity-watcher:compute.yml@pull/1 | ||
type: github | ||
with: | ||
settings1: 'enabled'`, | ||
}; | ||
}, | ||
}, | ||
}, | ||
}, | ||
eventHandler: {} as GitHubEventHandler, | ||
} as unknown as GitHubContext); | ||
expect(cfg.plugins["issues.labeled"]).toEqual([ | ||
{ | ||
uses: [ | ||
{ | ||
plugin: { | ||
owner: "ubiquity", | ||
repo: "user-activity-watcher", | ||
workflowId: "compute.yml", | ||
ref: "pull/1", | ||
}, | ||
type: "github", | ||
with: { | ||
settings1: "enabled", | ||
}, | ||
}, | ||
], | ||
skipBotEvents: true, | ||
}, | ||
]); | ||
}); | ||
}); |
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
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