-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EW-561 code coverage, better searching and pagination
- Loading branch information
Showing
14 changed files
with
248 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
61 changes: 61 additions & 0 deletions
61
src/modules/person/persistence/person.scope.integration-spec.ts
This file contains 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,61 @@ | ||
import { Mapper } from '@automapper/core'; | ||
import { getMapperToken } from '@automapper/nestjs'; | ||
import { MikroORM } from '@mikro-orm/core'; | ||
import { EntityManager } from '@mikro-orm/postgresql'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ConfigTestModule, DatabaseTestModule, DoFactory, MapperTestModule } from '../../../../test/utils/index.js'; | ||
import { PersonDo } from '../domain/person.do.js'; | ||
import { PersonPersistenceMapperProfile } from './person-persistence.mapper.profile.js'; | ||
import { PersonEntity } from './person.entity.js'; | ||
import { PersonScope } from './person.scope.js'; | ||
import { ScopeOrder } from '../../../shared/persistence/scope.enums.js'; | ||
|
||
describe('PersonScope', () => { | ||
let module: TestingModule; | ||
let orm: MikroORM; | ||
let em: EntityManager; | ||
let mapper: Mapper; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [ConfigTestModule, DatabaseTestModule.forRoot({ isDatabaseRequired: true }), MapperTestModule], | ||
providers: [PersonPersistenceMapperProfile], | ||
}).compile(); | ||
orm = module.get(MikroORM); | ||
em = module.get(EntityManager); | ||
mapper = module.get(getMapperToken()); | ||
|
||
await DatabaseTestModule.setupDatabase(orm); | ||
}, 30 * 1_000); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}, 30 * 1_000); | ||
|
||
beforeEach(async () => { | ||
await DatabaseTestModule.clearDatabase(orm); | ||
}); | ||
|
||
describe('findBy', () => { | ||
describe('when filtering for persons', () => { | ||
beforeEach(async () => { | ||
const persons: PersonEntity[] = Array.from({ length: 110 }, (_v: unknown, i: number) => | ||
mapper.map(DoFactory.createPerson(false, { firstName: `John #${i}` }), PersonDo, PersonEntity), | ||
); | ||
|
||
await em.persistAndFlush(persons); | ||
}); | ||
|
||
it('should return found persons', async () => { | ||
const scope: PersonScope = new PersonScope() | ||
.findBy({ firstName: new RegExp('John #1') }) | ||
.sortBy('firstName', ScopeOrder.ASC) | ||
.paged(10, 10); | ||
const [persons, total]: Counted<PersonEntity> = await scope.executeQuery(em); | ||
|
||
expect(total).toBe(21); | ||
expect(persons).toHaveLength(10); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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.