Skip to content

Commit

Permalink
test: add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
casheeeewnuts authored and casheeeewnutsShu Nonaka committed Jan 15, 2024
1 parent 255df35 commit 124d86c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/integration/sample2-one-to-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,47 @@ describe("one-to-one", function () {
.getOne()
.should.eventually.eql(expectedDetails)
})

it("should load post and its details with no hangup if query used", async function () {
if (!dataSource) return
const expectedPost = new Post()
expectedPost.id = savedPost.id
expectedPost.text = savedPost.text
expectedPost.title = savedPost.title
expectedPost.details = new PostDetails()
expectedPost.details!.id = savedPost.details!.id
expectedPost.details!.authorName = savedPost.details!.authorName
expectedPost.details!.comment = savedPost.details!.comment
expectedPost.details!.metadata = savedPost.details!.metadata

const findOne = () => postRepository.findOne({
where: {
id: savedPost.id
},
relations: {
details: true
},
relationLoadStrategy: "query"
})

const posts = await Promise.all([
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
])

posts.forEach(post => {
expect(post).not.to.be.null
post!.should.eql(expectedPost)
})
})
})

describe("insert post and category (one-side relation)", function () {
Expand Down
41 changes: 41 additions & 0 deletions test/integration/sample3-many-to-one.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,47 @@ describe("many-to-one", function () {
.getOne()
.should.eventually.eql(expectedDetails)
})

it("should load post and its details with no hangup if query used", async function () {
if (!dataSource) return
const expectedPost = new Post()
expectedPost.id = savedPost.id
expectedPost.text = savedPost.text
expectedPost.title = savedPost.title
expectedPost.details = new PostDetails()
expectedPost.details!.id = savedPost.details!.id
expectedPost.details!.authorName = savedPost.details!.authorName
expectedPost.details!.comment = savedPost.details!.comment
expectedPost.details!.metadata = savedPost.details!.metadata

const findOne = () => postRepository.findOne({
where: {
id: savedPost.id
},
relations: {
details: true
},
relationLoadStrategy: "query"
})

const posts = await Promise.all([
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
findOne(),
])

posts.forEach(post => {
expect(post).not.to.be.null
post!.should.eql(expectedPost)
})
})
})

describe("insert post and category (one-side relation)", function () {
Expand Down

0 comments on commit 124d86c

Please sign in to comment.