Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
unit(query): prepare the tests for filtering message by kind
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 15, 2022
1 parent 993dcbf commit 82724e4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions database/queries/chat_message/sift_by_consultation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Database Pipe: Sift by consultation", () => {
const activity = await new ChatMessageActivityFactory()
.consultation(() => Promise.resolve(consultation))
.insertOne()
await new Factory()
const model = await new Factory()
.chatMessageActivity(() => Promise.resolve(activity))
.insertOne()

Expand All @@ -24,7 +24,7 @@ describe("Database Pipe: Sift by consultation", () => {

expect(options).toHaveProperty("include.0.where")
expect(foundModels).toHaveLength(1)
expect(foundModels).toHaveProperty("0.id", activity.id)
expect(foundModels).toHaveProperty("0.id", model.id)
})

it("cannot find on specific model", async() => {
Expand Down
50 changes: 50 additions & 0 deletions database/queries/chat_message/sift_by_kind.spec.ts
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)
})
})
2 changes: 1 addition & 1 deletion database/queries/consultation/sift_by_range.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Factory from "~/factories/consultation"
import siftByRange from "./sift_by_range"

describe("Database Pipe: Sift by range", () => {
it("can find on all consultation", async() => {
it("can find on all models", async() => {
const model = await new Factory().insertOne()

const options = siftByRange({}, {
Expand Down

0 comments on commit 82724e4

Please sign in to comment.