This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
generated from KennethTrecy/web_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit(query): make query to sift by tags
- Loading branch information
1 parent
66eacd0
commit 3bfa9c8
Showing
2 changed files
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Model from "%/models/post" | ||
import Factory from "~/factories/post" | ||
import TagFactory from "~/factories/tag" | ||
import PostTagFactory from "~/factories/post_tag" | ||
|
||
import siftByTags from "./sift_by_tags" | ||
|
||
describe("Database Pipe: Sift by tag", () => { | ||
it("can find on specific tag", async() => { | ||
const tag = await new TagFactory().insertOne() | ||
const model = await new Factory().insertOne() | ||
await new PostTagFactory() | ||
.post(() => Promise.resolve(model)) | ||
.tag(() => Promise.resolve(tag)) | ||
.insertOne() | ||
|
||
const options = siftByTags({}, { | ||
"filter": { | ||
"tagIDs": [ tag.id ] | ||
} | ||
}) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("include") | ||
expect(foundModels).toHaveLength(1) | ||
expect(foundModels).toHaveProperty("0.id", model.id) | ||
}) | ||
|
||
it("cannot find on empty tag", async() => { | ||
const tagA = await new TagFactory().insertOne() | ||
const tagB = await new TagFactory().insertOne() | ||
const model = await new Factory().insertOne() | ||
await new PostTagFactory() | ||
.post(() => Promise.resolve(model)) | ||
.tag(() => Promise.resolve(tagA)) | ||
.insertOne() | ||
|
||
const options = siftByTags({}, { | ||
"filter": { | ||
"tagIDs": [ tagB.id ] | ||
} | ||
}) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("include") | ||
expect(foundModels).toHaveLength(0) | ||
}) | ||
}) |
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