Skip to content
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

TEST: Test/automated scenarios testing #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/test-rule-scenarios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test Rule Scenarios

on:
push:
branches: '*'
pull_request:
branches: '*'

jobs:
test-rule-scenarios:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: npm install

- name: Run Jest rule scenario tests
run: npm test src/testAllRules.spec.ts

- name: Run Jest rule Excel scenario tests
run: npm test src/testAllRulesExcel.spec.ts
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name: Test

on:
push:
branches:
- '*'
branches: '*'
pull_request:
branches:
- '*'
branches: '*'

jobs:
test:
Expand Down
128 changes: 124 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@gorules/zen-engine": "^0.21.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.0.0",
Expand All @@ -45,6 +46,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"node-xlsx": "^0.24.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
Expand Down
Binary file added src/InputOutputTest.xlsx
Binary file not shown.
24 changes: 24 additions & 0 deletions src/api/decisions/decisions.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, Get, Param, HttpException, HttpStatus } from '@nestjs/common';
import { DecisionsService } from './decisions.service';

@Controller('api/decisions')
export class DecisionsController {
constructor(private readonly decisionsService: DecisionsService) {}

@Get('/:ruleId')
async getSubmissions(@Param('ruleId') ruleId: string) {
try {
// TODO: Get inputs from request
return await this.decisionsService.runDecision({
numberOfChildren: 2,
familyComposition: 'single',
familyUnitInPayForDecember: true,
});
} catch (error) {
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@Get('/:formId/:id')
async getSubmissionById(@Param('formId') formId: string, @Param('id') id: string) {}
}
11 changes: 11 additions & 0 deletions src/api/decisions/decisions.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Injectable } from '@nestjs/common';
import { runDecision } from '../../services/gorules';

@Injectable()
export class DecisionsService {
constructor() {}

async runDecision(inputs: object) {
return runDecision('wintersupplement', inputs);
}
}
8 changes: 5 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { MongooseModule } from '@nestjs/mongoose';
import { RuleData, RuleDataSchema } from './api/ruleData/ruleData.schema';
import { RuleDataController } from './api/ruleData/ruleData.controller';
import { RuleDataService } from './api/ruleData/ruleData.service';
import { DecisionsController } from './api/decisions/decisions.controller';
import { DecisionsService } from './api/decisions/decisions.service';
import { SubmissionsController } from './api/submissions/submissions.controller';
import { SubmissionsService } from './api/submissions/submissions.service';

@Module({
imports: [
ConfigModule.forRoot(),
MongooseModule.forRoot(process.env.MONGODB_URL),
MongooseModule.forFeature([{ name: RuleData.name, schema: RuleDataSchema }]), // import model
MongooseModule.forFeature([{ name: RuleData.name, schema: RuleDataSchema }]),
],
controllers: [RuleDataController, SubmissionsController],
providers: [RuleDataService, SubmissionsService],
controllers: [RuleDataController, DecisionsController, SubmissionsController],
providers: [RuleDataService, DecisionsService, SubmissionsService],
})
export class AppModule {}
Loading
Loading