-
-
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.
- Loading branch information
1 parent
8a7eca2
commit 79e3ac8
Showing
8 changed files
with
228 additions
and
11 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,21 @@ | ||
# Changelog | ||
|
||
## Emojis | ||
|
||
- New Features -> :zap: | ||
- Enhancements -> :star2: | ||
- Breaking Changes -> :boom: | ||
- Bugs -> :beetle: | ||
- Pull Requests -> :book: | ||
- Documents -> :mortar_board: | ||
- Tests -> :eyeglasses: | ||
|
||
--- | ||
|
||
## [v1.1.0](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.1.0) - *(2018-11-15)* | ||
|
||
- :zap: Added ability to set `defaults` for decoded params | ||
|
||
## [v1.0.0](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.0.0) - *(2018-11-15)* | ||
|
||
- :tada: First Release |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,6 @@ | ||
{ | ||
"name": "foxify-restify-odin", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Easily restify odin databases", | ||
"author": "Ardalan Amini <[email protected]> [https://github.com/ardalanamini]", | ||
"license": "MIT", | ||
|
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
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,144 @@ | ||
import * as Odin from "@foxify/odin"; | ||
import * as Foxify from "foxify"; | ||
import "prototyped.js"; | ||
import { stringify } from "qs"; | ||
import * as restify from "../src"; | ||
|
||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
__MONGO_DB_NAME__: string; | ||
__MONGO_CONNECTION__: any; | ||
} | ||
} | ||
} | ||
|
||
const TABLE = "users"; | ||
const ITEMS = [ | ||
{ | ||
email: "[email protected]", | ||
username: "ardalanamini", | ||
age: 22, | ||
name: { | ||
first: "Ardalan", | ||
last: "Amini", | ||
}, | ||
}, | ||
{ | ||
email: "[email protected]", | ||
username: "john", | ||
age: 45, | ||
name: { | ||
first: "John", | ||
last: "Due", | ||
}, | ||
}, | ||
]; | ||
|
||
Odin.connections({ | ||
default: { | ||
driver: "MongoDB", | ||
database: global.__MONGO_DB_NAME__, | ||
connection: global.__MONGO_CONNECTION__, | ||
}, | ||
}); | ||
|
||
beforeAll((done) => { | ||
Odin.DB.table(TABLE).insert(ITEMS, (err) => { | ||
if (err) throw err; | ||
|
||
Odin.DB.table(TABLE).get((err, items) => { | ||
if (err) throw err; | ||
|
||
ITEMS.length = 0; | ||
|
||
ITEMS.push(...items); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
afterEach((done) => { | ||
Odin.DB.table(TABLE).delete((err) => { | ||
if (err) throw err; | ||
|
||
Odin.DB.table(TABLE).insert(ITEMS, (err) => { | ||
if (err) throw err; | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
afterAll((done) => { | ||
Odin.DB.table(TABLE).delete((err) => { | ||
if (err) throw err; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
interface User extends Odin { } | ||
|
||
class User extends Odin { | ||
public static schema = { | ||
email: User.Types.String.email.required, | ||
username: User.Types.String.alphanum.min(3).required, | ||
age: User.Types.Number.min(18).required, | ||
name: { | ||
first: User.Types.String.min(3).required, | ||
last: User.Types.String.min(3), | ||
}, | ||
}; | ||
} | ||
|
||
it("Should limit 1 item by default", async () => { | ||
expect.assertions(2); | ||
|
||
const app = new Foxify(); | ||
|
||
app.get("/users", restify(User, { limit: 1 }), async (req, res) => { | ||
expect(req.fro).toBeDefined(); | ||
|
||
res.json({ | ||
users: await req.fro.query.get(), | ||
total: await req.fro.counter.count(), | ||
}); | ||
}); | ||
|
||
const result = await app.inject(`/users`); | ||
|
||
const users = ITEMS.initial(); | ||
|
||
expect(JSON.parse(result.body)) | ||
.toEqual({ users, total: ITEMS.length }); | ||
}); | ||
|
||
it("Should skip 1 item by default and sort by -age", async () => { | ||
expect.assertions(2); | ||
|
||
const app = new Foxify(); | ||
|
||
app.get("/users", restify(User, { skip: 1 }), async (req, res) => { | ||
expect(req.fro).toBeDefined(); | ||
|
||
res.json({ | ||
users: await req.fro.query.get(), | ||
total: await req.fro.counter.count(), | ||
}); | ||
}); | ||
|
||
const result = await app.inject(`/users?${stringify( | ||
{ | ||
sort: [ | ||
"-age", | ||
], | ||
}, | ||
)}`); | ||
|
||
const users = ITEMS.orderBy("age", "desc").tail(); | ||
|
||
expect(JSON.parse(result.body)) | ||
.toEqual({ users, total: ITEMS.length }); | ||
}); |
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
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