-
Notifications
You must be signed in to change notification settings - Fork 0
Prod deployment of new security fixes and SFDC reports needed for Looker replacement #27
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a97c073
Expose parameters to API callers
jmgasper 5764b54
Initial SFDC syncing / finance requirements
jmgasper 285b1ab
Fix column name
jmgasper b7a4fff
Cast this to make it work
jmgasper 7f69b0d
Cast this parameter
jmgasper 2d5df3c
Update to use tc-core-library-js security branch and fix a bunch of l…
jmgasper 58cc830
Security fixes and tweak to parameter type
jmgasper 11250a3
Fix build issues
jmgasper 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ lerna-debug.log* | |
| # Tests | ||
| /coverage | ||
| /.nyc_output | ||
| junit.xml | ||
|
|
||
| # IDEs and editors | ||
| /.idea | ||
|
|
||
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,87 @@ | ||
| # Testing Guide | ||
|
|
||
| ## Overview | ||
| Jest with `@nestjs/testing` is used for unit and lightweight integration tests. Tests focus on isolating controllers, services, DTO validation, and module wiring without hitting external systems such as databases or the filesystem. | ||
|
|
||
| ## Running Tests | ||
| - `pnpm test` — run all specs once | ||
| - `pnpm test:watch` — watch mode during development | ||
| - `pnpm test:cov` — generate coverage report | ||
| - `pnpm test:debug` — start Jest in debug/inspect mode | ||
|
|
||
| ## Test Structure | ||
| - Tests live alongside source files and are named `*.spec.ts`. | ||
| - Use `describe` blocks per class or function and keep expectations close to the behavior under test. | ||
| - Mock framework dependencies (e.g., `DbService`, `SqlLoaderService`) to avoid side effects. | ||
|
|
||
| ## Writing Tests for SFDC Endpoints | ||
| - **Controllers:** mock services, assert route handlers pass through parameters and propagate errors. | ||
| - **Services:** mock `DbService` and `SqlLoaderService`; verify parameter ordering and validation paths. | ||
| - **DTOs:** leverage `class-validator` with `validate()` to assert decorator behavior and data transforms. | ||
| - **Modules:** use `Test.createTestingModule` to ensure providers/controllers are registered and injectable. | ||
|
|
||
| ## Mock Data | ||
| Reusable fixtures live under `src/reports/sfdc/test-helpers`. Share mock responses and query DTOs across controller, service, and DTO specs to keep assertions consistent. | ||
|
|
||
| ## Best Practices | ||
| - Reset mocks in `beforeEach` to avoid cross-test leakage. | ||
| - Cover happy paths and error cases, especially validation failures. | ||
| - Prefer deterministic data; avoid randomness and timers. | ||
| - Keep assertions focused—each test should validate one behavior. | ||
|
|
||
| ## Example Patterns | ||
| ```ts | ||
| const mockDb = { query: jest.fn() }; | ||
| const moduleRef = await Test.createTestingModule({ | ||
| providers: [{ provide: DbService, useValue: mockDb }, SfdcReportsService], | ||
| }).compile(); | ||
| ``` | ||
|
|
||
| ```ts | ||
| const dto = plainToInstance(ChallengesReportQueryDto, input); | ||
| const errors = await validate(dto); | ||
| expect(errors).toHaveLength(0); | ||
| ``` | ||
|
|
||
| ## CI/CD Integration | ||
| - Ensure `pnpm test` and `pnpm test:cov` run cleanly in CI; failing tests should block deployments. | ||
| - Coverage output is written to `coverage/` and should be ignored from commits by default. | ||
|
|
||
| ## Coverage for SFDC Endpoints | ||
|
|
||
| All SFDC report endpoints (`/challenges`, `/payments`, `/taas/*`, `/ba-fees`) should have: | ||
| - **Controller tests**: Route handling, parameter transforms, error propagation | ||
| - **Service tests**: SQL loading, parameter ordering (verify all query params), filter logic (include/exclude via `multiValueArrayFilter`), empty results, error handling | ||
| - **DTO tests**: All validators (`@IsString`, `@IsDateString`, `@IsNumber`, etc.), transforms (`transformArray`, `transformToNumber`), optional fields, invalid input rejection | ||
|
|
||
| Example service test for parameter ordering: | ||
| ```ts | ||
| it('passes all filters in correct order', async () => { | ||
| await service.getPaymentsReport({ | ||
| billingAccountIds: ['12345'], | ||
| challengeIds: ['uuid1'], | ||
| handles: ['user1'], | ||
| challengeName: 'Task', | ||
| startDate: '2023-01-01', | ||
| endDate: '2023-12-31', | ||
| minPaymentAmount: 100, | ||
| maxPaymentAmount: 1000, | ||
| challengeStatus: ['COMPLETED'] | ||
| }); | ||
|
|
||
| expect(mockDbService.query).toHaveBeenCalledWith(mockSql, [ | ||
| ['12345'], // include billing accounts | ||
| undefined, // exclude billing accounts | ||
| ['uuid1'], // challenge IDs | ||
| ['user1'], // handles | ||
| 'Task', // challenge name | ||
| '2023-01-01', // start date | ||
| '2023-12-31', // end date | ||
| 100, // min amount | ||
| 1000, // max amount | ||
| ['COMPLETED'] // challenge status | ||
| ]); | ||
| }); | ||
| ``` | ||
|
|
||
| Refer to `sfdc-reports.controller.spec.ts`, `sfdc-reports.service.spec.ts`, and `sfdc-reports.dto.spec.ts` for complete patterns. |
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,20 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| rootDir: 'src', | ||
| testRegex: '.*\\.spec\\.ts$', | ||
| moduleFileExtensions: ['js', 'json', 'ts'], | ||
| transform: { | ||
| '^.+\\.(t|j)s$': 'ts-jest', | ||
| }, | ||
| moduleNameMapper: { | ||
| '^src/(.*)$': '<rootDir>/$1', | ||
| }, | ||
| collectCoverageFrom: [ | ||
| '**/*.{service,controller,dto}.ts', | ||
| '!**/*.spec.ts', | ||
| '!**/interfaces/**', | ||
| '!**/node_modules/**', | ||
| ], | ||
| coverageDirectory: '../coverage', | ||
| }; | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
maintainability]Consider adding more specific patterns to
collectCoverageFromto ensure that only the intended files are included in the coverage report. This can help avoid unintentional inclusion of files that match the current pattern but are not meant to be covered.