This repository was 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
Expand file tree
/
Copy pathindex.test.ts
More file actions
65 lines (60 loc) · 2.29 KB
/
index.test.ts
File metadata and controls
65 lines (60 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { useTestDatabase } from './config/index';
import blog from './config/blog';
const nodeBlog = require('../');
const { authors, auth, users, categories, articles } = require('../');
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 === 'true';
const generatedBlog = nodeBlog(client, host, user, database, password, debug);
useTestDatabase();
describe('NodeBlog NPM module', () => {
test('NodeBlog to create a knex instance', () => {
expect(typeof generatedBlog).toBe('function');
});
test('Blog authors should work', async () => {
expect.assertions(2);
const list = await authors.list(blog);
const getItem = await authors.get(blog, 1);
expect(typeof list).toBe('object');
expect(typeof getItem).toBe('object');
});
test('Blog users should work', async () => {
expect.assertions(2);
const list = await users.list(blog);
const getItem = await users.get(blog, 1);
expect(typeof list).toBe('object');
expect(typeof getItem).toBe('object');
});
test('Blog categories should work', async () => {
expect.assertions(2);
const list = await categories.list(blog);
const getItem = await categories.get(blog, 1);
expect(typeof list).toBe('object');
expect(typeof getItem).toBe('object');
});
test('Blog articles should work', async () => {
expect.assertions(2);
const list = await articles.list(blog);
const getItem = await articles.get(blog, 1);
expect(typeof list).toBe('object');
expect(typeof getItem).toBe('object');
});
test('Add user should be working', async () => {
expect.assertions(1);
const newUser = {
username: 'anewuser',
email: 'anewuser@domain.com',
first_name: 'Jane',
last_name: 'Doe',
password: 'theplainpasswordgoeshere',
author_id: 2,
};
await users.add(blog, newUser);
const isAuth =
await auth.authenticate(blog, newUser.username, newUser.password);
expect(isAuth).toBe(true);
});
});