Skip to content

Commit

Permalink
test: added unit test for generateReportContent utility
Browse files Browse the repository at this point in the history
- Relates #10
  • Loading branch information
KoolTheba committed Feb 24, 2023
1 parent ef54276 commit 611de75
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
15 changes: 14 additions & 1 deletion __fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ const scope = {
}
}

const scores = [
{
org: 'fake-org',
repo: 'fake-repo',
platform: 'github.com',
commit: '846b3ddb5f75d95235e94d9eb52e920f4a067338',
score: 10,
date: '2023-02-20',
currentDiff: 5
}
]

module.exports = {
database,
scope
scope,
scores
}
31 changes: 31 additions & 0 deletions __tests__/__snapshots__/utils.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Utils generateReportContent Should render template with scores and title 1`] = `
"# OpenSSF Scorecard Report
## Summary
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
| [fake-org/fake-repo](https://github.com/fake-org/fake-repo) | [846b3dd](https://github.com/fake-org/fake-repo/commit/846b3ddb5f75d95235e94d9eb52e920f4a067338) | 10 | 2023-02-20 | 5 | [Full Report](https://deps.dev/project/github/fake-org%2Ffake-repo) |
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;

exports[`Utils generateReportContent Should render template with scores only 1`] = `
"
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
| [fake-org/fake-repo](https://github.com/fake-org/fake-repo) | [846b3dd](https://github.com/fake-org/fake-repo/commit/846b3ddb5f75d95235e94d9eb52e920f4a067338) | 10 | 2023-02-20 | 5 | [Full Report](https://deps.dev/project/github/fake-org%2Ffake-repo) |
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;

exports[`Utils generateReportContent Should render template with title only 1`] = `
"# OpenSSF Scorecard Report
## Summary
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;
23 changes: 21 additions & 2 deletions __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { validateDatabaseIntegrity, validateScopeIntegrity } = require('../src/utils')
const { database, scope } = require('../__fixtures__')
const { validateDatabaseIntegrity, validateScopeIntegrity, generateReportContent } = require('../src/utils')
const { database, scope, scores } = require('../__fixtures__')

describe('Utils', () => {
describe('validateDatabaseIntegrity', () => {
Expand All @@ -19,4 +19,23 @@ describe('Utils', () => {
expect(() => validateScopeIntegrity(scope.emptyScope)).not.toThrow()
})
})

describe('generateReportContent', () => {
it('Should render template with scores and title', async () => {
const reportTagsEnabled = false
const report = await generateReportContent(scores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
it('Should render template with scores only', async () => {
const reportTagsEnabled = true
const report = await generateReportContent(scores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
it('Should render template with title only', async () => {
const emptyScores = []
const reportTagsEnabled = false
const report = await generateReportContent(emptyScores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
})
})

0 comments on commit 611de75

Please sign in to comment.