Skip to content

Commit

Permalink
feat(bpmn-service): add unit and acceptance tests (#289)
Browse files Browse the repository at this point in the history
GH-0
  • Loading branch information
akshatdubeysf authored Sep 21, 2021
1 parent 444ed5d commit 320e513
Show file tree
Hide file tree
Showing 19 changed files with 818 additions and 28 deletions.
1 change: 1 addition & 0 deletions services/bpmn-service/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
dist/
coverage/
migrations/
.nyc_output

.eslintrc.js
migration.js
7 changes: 7 additions & 0 deletions services/bpmn-service/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"include": ["dist"],
"exclude": ["dist/__tests__/"],
"extension": [".js", ".ts"],
"reporter": ["text", "html"],
"exclude-after-remap": false
}
1 change: 1 addition & 0 deletions services/bpmn-service/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
*.json
coverage
9 changes: 9 additions & 0 deletions services/bpmn-service/package-lock.json

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

8 changes: 6 additions & 2 deletions services/bpmn-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"openapi-spec": "node ./dist/openapi-spec",
"apidocs": "./node_modules/.bin/widdershins --search false --language_tabs 'javascript:JavaScript:request' 'javascript--nodejs:Node.JS' --summary openapi.json -o openapi.md",
"pretest": "npm run clean && npm run build",
"test": "echo \"No tests !\"",
"test": "lb-mocha --allow-console-logs \"dist/__tests__\"",
"coverage": "lb-nyc npm run test",
"coverage:ci": "lb-nyc report --reporter=text-lcov | coveralls",
"posttest": "npm run lint",
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
"clean": "lb-clean dist *.tsbuildinfo .eslintcache",
Expand Down Expand Up @@ -62,6 +64,7 @@
"camunda-external-task-client-js": "^2.1.0",
"dotenv": "^8.2.0",
"dotenv-extended": "^2.9.0",
"jsonwebtoken": "^8.5.1",
"loopback-connector-postgresql": "^5.3.0",
"loopback4-authentication": "^4.6.0",
"loopback4-authorization": "^3.2.0",
Expand All @@ -76,6 +79,7 @@
"@types/camunda-external-task-client-js": "^1.3.1",
"@types/lodash": "^4.14.169",
"@types/node": "^10.17.60",
"@types/jsonwebtoken": "^8.5.4",
"db-migrate": "^0.11.12",
"db-migrate-pg": "^1.2.2",
"eslint": "^7.25.0",
Expand All @@ -87,4 +91,4 @@
"registry": "https://registry.npmjs.org/",
"access": "public"
}
}
}
69 changes: 69 additions & 0 deletions services/bpmn-service/src/__tests__/acceptance/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
Client,
createRestAppClient,
givenHttpServerConfig,
} from '@loopback/testlab';
import {BearerTokenVerifyProvider} from '../provider/bearer-token-verify.provider';
import {Strategies} from 'loopback4-authentication';
import {WorkflowServiceApplication} from '../../application';
import {BPMTask, WorkflowCacheSourceName} from '../../types';
import {WorkflowDbDatasource} from '../datasources/workflowdb.datasource';
import {WorkflowServiceBindings} from '../../keys';
import {WorkflowMockProvider} from '../provider/workflow-helper-mock.provider';
import {firstTestBpmn, MOCK_CAMUNDA} from '../const';
import {MOCK_BPMN_ENGINE_KEY} from '../types';
import {MockEngine} from '../mock-engine';
import {BindingScope} from '@loopback/context';
import {WorkerMockImplementationProvider} from '../provider/workflow-mock-implementation.provider';
import {TestBpmnCommand} from '../commands/test.command';

export async function setUpApplication(): Promise<AppWithClient> {
const app = new WorkflowServiceApplication({
rest: givenHttpServerConfig(),
});

app.dataSource(WorkflowDbDatasource);
app.bind(`datasources.config.${WorkflowCacheSourceName}`).to({
name: 'pgdb',
connector: 'memory',
});
app
.bind(Strategies.Passport.BEARER_TOKEN_VERIFIER)
.toProvider(BearerTokenVerifyProvider);
app
.bind(WorkflowServiceBindings.WorkflowManager)
.toProvider(WorkflowMockProvider);
app
.bind(WorkflowServiceBindings.WorkerImplementationFunction)
.toProvider(WorkerMockImplementationProvider);
app.bind(WorkflowServiceBindings.Config).to({
workflowEngineBaseUrl: MOCK_CAMUNDA,
useCustomSequence: false,
});
app
.bind(MOCK_BPMN_ENGINE_KEY)
.toClass(MockEngine)
.inScope(BindingScope.SINGLETON);
const registerFn = await app.getValueOrPromise(
WorkflowServiceBindings.RegisterWorkerFunction,
);
if (registerFn) {
const cmd = new TestBpmnCommand();
await registerFn(firstTestBpmn.name, 'topic1', new BPMTask(cmd));
await registerFn(firstTestBpmn.name, 'topic2', new BPMTask(cmd));
} else {
throw new Error('No worker register function in the context');
}
await app.boot();

await app.start();

const client = createRestAppClient(app);

return {app, client};
}

export interface AppWithClient {
app: WorkflowServiceApplication;
client: Client;
}
Loading

0 comments on commit 320e513

Please sign in to comment.