-
-
Notifications
You must be signed in to change notification settings - Fork 3
Dynamic reports #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dynamic reports #228
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9f279a0
chore: relocate API V1 router file
UlisesGascon 7008b3a
feat: use the reports assets folder as static folder for the server
UlisesGascon e026c76
chore: rename template files
UlisesGascon c98fd48
feat: add link constructor for templates, static flat structure and logo
UlisesGascon 3dcc169
feat: add a "Not Found" template
UlisesGascon 60f2344
feat: add `getOne` function to store
UlisesGascon 2952af2
feat: add separated data collection functions for reporting
UlisesGascon 7aa2727
feat: add website routes
UlisesGascon 296c477
feat: use partial with the EJS templates
UlisesGascon 90c5212
chore: improve server life cycle handler
UlisesGascon 42f7cf3
test: relocate API v1 tests
UlisesGascon 7298c44
test: add tests for `GET /` and `GET /projects/:id`
UlisesGascon bef986b
feat: add JSON Schema validation for statics and server templates
UlisesGascon 7e1ab5b
chore: refactor and enhancements
UlisesGascon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,69 @@ | ||
| const request = require('supertest') | ||
| const knexInit = require('knex') | ||
| const serverModule = require('../../src/httpServer') | ||
| const { getConfig } = require('../../src/config') | ||
| const { resetDatabase, initializeStore } = require('../../__utils__') | ||
|
|
||
| const { dbSettings } = getConfig('test') | ||
|
|
||
| let server | ||
| let serverStop | ||
| let app | ||
| let knex | ||
| let addProject | ||
| let testProjectId | ||
|
|
||
| beforeAll(async () => { | ||
| // Initialize database | ||
| knex = knexInit(dbSettings); | ||
| ({ addProject } = initializeStore(knex)) | ||
|
|
||
| // Reset database and add test project | ||
| await resetDatabase(knex) | ||
| const testProject = await addProject({ name: 'Test Project' }) | ||
| testProjectId = testProject.id | ||
|
|
||
| // Initialize server asynchronously | ||
| const serverInstance = serverModule() | ||
| server = await serverInstance.start() | ||
| serverStop = serverInstance.stop | ||
| app = request(server) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| // Cleanup after all tests | ||
| await serverStop?.() | ||
| await resetDatabase(knex) | ||
| await knex.destroy() | ||
| }) | ||
|
|
||
| describe('HTTP Server WEBSITE', () => { | ||
| describe('GET /', () => { | ||
| it('should render index page', async () => { | ||
| const response = await app.get('/') | ||
| expect(response.status).toBe(200) | ||
| expect(response.header['content-type']).toMatch(/text\/html/) | ||
| }) | ||
| }) | ||
|
|
||
| describe('GET /projects/:id', () => { | ||
| it('should render project page for valid project ID', async () => { | ||
| const response = await app.get(`/projects/${testProjectId}`) | ||
| expect(response.status).toBe(200) | ||
| expect(response.header['content-type']).toMatch(/text\/html/) | ||
| }) | ||
|
|
||
| it('should render notFound page for invalid project ID format', async () => { | ||
| const response = await app.get('/projects/invalid') | ||
| expect(response.status).toBe(404) | ||
| expect(response.header['content-type']).toMatch(/text\/html/) | ||
| }) | ||
|
|
||
| it('should render notFound page for non-existent project ID', async () => { | ||
| const nonExistentId = 9999 | ||
| const response = await app.get(`/projects/${nonExistentId}`) | ||
| expect(response.status).toBe(404) | ||
| expect(response.header['content-type']).toMatch(/text\/html/) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or 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,47 @@ | ||
| const { internalLinkBuilder } = require('../src/reports') | ||
|
|
||
| describe('internalLinkBuilder', () => { | ||
| describe('static mode', () => { | ||
| const staticLinkBuilder = internalLinkBuilder('static') | ||
|
|
||
| test('should handle empty reference', () => { | ||
| expect(staticLinkBuilder('', null)).toBe('index.html') | ||
| }) | ||
|
|
||
| test('should remove leading slash in static mode', () => { | ||
| expect(staticLinkBuilder('/assets/favicon.ico', null)).toBe('assets/favicon.ico') | ||
| }) | ||
|
|
||
| test('should handle project references in static mode', () => { | ||
| const project = { name: 'testproject', id: 123 } | ||
| expect(staticLinkBuilder('', project)).toBe('testproject.html') | ||
| }) | ||
|
|
||
| test('should prioritize project reference over path', () => { | ||
| const project = { name: 'testproject', id: 123 } | ||
| expect(staticLinkBuilder('/some/path', project)).toBe('testproject.html') | ||
| }) | ||
| }) | ||
|
|
||
| describe('server mode', () => { | ||
| const serverLinkBuilder = internalLinkBuilder('server') | ||
|
|
||
| test('should handle empty reference', () => { | ||
| expect(serverLinkBuilder('', null)).toBe('index.html') | ||
| }) | ||
|
|
||
| test('should preserve leading slash in server mode', () => { | ||
| expect(serverLinkBuilder('/assets/favicon.ico', null)).toBe('/assets/favicon.ico') | ||
| }) | ||
|
|
||
| test('should handle project references in server mode', () => { | ||
| const project = { name: 'testproject', id: 123 } | ||
| expect(serverLinkBuilder('', project)).toBe('/projects/123') | ||
| }) | ||
|
|
||
| test('should prioritize project reference over path', () => { | ||
| const project = { name: 'testproject', id: 123 } | ||
| expect(serverLinkBuilder('/some/path', project)).toBe('/projects/123') | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.