2018-12-27 13:11:07 +00:00
|
|
|
const expect = require('chai').expect
|
|
|
|
const sinon = require('sinon')
|
2018-12-18 23:32:01 +00:00
|
|
|
|
2018-12-27 13:11:07 +00:00
|
|
|
const sample = require('./sample')
|
|
|
|
const Builds = require('../src/builds')
|
|
|
|
const Comments = require('../src/comments')
|
2018-12-18 23:32:01 +00:00
|
|
|
|
|
|
|
let comments, client, builds
|
|
|
|
|
2018-12-18 23:43:16 +00:00
|
|
|
/* expected comment based on given builds */
|
|
|
|
const COMMENT = `
|
|
|
|
### Jenkins Builds
|
2018-12-20 08:28:40 +00:00
|
|
|
| :grey_question: | Commit | :hash: | Finished (UTC) | Duration | Platform | Result |
|
2018-12-18 23:43:16 +00:00
|
|
|
|-|-|-|-|-|-|-|
|
2022-11-23 15:10:43 +00:00
|
|
|
| :heavy_check_mark: | COMMIT-0 | [ID-1](URL-1/) | 2018-12-20 08:25:56 | DURATION-1 | \`PLATFORM-1\` | [:robot:\`apk\`](https://example.org/StatusIm-123-456-abc-pr.apk) [:calling:](https://chart.apis.google.com/chart?cht=qr&chs=400x400&chld=L%7C%0A1&chl=https%3A%2F%2Fexample.org%2FStatusIm-123-456-abc-pr.apk)|
|
|
|
|
| :heavy_check_mark: | COMMIT-0 | [ID-2](URL-2/) | 2018-12-20 08:26:53 | DURATION-2 | \`PLATFORM-2\` | [:cd:\`exe\`](https://example.org/StatusIm-123-456-abc-pr.exe) |
|
2018-12-18 23:43:16 +00:00
|
|
|
`
|
|
|
|
|
2019-01-15 21:56:56 +00:00
|
|
|
const COMMENT_FOLDED = `
|
|
|
|
### Jenkins Builds
|
|
|
|
<details>
|
2019-01-16 14:10:22 +00:00
|
|
|
<summary>Click to see older builds (7)</summary>
|
2019-01-15 21:56:56 +00:00
|
|
|
|
|
|
|
| :grey_question: | Commit | :hash: | Finished (UTC) | Duration | Platform | Result |
|
|
|
|
|-|-|-|-|-|-|-|
|
2022-11-23 15:10:43 +00:00
|
|
|
| :heavy_check_mark: | COMMIT-0 | [ID-1](URL-1/) | 2018-12-20 08:25:56 | DURATION-1 | \`PLATFORM-1\` | [:robot:\`apk\`](https://example.org/StatusIm-123-456-abc-pr.apk) [:calling:](https://chart.apis.google.com/chart?cht=qr&chs=400x400&chld=L%7C%0A1&chl=https%3A%2F%2Fexample.org%2FStatusIm-123-456-abc-pr.apk)|
|
|
|
|
| :heavy_check_mark: | COMMIT-0 | [ID-2](URL-2/) | 2018-12-20 08:26:53 | DURATION-2 | \`PLATFORM-2\` | [:cd:\`exe\`](https://example.org/StatusIm-123-456-abc-pr.exe) |
|
2019-09-30 10:25:28 +00:00
|
|
|
| :x: | COMMIT-0 | [ID-3](URL-3/) | 2018-12-20 08:27:50 | DURATION-3 | \`PLATFORM-3\` | [:page_facing_up:\`log\`](URL-3/consoleText) |
|
2019-01-15 21:56:56 +00:00
|
|
|
| | | | | | | |
|
2020-07-06 17:04:07 +00:00
|
|
|
| :heavy_check_mark: | COMMIT-1 | [ID-4](URL-4/) | 2018-12-20 08:28:47 | DURATION-4 | \`PLATFORM-4\` | [:package:\`App\`](https://example.org/StatusIm-123-456-abc-pr.AppImage) |
|
2022-11-23 15:10:43 +00:00
|
|
|
| :heavy_check_mark: | COMMIT-1 | [ID-5](URL-5/) | 2018-12-20 08:29:43 | DURATION-5 | \`PLATFORM-5\` | [:iphone:\`ipa\`](https://i.diawi.com/ABCDxyz1) [:calling:](https://chart.apis.google.com/chart?cht=qr&chs=400x400&chld=L%7C%0A1&chl=https%3A%2F%2Fi.diawi.com%2FABCDxyz1)|
|
2020-07-06 17:04:07 +00:00
|
|
|
| :heavy_multiplication_x: | COMMIT-1 | [ID-6](URL-6/) | 2018-12-20 08:30:40 | DURATION-6 | \`PLATFORM-6\` | [:package:\`pkg\`](https://unknown.example.org/path/package) |
|
|
|
|
| :interrobang: | COMMIT-1 | [ID-7](URL-7/) | 2018-12-20 08:31:37 | DURATION-7 | \`PLATFORM-7\` | [:page_facing_up:\`log\`](URL-7/consoleText) |
|
2019-01-15 21:56:56 +00:00
|
|
|
</details>
|
|
|
|
|
|
|
|
| :grey_question: | Commit | :hash: | Finished (UTC) | Duration | Platform | Result |
|
|
|
|
|-|-|-|-|-|-|-|
|
2021-08-16 17:29:57 +00:00
|
|
|
| :heavy_check_mark: | COMMIT-2 | [ID-8](URL-8/) | 2018-12-20 08:32:34 | DURATION-8 | \`PLATFORM-8\` | [:package:\`tgz\`](https://example.org/StatusIm-123-456-abc-pr.tar.gz) |
|
2022-11-23 15:10:43 +00:00
|
|
|
| :heavy_multiplication_x: | COMMIT-2 | [ID-9](URL-9/) | 2018-12-20 08:33:31 | DURATION-9 | \`PLATFORM-9\` | [:robot:\`apk\`](https://example.org/StatusIm-123-456-abc-pr.apk) [:calling:](https://chart.apis.google.com/chart?cht=qr&chs=400x400&chld=L%7C%0A1&chl=https%3A%2F%2Fexample.org%2FStatusIm-123-456-abc-pr.apk)|
|
|
|
|
| :heavy_check_mark: | COMMIT-2 | [ID-10](URL-10/) | 2018-12-20 08:34:27 | DURATION-10 | \`PLATFORM-10\` | [:cd:\`exe\`](https://example.org/StatusIm-123-456-abc-pr.exe) |
|
2021-08-16 17:29:57 +00:00
|
|
|
| :interrobang: | COMMIT-2 | [ID-11](URL-11/) | 2018-12-20 08:35:24 | DURATION-11 | \`PLATFORM-11\` | [:page_facing_up:\`log\`](URL-11/consoleText) |
|
2019-01-15 21:56:56 +00:00
|
|
|
| | | | | | | |
|
2021-08-16 17:29:57 +00:00
|
|
|
| :heavy_multiplication_x: | COMMIT-3 | [ID-12](URL-12/) | 2018-12-20 08:36:21 | DURATION-12 | \`PLATFORM-12\` | [:package:\`App\`](https://example.org/StatusIm-123-456-abc-pr.AppImage) |
|
2019-01-15 21:56:56 +00:00
|
|
|
`
|
|
|
|
|
2018-12-18 23:32:01 +00:00
|
|
|
describe('Comments', () => {
|
2018-12-18 23:43:16 +00:00
|
|
|
beforeEach(() => {
|
2018-12-20 15:10:01 +00:00
|
|
|
client = {
|
|
|
|
issues: {
|
|
|
|
createComment: sinon.stub().returns({ data: { id: 'ISSUE-ID' }}),
|
|
|
|
updateComment: sinon.stub().returns({ data: { id: 'ISSUE-ID' }}),
|
|
|
|
},
|
|
|
|
}
|
2018-12-18 23:32:01 +00:00
|
|
|
builds = sinon.createStubInstance(Builds, {
|
2019-01-15 21:56:56 +00:00
|
|
|
getBuilds: sample.BUILDS.slice(0, 2),
|
2018-12-18 23:32:01 +00:00
|
|
|
})
|
2019-02-06 21:50:48 +00:00
|
|
|
comments = new Comments({
|
|
|
|
client: client,
|
|
|
|
owner: 'owner',
|
|
|
|
repos: ['repo'],
|
|
|
|
builds: builds
|
|
|
|
})
|
2018-12-18 23:32:01 +00:00
|
|
|
})
|
|
|
|
|
2019-04-02 11:21:25 +00:00
|
|
|
describe('_renderComment', () => {
|
2018-12-18 23:32:01 +00:00
|
|
|
it('should fail with no builds', async () => {
|
2018-12-18 23:43:16 +00:00
|
|
|
builds.getBuilds.returns([])
|
2019-04-02 11:21:25 +00:00
|
|
|
expect(comments._renderComment('PR-ID')).rejectedWith('No builds exist for this PR')
|
2018-12-18 23:32:01 +00:00
|
|
|
})
|
2018-12-18 23:43:16 +00:00
|
|
|
|
2019-01-15 21:56:56 +00:00
|
|
|
it('should render less than 3 comments fully', async () => {
|
2019-04-02 11:21:25 +00:00
|
|
|
let body = await comments._renderComment('PR-ID')
|
2018-12-18 23:43:16 +00:00
|
|
|
expect(body).to.eq(COMMENT)
|
|
|
|
})
|
2019-01-15 21:56:56 +00:00
|
|
|
|
|
|
|
it('should render more than 3 comments folded', async () => {
|
|
|
|
builds.getBuilds.returns(sample.BUILDS)
|
2019-04-02 11:21:25 +00:00
|
|
|
let body = await comments._renderComment('PR-ID')
|
2019-01-15 21:56:56 +00:00
|
|
|
expect(body).to.eq(COMMENT_FOLDED)
|
|
|
|
})
|
2018-12-18 23:32:01 +00:00
|
|
|
})
|
2018-12-20 15:10:01 +00:00
|
|
|
|
2019-04-02 11:21:25 +00:00
|
|
|
describe('_postComment', () => {
|
2018-12-20 15:10:01 +00:00
|
|
|
it('should create a new comment', async () => {
|
2019-04-02 11:21:25 +00:00
|
|
|
let id = await comments._postComment({
|
2019-02-06 21:50:48 +00:00
|
|
|
repo: 'REPO-1', pr: 'PR-ID',
|
|
|
|
})
|
2018-12-20 15:10:01 +00:00
|
|
|
expect(id).to.eq('ISSUE-ID')
|
|
|
|
expect(client.issues.createComment).calledOnceWith({
|
|
|
|
body: sinon.match.any,
|
2018-12-20 17:19:41 +00:00
|
|
|
owner: 'owner',
|
2019-09-30 10:40:59 +00:00
|
|
|
issue_number: 'PR-ID',
|
2019-02-06 21:50:48 +00:00
|
|
|
repo: 'REPO-1',
|
2018-12-20 17:19:41 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-02 11:21:25 +00:00
|
|
|
describe('_updateComment', () => {
|
2018-12-20 17:19:41 +00:00
|
|
|
it('should update existing comment', async () => {
|
2019-04-02 11:21:25 +00:00
|
|
|
let id = await comments._updateComment({
|
2019-02-06 21:50:48 +00:00
|
|
|
repo: 'REPO-1', pr: 'PR-ID', comment_id: 'COMMENT-ID',
|
|
|
|
})
|
2018-12-20 17:19:41 +00:00
|
|
|
expect(id).to.eq('ISSUE-ID')
|
|
|
|
expect(client.issues.updateComment).calledOnceWith({
|
|
|
|
body: sinon.match.any,
|
2018-12-20 15:10:01 +00:00
|
|
|
owner: 'owner',
|
2019-02-06 21:50:48 +00:00
|
|
|
comment_id: 'COMMENT-ID',
|
|
|
|
repo: 'REPO-1',
|
2018-12-20 15:10:01 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-12-18 23:32:01 +00:00
|
|
|
})
|