Skip to content

Commit 63b0e02

Browse files
committed
refactor: restructure staticCodeAnalysis test data and improve repository data handling
1 parent eae37a1 commit 63b0e02

File tree

2 files changed

+34
-42
lines changed

2 files changed

+34
-42
lines changed

__tests__/checks/validators/staticCodeAnalysis.test.js

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ describe('staticCodeAnalysis', () => {
1212
{
1313
id: 1,
1414
name: 'test',
15-
full_name: 'org1/test'
15+
full_name: 'org1/test',
16+
ossf_results: {
17+
sast_score: 10
18+
}
1619
},
1720
{
1821
id: 2,
1922
name: 'discussions',
20-
full_name: 'org1/discussions'
21-
}
22-
],
23-
ossf_results: [
24-
{
25-
sast_score: 10,
26-
github_repository_id: 1
27-
},
28-
{
29-
sast_score: 10,
30-
github_repository_id: 2
23+
full_name: 'org1/discussions',
24+
ossf_results: {
25+
sast_score: 10
26+
}
3127
}
3228
]
3329
}, {
@@ -38,13 +34,10 @@ describe('staticCodeAnalysis', () => {
3834
{
3935
id: 3,
4036
name: '.github',
41-
full_name: 'org2/.github'
42-
}
43-
],
44-
ossf_results: [
45-
{
46-
sast_score: 10,
47-
github_repository_id: 3
37+
full_name: 'org2/.github',
38+
ossf_results: {
39+
sast_score: 10
40+
}
4841
}
4942
]
5043
}, {
@@ -55,13 +48,10 @@ describe('staticCodeAnalysis', () => {
5548
{
5649
id: 4,
5750
name: 'support',
58-
full_name: 'org3/support'
59-
}
60-
],
61-
ossf_results: [
62-
{
63-
sast_score: 10,
64-
github_repository_id: 4
51+
full_name: 'org3/support',
52+
ossf_results: {
53+
sast_score: 10
54+
}
6555
}
6656
]
6757
}]
@@ -110,9 +100,9 @@ describe('staticCodeAnalysis', () => {
110100
it.todo('Should generate a pass result if not have public repositories in all the organizations')
111101

112102
it('Should generate a failed result if some repositories have low static code analysis score', () => {
113-
data[0].ossf_results[0].sast_score = 0
114-
data[0].ossf_results[1].sast_score = null
115-
data[1].ossf_results[0].sast_score = 0
103+
data[0].repositories[0].ossf_results.sast_score = 0
104+
data[0].repositories[1].ossf_results.sast_score = null
105+
data[1].repositories[0].ossf_results.sast_score = 0
116106

117107
const analysis = staticCodeAnalysis({ data, check, projects })
118108
expect(analysis).toEqual({
@@ -154,8 +144,10 @@ describe('staticCodeAnalysis', () => {
154144
})
155145

156146
it('Should generate an unknown result if not have ossf results', () => {
157-
data[0].ossf_results = []
158-
data[1].ossf_results = []
147+
data[0].repositories[0].ossf_results = null
148+
data[0].repositories[1].ossf_results = null
149+
data[1].repositories[0].ossf_results = null
150+
data[2].repositories[0].ossf_results = null
159151

160152
const analysis = staticCodeAnalysis({ data, check, projects })
161153
expect(analysis).toEqual({
@@ -179,13 +171,9 @@ describe('staticCodeAnalysis', () => {
179171
tasks: []
180172
})
181173
})
174+
182175
it('Should generate an unknown result if some have repositories have unkown ossf results but other repositories have a high static code analysis score', () => {
183-
data[0].ossf_results = [
184-
{
185-
sast_score: 10,
186-
github_repository_id: 1
187-
}
188-
]
176+
data[0].repositories[1].ossf_results = undefined
189177

190178
const analysis = staticCodeAnalysis({ data, check, projects })
191179
expect(analysis).toEqual({
@@ -210,7 +198,7 @@ describe('staticCodeAnalysis', () => {
210198
})
211199
})
212200
it('Should generate an unknown result if some repositories have unknown static code analysis', () => {
213-
data[2].ossf_results[0].sast_score = null
201+
data[2].repositories[0].ossf_results.sast_score = null
214202

215203
const analysis = staticCodeAnalysis({ data, check, projects })
216204
expect(analysis).toEqual({

src/store/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,23 @@ const getAllOSSFResultsOfRepositoriesByProjectId = async (knex, projectIds) => {
228228
organizationsMap.set(orgId, orgData)
229229
}
230230

231+
let repoData = {}
231232
// Add repository if it exists
232233
if (row.repo_id) {
233-
const repoData = simplifyObject(row, {
234+
repoData = simplifyObject(row, {
234235
exclude: ['repo_id', 'org_id', 'ossf_id']
235236
})
236-
organizationsMap.get(orgId).repositories.push(repoData)
237237
}
238238

239-
if (row.ossf_id) {
239+
if (row.ossf_id && row.repo_id) {
240240
const ossfData = simplifyObject(row, {
241241
exclude: ['ossf_id', 'repo_id', 'org_id']
242242
})
243-
organizationsMap.get(orgId).ossf_results.push(ossfData)
243+
repoData.ossf_results = ossfData
244+
}
245+
246+
if (row.repo_id) {
247+
organizationsMap.get(orgId).repositories.push(repoData)
244248
}
245249
})
246250

0 commit comments

Comments
 (0)