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.
Co-authored-by: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com>
- Loading branch information
1 parent
6215147
commit fe0aee1
Showing
1 changed file
with
15 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import Department from "%/models/department" | ||
import DepartmentFactory from "~/factories/department" | ||
import Model from "%/models/department" | ||
import Factory from "~/factories/department" | ||
|
||
import siftBySlug from "./sift_by_slug" | ||
|
||
describe("Database Pipe: Sift by slug", () => { | ||
it("can find all", async() => { | ||
const department = await new DepartmentFactory().insertOne() | ||
const model = await new Factory().insertOne() | ||
const slug = "" | ||
|
||
const options = siftBySlug({}, { "filter": { slug } }) | ||
const foundDepartments = await Department.findAll(options) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).not.toHaveProperty("include") | ||
expect(foundDepartments).toHaveLength(1) | ||
expect(foundDepartments).toHaveProperty("0.id", department.id) | ||
expect(foundModels).toHaveLength(1) | ||
expect(foundModels).toHaveProperty("0.id", model.id) | ||
}) | ||
|
||
it("can find on specific using fullName", async() => { | ||
const department = await new DepartmentFactory() | ||
const model = await new Factory() | ||
.fullName(() => "firstDepartment") | ||
.insertOne() | ||
await new DepartmentFactory() | ||
await new Factory() | ||
.fullName(() => "secondDepartment") | ||
.insertOne() | ||
const slug = "fir" | ||
|
||
const options = siftBySlug({}, { "filter": { slug } }) | ||
const foundDepartments = await Department.findAll(options) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("where") | ||
expect(foundDepartments).toHaveLength(1) | ||
expect(foundDepartments).toHaveProperty("0.id", department.id) | ||
expect(foundModels).toHaveLength(1) | ||
expect(foundModels).toHaveProperty("0.id", model.id) | ||
}) | ||
|
||
it("cannot find on incorrect slug", async() => { | ||
await new DepartmentFactory() | ||
await new Factory() | ||
.fullName(() => "firstDepartment") | ||
.insertOne() | ||
await new DepartmentFactory() | ||
await new Factory() | ||
.fullName(() => "secondDepartment") | ||
.insertOne() | ||
const slug = "xx" | ||
|
||
const options = siftBySlug({}, { "filter": { slug } }) | ||
const foundDepartments = await Department.findAll(options) | ||
const foundModels = await Model.findAll(options) | ||
|
||
expect(options).toHaveProperty("where") | ||
expect(foundDepartments).toHaveLength(0) | ||
expect(foundModels).toHaveLength(0) | ||
}) | ||
}) |