add test for formatting of comments
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
27da010e8a
commit
203d5f2072
|
@ -7,22 +7,59 @@ import Comments from '../src/comments'
|
||||||
|
|
||||||
let comments, client, builds
|
let comments, client, builds
|
||||||
|
|
||||||
|
const BUILDS = [
|
||||||
|
{
|
||||||
|
id: 'ID-1',
|
||||||
|
commit: 'COMMIT-1',
|
||||||
|
success: true,
|
||||||
|
platform: 'PLATFORM-1',
|
||||||
|
duration: 'DURATION-1',
|
||||||
|
url: 'URL-1',
|
||||||
|
pkg_url: 'PKG_URL-1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'ID-2',
|
||||||
|
commit: 'COMMIT-2',
|
||||||
|
success: false,
|
||||||
|
platform: 'PLATFORM-2',
|
||||||
|
duration: 'DURATION-2',
|
||||||
|
url: 'URL-2',
|
||||||
|
pkg_url: 'PKG_URL-2',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
/* expected comment based on given builds */
|
||||||
|
const COMMENT = `
|
||||||
|
### Jenkins Builds
|
||||||
|
| :grey_question: | Commit | :hash: | Finished | Duration | Platform | Result |
|
||||||
|
|-|-|-|-|-|-|-|
|
||||||
|
| :heavy_check_mark: | COMMIT-1 | [ID-1](URL-1) | Invalid Date | DURATION-1 | \`PLATFORM-1\` | [:package: package](PKG_URL-1) |
|
||||||
|
| | | | | | | |
|
||||||
|
| :x: | COMMIT-2 | [ID-2](URL-2) | Invalid Date | DURATION-2 | \`PLATFORM-2\` | [:page_facing_up: build log](PKG_URL-2consoleText) |
|
||||||
|
`
|
||||||
|
|
||||||
describe('Comments', () => {
|
describe('Comments', () => {
|
||||||
before(() => {
|
beforeEach(() => {
|
||||||
//client = sinon.createStubInstance(Octokit, {what: 2})
|
//client = sinon.createStubInstance(Octokit, {what: 2})
|
||||||
builds = sinon.createStubInstance(Builds, {
|
builds = sinon.createStubInstance(Builds, {
|
||||||
getBuilds: []
|
getBuilds: BUILDS,
|
||||||
})
|
})
|
||||||
comments = new Comments(client, 'owner', 'repo', builds)
|
comments = new Comments(client, 'owner', 'repo', builds)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('renderComment', () => {
|
describe('renderComment', () => {
|
||||||
it('should fail with no builds', async () => {
|
it('should fail with no builds', async () => {
|
||||||
|
builds.getBuilds.returns([])
|
||||||
try {
|
try {
|
||||||
await comments.renderComment('PR')
|
await comments.renderComment('PR')
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
expect(err.message).to.eq('No builds exist for this PR')
|
expect(err.message).to.eq('No builds exist for this PR')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should render correctly', async () => {
|
||||||
|
let body = await comments.renderComment('PR')
|
||||||
|
expect(body).to.eq(COMMENT)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue