Skip to content

Commit

Permalink
SCP-66 Adds test suite for report service
Browse files Browse the repository at this point in the history
  • Loading branch information
francostramana committed Jan 24, 2024
1 parent d4b22d3 commit b071d74
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 75 deletions.
26 changes: 2 additions & 24 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,8 @@ describe('action', () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return '500';
default:
case 'scanner-parameters':
return '';
}
});

await main.run();
expect(runMock).toHaveReturned();

// Verify that all of the core library functions were called correctly
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...');
expect(debugMock).toHaveBeenNthCalledWith(2, expect.stringMatching(timeRegex));
expect(debugMock).toHaveBeenNthCalledWith(3, expect.stringMatching(timeRegex));
expect(setOutputMock).toHaveBeenNthCalledWith(1, 'time', expect.stringMatching(timeRegex));
expect(errorMock).not.toHaveBeenCalled();
});

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
switch (name) {
case 'milliseconds':
return 'this is not a number';
default:
return '';
}
Expand All @@ -70,7 +48,7 @@ describe('action', () => {
expect(runMock).toHaveReturned();

// Verify that all of the core library functions were called correctly
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'milliseconds not a number');
expect(debugMock).toHaveBeenNthCalledWith(1, 'SCANOSS Scan Action started...');
expect(errorMock).not.toHaveBeenCalled();
});
});
41 changes: 41 additions & 0 deletions __tests__/report-service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getLicensesReport } from '../src/services/report.service';
import { ScannerResults } from '../src/services/result.interfaces';

Check warning on line 2 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'ScannerResults' is defined but never used

Check warning on line 2 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'ScannerResults' is defined but never used
import { getLicenses, Licenses } from '../src/services/result.service';

Check warning on line 3 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'getLicenses' is defined but never used

Check warning on line 3 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'Licenses' is defined but never used

Check warning on line 3 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'getLicenses' is defined but never used

Check warning on line 3 in __tests__/report-service.test.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'Licenses' is defined but never used

const licenseTableTest = [
{
name: '1) report test',
licenses: [{ spdxid: 'MIT', url: null, copyleft: null }],
output: '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | :x: | |\n'
},
{
name: '2) report test',
licenses: [
{ spdxid: 'MIT', url: null, copyleft: null },
{ spdxid: 'Apache-2.0', url: null, copyleft: null },
{ spdxid: '0BSD', url: null, copyleft: null }
],
output:
'| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | :x: | |\n| Apache-2.0 | :x: | |\n| 0BSD | :x: | |\n'
},
{
name: '3) report test',
licenses: [
{ spdxid: 'GPL-2.0-only', url: 'https://spdx.org/licenses/GPL-2.0-only.html', copyleft: true },
{ spdxid: 'GPL-2.0-or-later', url: 'https://spdx.org/licenses/GPL-2.0-or-later.html', copyleft: true },
{ spdxid: 'JSON', url: 'https://spdx.org/licenses/JSON.html', copyleft: null },
{ spdxid: 'LicenseRef-scancode-unknown-license-reference', url: null, copyleft: null }
],
output:
'| License | Copyleft | URL |\n| ------- | -------- | --- |\n| GPL-2.0-only | :heavy_check_mark: | https://spdx.org/licenses/GPL-2.0-only.html |\n| GPL-2.0-or-later | :heavy_check_mark: | https://spdx.org/licenses/GPL-2.0-or-later.html |\n| JSON | :x: | https://spdx.org/licenses/JSON.html |\n| LicenseRef-scancode-unknown-license-reference | :x: | |\n'
}
];

describe('Test report service', () => {
for (const t of licenseTableTest) {
it(`${t.name}`, () => {
const report = getLicensesReport(t.licenses);
expect(report).toEqual(t.output);
});
}
});
51 changes: 0 additions & 51 deletions __tests__/report.service.test.ts

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import { getLicensesReport } from './services/report.service';
*/
export async function run(): Promise<void> {
try {
core.debug(`SCANOSS Scan Action started...`);

const repoDir = process.env.GITHUB_WORKSPACE as string;
const outputPath = 'results.json';

// create policies
core.debug(`Creating policies`);
const policies = [new LicensePolicyCheck()];
policies.forEach(async policy => policy.start());

Expand Down

0 comments on commit b071d74

Please sign in to comment.