-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(addLabel): update Label type & add some integration test (#10)
- Loading branch information
1 parent
c2d3de5
commit e29460a
Showing
8 changed files
with
134 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"event": "issues", | ||
"payload": { | ||
"action": "edited", | ||
"issue": { | ||
"number": 1234, | ||
"labels": [ | ||
{ | ||
"id": 737406747, | ||
"url": "url", | ||
"name": "Polls", | ||
"color": "ededed", | ||
"default": false | ||
} | ||
], | ||
"body": "/polls Option4 'Option 5' \"Option 6\"" | ||
}, | ||
"repository": { | ||
"name": "test", | ||
"owner": { | ||
"login": "evenchange4" | ||
} | ||
}, | ||
"installation": { | ||
"id": 1234 | ||
} | ||
} | ||
} |
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,20 @@ | ||
{ | ||
"event": "issues", | ||
"payload": { | ||
"action": "opened", | ||
"issue": { | ||
"number": 1234, | ||
"labels": [], | ||
"body": "/polls Option1 'Option 2' \"Option 3\"" | ||
}, | ||
"repository": { | ||
"name": "test", | ||
"owner": { | ||
"login": "evenchange4" | ||
} | ||
}, | ||
"installation": { | ||
"id": 1234 | ||
} | ||
} | ||
} |
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,10 +1,62 @@ | ||
// @flow | ||
const main = require('../index'); | ||
|
||
it('should call on', () => { | ||
const mockRobot = { | ||
on: jest.fn(), | ||
}; | ||
main(mockRobot); | ||
expect(mockRobot.on).toHaveBeenCalled(); | ||
const { createRobot } = require('probot'); | ||
const app = require('../index'); | ||
const issueOpenedPayload /* : Object */ = require('./fixtures/issue.opened.json'); | ||
const issueEditedPayload /* : Object */ = require('./fixtures/issue.edited.json'); | ||
|
||
jest.mock('../utils/API', () => ({ | ||
addPoll: () => new Promise(resolve => resolve('ID')), | ||
})); | ||
|
||
/** | ||
* ref: https://probot.github.io/docs/testing/ | ||
*/ | ||
describe('App Integration Test', () => { | ||
let robot /* : Robot */; | ||
let mockGitHubAPI; | ||
|
||
beforeEach(() => { | ||
robot /* : Robot */ = createRobot(); | ||
app(robot); | ||
mockGitHubAPI = { | ||
issues: { | ||
addLabels: jest.fn(), | ||
edit: jest.fn(), | ||
}, | ||
}; | ||
robot.auth = () => Promise.resolve(mockGitHubAPI); | ||
}); | ||
|
||
it('should performs actions when issue opened', async () => { | ||
await robot.receive(issueOpenedPayload); | ||
|
||
expect(mockGitHubAPI.issues.addLabels).toHaveBeenCalledWith({ | ||
labels: ['Polls'], | ||
number: 1234, | ||
owner: 'evenchange4', | ||
repo: 'test', | ||
}); | ||
expect(mockGitHubAPI.issues.edit).toHaveBeenCalledWith({ | ||
body: `[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option1)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option1/vote) | ||
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%202)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%202/vote) | ||
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%203)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%203/vote)`, | ||
number: 1234, | ||
owner: 'evenchange4', | ||
repo: 'test', | ||
}); | ||
}); | ||
|
||
it('should performs actions when issue edited', async () => { | ||
await robot.receive(issueEditedPayload); | ||
|
||
expect(mockGitHubAPI.issues.addLabels).not.toHaveBeenCalled(); | ||
expect(mockGitHubAPI.issues.edit).toHaveBeenCalledWith({ | ||
body: `[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option4)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option4/vote) | ||
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%205)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%205/vote) | ||
[![](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%206)](https://m131jyck4m.execute-api.us-west-2.amazonaws.com/prod/poll/ID/Option%206/vote)`, | ||
number: 1234, | ||
owner: 'evenchange4', | ||
repo: 'test', | ||
}); | ||
}); | ||
}); |
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