Skip to content

Commit 5f02b88

Browse files
authored
Merge pull request #228 from OpenPathfinder/ulises/2019-migration
2 parents 4bb7207 + 7e1ab5b commit 5f02b88

File tree

23 files changed

+950
-190
lines changed

23 files changed

+950
-190
lines changed

__fixtures__/index.js

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,121 @@ const sampleBulkImportFileContent = [{
920920
is_subscribed: true
921921
}]
922922

923+
// Sample project data for testing validateProjectData
924+
const sampleProjectData = {
925+
project: {
926+
id: 1,
927+
name: 'Test Project',
928+
description: 'A test project',
929+
created_at: '2023-01-01T00:00:00Z',
930+
updated_at: '2023-01-02T00:00:00Z'
931+
},
932+
checks: [
933+
{
934+
id: 1,
935+
checklist_id: 1,
936+
description: 'Test check',
937+
created_at: '2023-01-01T00:00:00Z',
938+
updated_at: '2023-01-02T00:00:00Z'
939+
}
940+
],
941+
results: [
942+
{
943+
id: 1,
944+
project_id: 1,
945+
name: 'Test result',
946+
score: 8.5,
947+
created_at: '2023-01-01T00:00:00Z',
948+
updated_at: '2023-01-02T00:00:00Z'
949+
}
950+
],
951+
tasks: [
952+
{
953+
id: 1,
954+
project_id: 1,
955+
description: 'Test task',
956+
implementation_status: 'pending',
957+
created_at: '2023-01-01T00:00:00Z',
958+
updated_at: '2023-01-02T00:00:00Z'
959+
}
960+
],
961+
alerts: [
962+
{
963+
id: 1,
964+
project_id: 1,
965+
title: 'Test alert',
966+
description: 'This is a test alert',
967+
severity: 'medium',
968+
created_at: '2023-01-01T00:00:00Z',
969+
updated_at: '2023-01-02T00:00:00Z'
970+
}
971+
],
972+
githubOrgs: [
973+
{
974+
id: 1,
975+
login: 'test-org',
976+
name: 'Test Organization',
977+
created_at: '2023-01-01T00:00:00Z',
978+
updated_at: '2023-01-02T00:00:00Z'
979+
}
980+
],
981+
githubRepos: [
982+
{
983+
id: 1,
984+
name: 'test-repo',
985+
full_name: 'test-org/test-repo',
986+
created_at: '2023-01-01T00:00:00Z',
987+
updated_at: '2023-01-02T00:00:00Z'
988+
}
989+
],
990+
ossfScorecardResults: [
991+
{
992+
id: 1,
993+
repository_id: 1,
994+
score: 8.5,
995+
created_at: '2023-01-01T00:00:00Z',
996+
updated_at: '2023-01-02T00:00:00Z'
997+
}
998+
]
999+
}
1000+
1001+
// Sample index data for testing validateIndexData
1002+
const sampleIndexData = {
1003+
projects: [
1004+
{
1005+
id: 1,
1006+
name: 'Test Project',
1007+
description: 'A test project',
1008+
created_at: '2023-01-01T00:00:00Z',
1009+
updated_at: '2023-01-02T00:00:00Z'
1010+
}
1011+
],
1012+
checklists: [
1013+
{
1014+
id: 1,
1015+
name: 'Test Checklist',
1016+
type: 'security',
1017+
created_at: '2023-01-01T00:00:00Z',
1018+
updated_at: '2023-01-02T00:00:00Z'
1019+
}
1020+
],
1021+
checks: [
1022+
{
1023+
id: 1,
1024+
checklist_id: 1,
1025+
description: 'Test check',
1026+
created_at: '2023-01-01T00:00:00Z',
1027+
updated_at: '2023-01-02T00:00:00Z'
1028+
}
1029+
]
1030+
}
1031+
9231032
module.exports = {
9241033
sampleGithubOrg,
9251034
sampleGithubListOrgRepos,
9261035
sampleGithubRepository,
9271036
sampleOSSFScorecardResult,
928-
sampleBulkImportFileContent
1037+
sampleBulkImportFileContent,
1038+
sampleProjectData,
1039+
sampleIndexData
9291040
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const request = require('supertest')
2-
const { generateStaticReports } = require('../src/reports')
3-
const serverModule = require('../src/httpServer')
2+
const { generateStaticReports } = require('../../src/reports')
3+
const serverModule = require('../../src/httpServer')
44
let server
55
let serverStop
66
let app
77

88
// Mocks
9-
jest.mock('../src/reports', () => ({
9+
jest.mock('../../src/reports', () => ({
1010
generateStaticReports: jest.fn()
1111
}))
1212

@@ -27,7 +27,7 @@ beforeEach(() => {
2727
jest.clearAllMocks()
2828
})
2929

30-
describe('HTTP Server API', () => {
30+
describe('HTTP Server API V1', () => {
3131
describe('GET /api/v1/__health', () => {
3232
test('should return status ok', async () => {
3333
const response = await app.get('/api/v1/__health')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const request = require('supertest')
2+
const knexInit = require('knex')
3+
const serverModule = require('../../src/httpServer')
4+
const { getConfig } = require('../../src/config')
5+
const { resetDatabase, initializeStore } = require('../../__utils__')
6+
7+
const { dbSettings } = getConfig('test')
8+
9+
let server
10+
let serverStop
11+
let app
12+
let knex
13+
let addProject
14+
let testProjectId
15+
16+
beforeAll(async () => {
17+
// Initialize database
18+
knex = knexInit(dbSettings);
19+
({ addProject } = initializeStore(knex))
20+
21+
// Reset database and add test project
22+
await resetDatabase(knex)
23+
const testProject = await addProject({ name: 'Test Project' })
24+
testProjectId = testProject.id
25+
26+
// Initialize server asynchronously
27+
const serverInstance = serverModule()
28+
server = await serverInstance.start()
29+
serverStop = serverInstance.stop
30+
app = request(server)
31+
})
32+
33+
afterAll(async () => {
34+
// Cleanup after all tests
35+
await serverStop?.()
36+
await resetDatabase(knex)
37+
await knex.destroy()
38+
})
39+
40+
describe('HTTP Server WEBSITE', () => {
41+
describe('GET /', () => {
42+
it('should render index page', async () => {
43+
const response = await app.get('/')
44+
expect(response.status).toBe(200)
45+
expect(response.header['content-type']).toMatch(/text\/html/)
46+
})
47+
})
48+
49+
describe('GET /projects/:id', () => {
50+
it('should render project page for valid project ID', async () => {
51+
const response = await app.get(`/projects/${testProjectId}`)
52+
expect(response.status).toBe(200)
53+
expect(response.header['content-type']).toMatch(/text\/html/)
54+
})
55+
56+
it('should render notFound page for invalid project ID format', async () => {
57+
const response = await app.get('/projects/invalid')
58+
expect(response.status).toBe(404)
59+
expect(response.header['content-type']).toMatch(/text\/html/)
60+
})
61+
62+
it('should render notFound page for non-existent project ID', async () => {
63+
const nonExistentId = 9999
64+
const response = await app.get(`/projects/${nonExistentId}`)
65+
expect(response.status).toBe(404)
66+
expect(response.header['content-type']).toMatch(/text\/html/)
67+
})
68+
})
69+
})

__tests__/reports.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { internalLinkBuilder } = require('../src/reports')
2+
3+
describe('internalLinkBuilder', () => {
4+
describe('static mode', () => {
5+
const staticLinkBuilder = internalLinkBuilder('static')
6+
7+
test('should handle empty reference', () => {
8+
expect(staticLinkBuilder('', null)).toBe('index.html')
9+
})
10+
11+
test('should remove leading slash in static mode', () => {
12+
expect(staticLinkBuilder('/assets/favicon.ico', null)).toBe('assets/favicon.ico')
13+
})
14+
15+
test('should handle project references in static mode', () => {
16+
const project = { name: 'testproject', id: 123 }
17+
expect(staticLinkBuilder('', project)).toBe('testproject.html')
18+
})
19+
20+
test('should prioritize project reference over path', () => {
21+
const project = { name: 'testproject', id: 123 }
22+
expect(staticLinkBuilder('/some/path', project)).toBe('testproject.html')
23+
})
24+
})
25+
26+
describe('server mode', () => {
27+
const serverLinkBuilder = internalLinkBuilder('server')
28+
29+
test('should handle empty reference', () => {
30+
expect(serverLinkBuilder('', null)).toBe('index.html')
31+
})
32+
33+
test('should preserve leading slash in server mode', () => {
34+
expect(serverLinkBuilder('/assets/favicon.ico', null)).toBe('/assets/favicon.ico')
35+
})
36+
37+
test('should handle project references in server mode', () => {
38+
const project = { name: 'testproject', id: 123 }
39+
expect(serverLinkBuilder('', project)).toBe('/projects/123')
40+
})
41+
42+
test('should prioritize project reference over path', () => {
43+
const project = { name: 'testproject', id: 123 }
44+
expect(serverLinkBuilder('/some/path', project)).toBe('/projects/123')
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)