-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
766d0d8
commit 41c4ee0
Showing
2 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export class Result { | ||
/** | ||
* For storing and sharing results. | ||
* | ||
* @param {string} repoOwner - The owner of the repository. | ||
* @param {string} repoName - The name of the repository. | ||
*/ | ||
constructor (repoOwner, repoName) { | ||
if (!repoOwner) { | ||
this.log('repoOwner must be provided', 'error') | ||
throw new Error('repoOwner must be provided') | ||
} | ||
if (!repoName) { | ||
this.log('repoName must be provided', 'error') | ||
throw new Error('repoName must be provided') | ||
} | ||
this.repoOwner = repoOwner | ||
this.repoName = repoName | ||
this.builtByGovernment = false | ||
this.isPrototype = false | ||
this.updatedAt = '' | ||
this.createdAt = '' | ||
this.directDependencies = [] | ||
this.indirectDependencies = [] | ||
this.errorsThrown = [] | ||
this.unknownLockFileType = false | ||
this.isValid = false | ||
|
||
// Non returned values | ||
this.latestCommitSHA = '' | ||
this.repoTree = [] | ||
} | ||
|
||
validate () { | ||
let valid = true | ||
|
||
if (this.directDependencies.length === 0 && this.indirectDependencies.length === 0 && !this.unknownLockFileType) { | ||
console.log('Result validation failed: No dependencies found, and no unknown lock file type') | ||
valid = false | ||
} | ||
|
||
if (this.errorsThrown.length > 0) { | ||
console.log('Result validation failed: Errors were thrown during analysis') | ||
valid = false | ||
} | ||
|
||
return valid | ||
} | ||
|
||
getResult () { | ||
return { | ||
repoOwner: this.repoOwner, | ||
repoName: this.repoName, | ||
builtByGovernment: this.builtByGovernment, | ||
updatedAt: this.updatedAt, | ||
createdAt: this.createdAt, | ||
directDependencies: this.directDependencies, | ||
isPrototype: this.isPrototype, | ||
isIndirect: this.directDependencies.length === 0, | ||
indirectDependencies: this.indirectDependencies, | ||
errorsThrown: this.errorsThrown, | ||
unknownLockFileType: this.unknownLockFileType, | ||
isValid: this.validate() | ||
} | ||
} | ||
} |
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,17 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { Result } from './result.mjs' | ||
|
||
describe('Result', () => { | ||
describe('validate', () => { | ||
it('should return false if no dependencies and no unknown lock file type', () => { | ||
const result = new Result('owner', 'repo') | ||
expect(result.validate()).toBe(false) | ||
}) | ||
|
||
it('should return false if errors were thrown during analysis', () => { | ||
const result = new Result('owner', 'repo') | ||
result.errorsThrown.push(new Error('Test error')) | ||
expect(result.validate()).toBe(false) | ||
}) | ||
}) | ||
}) |