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

Commit

Permalink
unit(database): ensure sift by slug for tag works
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Magtoto committed Nov 14, 2022
1 parent 5ca5b76 commit b15c2b0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions database/queries/tag/sift_by_slug.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Tag from "%/models/tag"
import TagFactory from "~/factories/tag"

import siftBySlug from "./sift_by_slug"

describe("Database Pipe: Sift by slug", () => {
it("can find all", async() => {
const tag = await new TagFactory().insertOne()
const slug = ""

const options = siftBySlug({}, { "filter": { slug } })
const foundTags = await Tag.findAll(options)

expect(options).not.toHaveProperty("include")
expect(foundTags).toHaveLength(1)
expect(foundTags).toHaveProperty("0.id", tag.id)
})

it("can find on specific using name", async() => {
const tag = await new TagFactory()
.name(() => "firsttag")
.insertOne()
await new TagFactory()
.name(() => "secondtag")
.insertOne()
const slug = "fir"

const options = siftBySlug({}, { "filter": { slug } })
const foundTags = await Tag.findAll(options)

expect(options).toHaveProperty("where")
expect(foundTags).toHaveLength(1)
expect(foundTags).toHaveProperty("0.id", tag.id)
})

it("cannot find on incorrect slug", async() => {
await new TagFactory()
.name(() => "firsttag")
.insertOne()
await new TagFactory()
.name(() => "secondtag")
.insertOne()
const slug = "xx"

const options = siftBySlug({}, { "filter": { slug } })
const foundTags = await Tag.findAll(options)

expect(options).toHaveProperty("where")
expect(foundTags).toHaveLength(0)
})
})

0 comments on commit b15c2b0

Please sign in to comment.