Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Martin Adámek <banan23@gmail.com>
- Loading branch information
1 parent
633489b
commit 9d5d457
Showing
2 changed files
with
34 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { MikroORM } from '@mikro-orm/core'; | ||
import { initORMPostgreSql } from '../bootstrap'; | ||
import { Author2, Book2 } from '../entities-sql'; | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => orm = await initORMPostgreSql()); | ||
beforeEach(async () => orm.schema.clearDatabase()); | ||
afterAll(() => orm.close(true)); | ||
|
||
test('test findOne without a offset', async () => { | ||
const author = new Author2('Bartleby', 'bartelby@writer.org'); | ||
const book = new Book2('My Life on The Wall, part 1', author); | ||
new Book2('My Life on The Wall, part 2', author); | ||
|
||
await orm.em.fork().persistAndFlush(author); | ||
|
||
const myBook = await orm.em.findOne(Book2, {}); | ||
|
||
expect(myBook?.title).toEqual(book.title); | ||
}); | ||
|
||
test('test findOne but with a offset', async () => { | ||
const author = new Author2('Bartleby', 'bartelby@writer.org'); | ||
new Book2('My Life on The Wall, part 1', author); | ||
const book2 = new Book2('My Life on The Wall, part 2', author); | ||
|
||
await orm.em.fork().persistAndFlush(author); | ||
|
||
const myBook = await orm.em.findOne(Book2, {}, { offset: 1 }); | ||
|
||
expect(myBook?.title).toEqual(book2.title); | ||
}); |