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

Commit

Permalink
unit(query): generalize names
Browse files Browse the repository at this point in the history
Co-authored-by: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com>
  • Loading branch information
lemredd and KennethTrecy committed Nov 6, 2022
1 parent 6215147 commit fe0aee1
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions database/queries/department/sift_by_slug.spec.ts
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)
})
})

0 comments on commit fe0aee1

Please sign in to comment.