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): prepare the tests for filtering message by kind
- Loading branch information
1 parent
993dcbf
commit 82724e4
Showing
3 changed files
with
53 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Model from "%/models/chat_message" | ||
import Factory from "~/factories/chat_message" | ||
|
||
import siftByKind from "./sift_by_kind" | ||
|
||
describe("Database Pipe: Sift by kind", () => { | ||
it("can find all models", async() => { | ||
const model = await new Factory().insertOne() | ||
|
||
const options = siftByKind({}, { | ||
"filter": { | ||
"chatMessageKind": "*" | ||
} | ||
}) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(foundModels).toHaveLength(1) | ||
expect(foundModels).toHaveProperty("0.id", model.id) | ||
}) | ||
|
||
it("can find on specific model", async() => { | ||
const model = await new Factory().insertOne() | ||
|
||
const options = siftByKind({}, { | ||
"filter": { | ||
"chatMessageKind": model.kind | ||
} | ||
}) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("include.0.where") | ||
expect(foundModels).toHaveLength(1) | ||
expect(foundModels).toHaveProperty("0.id", model.id) | ||
}) | ||
|
||
it("cannot find on specific model", async() => { | ||
const model = await new Factory().insertOne() | ||
|
||
const options = siftByKind({}, { | ||
"filter": { | ||
// Repeat the kind name so there will be no match | ||
"chatMessageKind": model.kind + model.kind | ||
} | ||
}) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("include.0.where") | ||
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