-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(github): fix 404 not found & init tests
- Loading branch information
Showing
22 changed files
with
104 additions
and
162 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
141 changes: 0 additions & 141 deletions
141
packages/plugin-github/tests/__snapshots__/index.spec.ts.snap
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,45 @@ | ||
module.exports[`commit_comment.created`] = ` | ||
[GitHub] Shigma commented on commit koishijs/koishi@bff469 | ||
URL: https://github.com/koishijs/koishi/commit/bff469eabe14d42683a4f7c3ccb659daec5e1c00#commitcomment-36878220 | ||
This will introduce a failure in test.` | ||
|
||
module.exports[`issue_comment.created.1`] = ` | ||
[GitHub] simon300000 commented on issue koishijs/koishi#19 | ||
URL: https://github.com/koishijs/koishi/issues/19#issuecomment-576277946 | ||
Mich würde auch interessieren, was ist „CoolQ“?` | ||
|
||
module.exports[`issue_comment.created.2`] = ` | ||
[GitHub] Kouchya commented on pull request koishijs/koishi#20 | ||
URL: https://github.com/koishijs/koishi/pull/20#issuecomment-576291300 | ||
C'est important!` | ||
|
||
module.exports[`issues.opened`] = ` | ||
[GitHub] simon300000 opened an issue koishijs/koishi#19 | ||
URL: https://github.com/koishijs/koishi/issues/19 | ||
Title: Wie kann man um das Koishi zu installieren? | ||
Ich verstecke Englisch und Chinesisch nicht! Gab es Personen, die mir helfen kann?` | ||
|
||
module.exports[`pull_request.opened`] = ` | ||
[GitHub] simon300000 opened a pull request koishijs/koishi#20 (koishijs:develop <- koishijs:experimental) | ||
URL: https://github.com/koishijs/koishi/pull/20 | ||
Das ist wichtig!` | ||
|
||
module.exports[`pull_request_review.submitted.2`] = ` | ||
[GitHub] Kouchya reviewed pull request koishijs/koishi#20 | ||
URL: https://github.com/koishijs/koishi/pull/20#pullrequestreview-345349537 | ||
LGTM` | ||
|
||
module.exports[`pull_request_review_comment.created`] = ` | ||
[GitHub] Shigma commented on pull request review koishijs/koishi#20 | ||
Path: packages/test-utils/src/mocks.ts | ||
URL: https://github.com/koishijs/koishi/pull/20#discussion_r368570320 | ||
Naming is so hard......` | ||
|
||
module.exports[`push.commit`] = ` | ||
[GitHub] Shigma pushed to koishijs/koishi:refs/heads/develop | ||
Compare: https://github.com/koishijs/koishi/compare/976c6e8f09a4...3ae7e7044d06 | ||
[d7ff34] chore: adjust | ||
[3ae7e7] fix(core): create major context at demand` | ||
|
||
module.exports[`push.tag`] = ` | ||
[GitHub] Shigma published tag koishijs/koishi@1.5.0` |
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 |
---|---|---|
@@ -1,27 +1,54 @@ | ||
import { MockedApp } from 'koishi-test-utils' | ||
import { apply, webhooks } from '../src' | ||
import { App, BASE_SELF_ID, memory } from 'koishi-test-utils' | ||
import { Random } from 'koishi-utils' | ||
import { fn, spyOn } from 'jest-mock' | ||
import { expect } from 'chai' | ||
import { readdirSync } from 'fs-extra' | ||
import { resolve } from 'path' | ||
import * as github from 'koishi-plugin-github' | ||
|
||
const app = new MockedApp({ | ||
githubWebhook: { | ||
secret: 'secret', | ||
}, | ||
const secret = Random.uuid() | ||
|
||
const app = new App({ port: 10000 }) | ||
|
||
app.plugin(memory) | ||
|
||
app.plugin(github, { | ||
secret, | ||
repos: { 'koishijs/koishi': [123] }, | ||
}) | ||
|
||
app.plugin(apply, { | ||
'koishijs/koishi': [123], | ||
// override listen | ||
const listen = spyOn(app.server, 'listen') | ||
listen.mockReturnValue(Promise.resolve()) | ||
|
||
// spy on sendGroupMsg | ||
const sendGroupMsg = app.bots[0].sendGroupMsg = fn() | ||
|
||
before(async () => { | ||
await app.start() | ||
await app.database.getGroup(123, BASE_SELF_ID) | ||
}) | ||
|
||
const webhook = webhooks['/secret12140'] | ||
const snapshot = require('./index.snap') | ||
|
||
readdirSync(resolve(__dirname, '__fixtures__')).forEach((file) => { | ||
file = file.slice(0, -5) | ||
const [name] = file.split('.', 1) | ||
const payload = require(`./__fixtures__/${file}`) | ||
function check(file: string) { | ||
it(file, async () => { | ||
sendGroupMsg.mockClear() | ||
const payload = require(`./fixtures/${file}`) | ||
const [name] = file.split('.', 1) | ||
await app.githubWebhooks.receive({ id: Random.uuid(), name, payload }) | ||
if (snapshot[file]) { | ||
expect(sendGroupMsg.mock.calls).to.have.length(1) | ||
expect(sendGroupMsg.mock.calls[0][1]).to.equal(snapshot[file].trim()) | ||
} else { | ||
expect(sendGroupMsg.mock.calls).to.have.length(0) | ||
} | ||
}) | ||
} | ||
|
||
test(file, async () => { | ||
await webhook.receive({ id: 'id', name, payload }) | ||
app.shouldMatchSnapshot(file) | ||
describe('koishi-plugin-github', () => { | ||
const files = readdirSync(resolve(__dirname, 'fixtures')) | ||
files.forEach(file => { | ||
check(file.slice(0, -5)) | ||
}) | ||
}) |