Skip to content

Commit

Permalink
test validator separately
Browse files Browse the repository at this point in the history
  • Loading branch information
cecric committed Oct 22, 2021
1 parent 3afb9b1 commit 7e854f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/application/tests/example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
import { ExampleTestUsecases } from '@core/example/usecases/example.test.usecases';
import { expect } from 'chai';

describe('test usecase -> test action', () => {
describe('test usecase -> test validator action', () => {
it('should return ok:true', async () => {
const result = await ExampleTestUsecases.testAction();
const result = await ExampleTestUsecases.testValidatorAction();
expect(result['ok']).to.be.true;
});
});
});

describe('test usecase -> test database repositories action', () => {
it('should return ok:true', async () => {
const result = await ExampleTestUsecases.testDatabaseRepositoriesAction();
expect(result['ok']).to.be.true;
});
});

22 changes: 18 additions & 4 deletions src/core/example/usecases/example.test.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,37 @@ import { Example } from '../models/example';
*/
export class ExampleTestUsecases extends UseCases {


/**
* Test action example to test some services
* @date 20/09/2021 - 08:00:00
* Test the validator service
* @date 22/10/2021 - 16:44:59
* @author cecric
*
* @public
* @static
* @async
* @returns {Promise<any>}
*/
public static async testAction (): Promise<any> {
public static async testValidatorAction (): Promise<any> {
const ex = new Example();
ex.setExample('[email protected]');
ex.setDateExample(new Date());
const validatorService: ValidatorService = await ServiceManager.get<ValidatorService>(ValidatorService.name);
await validatorService.validate<Example>('example', ex.toObject());
logger.log('test something');
return {'ok': true};
}

/**
* Test the orm services
* @date 20/09/2021 - 08:00:00
* @author cecric
*
* @public
* @static
* @async
* @returns {Promise<any>}
*/
public static async testDatabaseRepositoriesAction (): Promise<any> {
const repositoriesService: RepositoriesService = await ServiceManager.get<RepositoriesService>(RepositoriesService.name);
const repo = await repositoriesService.getRepositoryByName('example') as IExample;
const result = await repo.getExample();
Expand Down

0 comments on commit 7e854f3

Please sign in to comment.