create-sipere 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/js-rest-api/app/controllers/authController.js +2 -2
- package/templates/js-rest-api/app/database/database.js +1 -5
- package/templates/js-rest-api/package.json +2 -8
- package/templates/js-rest-api/test/mocha.setup.js +8 -0
- package/templates/js-rest-api/test/user.spec.js +13 -12
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import bcrypt from 'bcryptjs'
|
|
2
2
|
import jwt from 'jsonwebtoken'
|
|
3
3
|
import User from '../models/user.js'
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import dotenvFlow from 'dotenv-flow'
|
|
5
|
+
dotenvFlow.config()
|
|
6
6
|
|
|
7
7
|
const AuthController = {
|
|
8
8
|
async register(req, res) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import Sequelize from 'sequelize'
|
|
2
2
|
import dotenvFlow from 'dotenv-flow'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
dotenvFlow.config({ path: '.env.test' })
|
|
6
|
-
}else {
|
|
7
|
-
dotenvFlow.config()
|
|
8
|
-
}
|
|
4
|
+
dotenvFlow.config()
|
|
9
5
|
|
|
10
6
|
const sequelize = new Sequelize(
|
|
11
7
|
process.env.DB_NAME,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "Express API with simple Sequelize",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "NODE_ENV=test mocha",
|
|
7
|
+
"test": "NODE_ENV=test mocha --file test/mocha.setup.js 'test/**/*.spec.js'",
|
|
8
8
|
"dev": "nodemon app",
|
|
9
9
|
"start": "node app"
|
|
10
10
|
},
|
|
@@ -15,22 +15,16 @@
|
|
|
15
15
|
"author": "your name",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@sipere/op-cli": "^0.9.2",
|
|
18
|
+
"@sipere/op-cli": "^0.9.3",
|
|
20
19
|
"bcryptjs": "^2.4.3",
|
|
21
20
|
"cors": "^2.8.5",
|
|
22
21
|
"dotenv-flow": "^4.1.0",
|
|
23
22
|
"express": "^4.18.2",
|
|
24
|
-
"generate-api-key": "^1.0.2",
|
|
25
23
|
"jsonwebtoken": "^9.0.0",
|
|
26
24
|
"mariadb": "^3.1.2",
|
|
27
25
|
"morgan": "^1.10.0",
|
|
28
|
-
"read": "^4.1.0",
|
|
29
|
-
"replace": "^1.2.2",
|
|
30
26
|
"sequelize": "^6.32.0",
|
|
31
27
|
"sqlite3": "^5.1.6",
|
|
32
|
-
"umzug": "^3.8.2",
|
|
33
|
-
"yargs": "^18.0.0"
|
|
34
28
|
},
|
|
35
29
|
"devDependencies": {
|
|
36
30
|
"@types/bcryptjs": "^2.4.6",
|
|
@@ -5,8 +5,8 @@ describe('/api/register and /api/login', () => {
|
|
|
5
5
|
const restype= 'application/json; charset=utf-8'
|
|
6
6
|
var token = null
|
|
7
7
|
|
|
8
|
-
it('post /register ',
|
|
9
|
-
supertest(app)
|
|
8
|
+
it('post /register ', async () => {
|
|
9
|
+
await supertest(app)
|
|
10
10
|
.post('/api/register')
|
|
11
11
|
.set('Accept', 'application/json')
|
|
12
12
|
.send({
|
|
@@ -16,11 +16,11 @@ describe('/api/register and /api/login', () => {
|
|
|
16
16
|
password_confirmation: 'titok'
|
|
17
17
|
})
|
|
18
18
|
.expect('Content-Type', restype)
|
|
19
|
-
.expect(201
|
|
19
|
+
.expect(201)
|
|
20
20
|
|
|
21
21
|
})
|
|
22
|
-
it('post /login ', (
|
|
23
|
-
supertest(app)
|
|
22
|
+
it('post /login ', async () => {
|
|
23
|
+
const res = await supertest(app)
|
|
24
24
|
.post('/api/login')
|
|
25
25
|
.set('Accept', 'application/json')
|
|
26
26
|
.send({
|
|
@@ -28,16 +28,17 @@ describe('/api/register and /api/login', () => {
|
|
|
28
28
|
password: 'titok'
|
|
29
29
|
})
|
|
30
30
|
.expect('Content-Type', restype)
|
|
31
|
-
.expect(200
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
.expect(200)
|
|
32
|
+
token = res.body.accessToken
|
|
33
|
+
if(!token) {
|
|
34
|
+
throw new Error('No token')
|
|
35
|
+
}
|
|
35
36
|
})
|
|
36
|
-
it('get /users ',
|
|
37
|
-
supertest(app)
|
|
37
|
+
it('get /users ', async () => {
|
|
38
|
+
await supertest(app)
|
|
38
39
|
.get('/api/users')
|
|
39
40
|
.set('Accept', 'application/json')
|
|
40
41
|
.set('Authorization', 'Bearer ' + token)
|
|
41
|
-
.expect(200
|
|
42
|
+
.expect(200)
|
|
42
43
|
})
|
|
43
44
|
})
|