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(database): ensure sift by slug for tag works
- Loading branch information
Angelo Magtoto
committed
Nov 14, 2022
1 parent
5ca5b76
commit b15c2b0
Showing
1 changed file
with
51 additions
and
0 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 |
---|---|---|
@@ -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) | ||
}) | ||
}) |