This repository has been archived by the owner on Jan 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Luciano Nooijen
committed
Dec 6, 2018
1 parent
c2da3c3
commit fed74bd
Showing
7 changed files
with
131 additions
and
34 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
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,9 +1,12 @@ | ||
const Authors = require('./authors'); | ||
const Users = require('./users'); | ||
// const Categories = require('./categories'); | ||
// const Posts = require('./posts'); | ||
const Auth = require('./auth'); | ||
const Articles = require('./articles'); | ||
|
||
module.exports = { | ||
Authors, | ||
Auth, | ||
Users, | ||
Articles, | ||
}; |
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,50 @@ | ||
/* eslint-disable object-curly-newline */ // TODO: Write docs!!!!!! | ||
|
||
const getKnexInstance = require('knex'); | ||
const generateKnexfile = require('../database/generate-knexfile'); | ||
|
||
const { Authors, Auth, Users, Articles } = require('../controllers'); | ||
|
||
const authors = { | ||
list: Authors.listAuthors, | ||
get: Authors.getAuthor, | ||
add: Authors.addAuthor, | ||
modify: Authors.modifyAuthor, | ||
delete: Authors.deleteAuthor, | ||
}; | ||
|
||
const auth = { | ||
authenticate: Auth.authenticateUser, | ||
validate: Auth.validateToken, | ||
}; | ||
|
||
const users = { | ||
list: Users.listUsers, | ||
get: Users.listUsers, | ||
add: Users.addUser, | ||
modify: Users.modifyUser, | ||
delete: Users.deleteUser, | ||
}; | ||
|
||
const articles = { | ||
list: Articles.listArticles, | ||
get: Articles.getArticle, | ||
add: Articles.addArticle, | ||
// Modify is not yet available | ||
delete: Articles.deleteArticle, | ||
}; | ||
|
||
// eslint-disable-next-line max-len, prettier/prettier | ||
const createNodeBlogInstance = (client, host, database, user, password, debug) => { | ||
const knexConfig = { client, host, database, user, password, debug }; | ||
const knexfile = generateKnexfile(knexConfig); | ||
const knex = getKnexInstance(knexfile); | ||
knex.migrate.latest(); | ||
return knex; | ||
}; | ||
|
||
module.exports = createNodeBlogInstance; | ||
module.exports.authors = authors; | ||
module.exports.auth = auth; | ||
module.exports.users = users; | ||
module.exports.articles = articles; |
This file was deleted.
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,3 +1,3 @@ | ||
const getNodeBlogInstance = require('./nodeblog-class'); | ||
const createNodeBlog = require('./create-node-blog'); | ||
|
||
module.exports = getNodeBlogInstance; | ||
module.exports = createNodeBlog; |
Empty file.
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,35 @@ | ||
const nodeBlog = require('../'); | ||
const { authors, auth, users, articles } = require('../'); | ||
const { Authors } = require('../controllers'); | ||
|
||
const client = process.env.DB_CLIENT_TEST; | ||
const host = process.env.DB_HOST_TEST; | ||
const user = process.env.DB_USER_TEST; | ||
const database = process.env.DB_NAME_TEST; | ||
const password = process.env.DB_PASS_TEST; | ||
const debug = process.env.KNEX_DEBUG; | ||
|
||
const nodeBlogArguments = { client, host, user, database, password, debug }; | ||
const blog = nodeBlog(client, host, user, database, password, debug); | ||
|
||
describe('NodeBlog NPM module', () => { | ||
test('NodeBlog to create a knex instance', () => { | ||
expect(typeof blog).toBe('function'); | ||
}); | ||
test('Blog authors should work', async () => { | ||
expect.assertions(3); | ||
expect(typeof await authors.list(blog)).toBe('array'); | ||
expect(await authors.list(blog)).toEqual(Authors.list(blog)); | ||
expect(typeof await authors.get(blog, 1)).toBe('object'); | ||
}); | ||
test('Blog users should work', async () => { | ||
expect.assertions(2); | ||
expect(typeof await users.list(blog)).toBe('array'); | ||
expect(typeof await users.get(blog, 1)).toBe('object'); | ||
}); | ||
test('Blog articles should work', async () => { | ||
expect.assertions(2); | ||
expect(typeof await articles.list(blog)).toBe('array'); | ||
expect(typeof await articles.get(blog, 1)).toBe('object'); | ||
}); | ||
}); |