Skip to content

Commit

Permalink
Add test for undefined array value in negative news flow (#137)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Nov 6, 2023
1 parent b8490dc commit 9c3cd78
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/services/negative-news/negative-news.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ export class NegativeNewsImpl implements NegativeNewsApi {
}

async validateUrls(data: SearchResult[]): Promise<{validUrls: ValidatedSearchResult[], badUrls: ValidatedSearchResult[]}> {
if (!data) {
const message: string = 'validateUrls() data value is undefined'
console.log(message)
throw new Error(message)
}

const validatedData: ValidatedSearchResult[] = await Promise.all(
data.map(this.validateUrl.bind(this))
)
Expand All @@ -568,6 +574,12 @@ export class NegativeNewsImpl implements NegativeNewsApi {

async checkAllNegativeNews(news: ValidatedSearchResult[], generate: GenerateFunction): Promise<{negativeNews: ScoredSearchResult[], positiveNews: ScoredSearchResult[]}> {

if (!news) {
const message: string = 'checkAllNegativeNews() news value is undefined'
console.log(message)
throw new Error(message)
}

const results: ScoredSearchResult[] = await Promise.all(news.map(val => this.checkNegativeNews(val, generate)))

return {
Expand Down Expand Up @@ -609,6 +621,12 @@ export class NegativeNewsImpl implements NegativeNewsApi {

async summarizeAllNews(news: ScoredSearchResult[], generate: GenerateFunction): Promise<SummarizedSearchResult[]> {

if (!news) {
const message: string = 'summarizeAllNews() news value is undefined'
console.log(message)
throw new Error(message)
}

return Promise.all(news.map(news => this.summarizeNews(news, generate)))
}

Expand All @@ -624,6 +642,12 @@ export class NegativeNewsImpl implements NegativeNewsApi {

async filterAllNews(negativeNews: SummarizedSearchResult[], subjectName: string, generate: GenerateFunction, filterParams?: {countryOfResidence?: string, dateOfBirth?: string}): Promise<{tp: FilteredSearchResult[], fp: FilteredSearchResult[]}> {

if (!negativeNews) {
const message: string = 'filterAllNews() negativeNews value is undefined'
console.log(message)
throw new Error(message)
}

const result = await Promise.all(
negativeNews.map(news => this.filterNews(news, subjectName, generate, filterParams))
)
Expand Down Expand Up @@ -727,6 +751,12 @@ export class NegativeNewsImpl implements NegativeNewsApi {
}

extractTopics(vals: FilteredSearchResult[]) {
if (!vals) {
const message: string = 'extractTopics() vals parameter is undefined'
console.log(message)
throw new Error(message)
}

return vals
.map(val => val.negativeNewsTopics)
.reduce((topics: string[], current: string[]) => {
Expand Down

0 comments on commit 9c3cd78

Please sign in to comment.