Skip to content

Commit 826035e

Browse files
committed
add seed for test db
1 parent 7e71f82 commit 826035e

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

.env.example

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ PORT=3000
1010
CORS_URL=*
1111

1212
# Databse
13-
DB_NAME=afteracademy-blog-db # YOUR_MONGO_DB_NAME
13+
# YOUR_MONGO_DB_NAME
14+
DB_NAME=afteracademy-blog-db
15+
1416
#localhost or IP of the server
1517
# If using the docker installation then use 'mongo' for host name else localhost or ip or db server
16-
DB_HOST=mongo # YOUR_MONGO_DB_HOST_NAME
18+
#YOUR_MONGO_DB_HOST_NAME
19+
DB_HOST=mongo
20+
1721
DB_PORT=27017
18-
DB_USER=afteracademy-blog-db-user # YOUR_MONGO_DB_USER_NAME
19-
DB_USER_PWD=changeit # YOUR_MONGO_DB_USER_PWD
2022

21-
# Admin when using Docker
23+
#YOUR_MONGO_DB_USER_NAME
24+
DB_USER=afteracademy-blog-db-user
25+
26+
#YOUR_MONGO_DB_USER_PWD
27+
DB_USER_PWD=changeit
28+
29+
# Admin of mongo db when using Docker
2230
DB_ADMIN=admin
2331
DB_ADMIN_PWD=changeit
2432

addons/init-mongo.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
db = db.getSiblingDB('afteracademy-blog-db')
1+
function seed(dbName, user, password){
2+
db = db.getSiblingDB(dbName)
3+
db.createUser({
4+
user: user,
5+
pwd: password,
6+
roles: [{ role: 'readWrite', db: dbName }]
7+
})
28

3-
db.createUser({
4-
user: 'afteracademy-blog-db-user',
5-
pwd: 'changeit',
6-
roles: [{ role: 'readWrite', db: 'afteracademy-blog-db' }]
7-
})
9+
db.createCollection("api_keys")
10+
db.createCollection("roles")
811

9-
db.createCollection("api_keys")
10-
db.createCollection("roles")
12+
db.api_keys.insert({
13+
metadata: "To be used by the xyz vendor",
14+
key: "GCMUDiuY5a7WvyUNt9n3QztToSHzK7Uj",
15+
version: 1,
16+
status: true,
17+
createdAt: new Date(),
18+
updatedAt: new Date()
19+
})
1120

12-
db.api_keys.insert({
13-
metadata: "To be used by the xyz vendor",
14-
key: "GCMUDiuY5a7WvyUNt9n3QztToSHzK7Uj",
15-
version: 1,
16-
status: true,
17-
createdAt: new Date(),
18-
updatedAt: new Date()
19-
})
21+
db.roles.insertMany([
22+
{ code: "LEARNER", status: true, createdAt: new Date(), updatedAt: new Date() },
23+
{ code: "WRITER", status: true, createdAt: new Date(), updatedAt: new Date() },
24+
{ code: "EDITOR", status: true, createdAt: new Date(), updatedAt: new Date() },
25+
{ code: "ADMIN", status: true, createdAt: new Date(), updatedAt: new Date() },
26+
])
27+
}
2028

21-
db.roles.insertMany([
22-
{ code: "LEARNER", status: true, createdAt: new Date(), updatedAt: new Date()},
23-
{ code: "WRITER", status: true, createdAt: new Date(), updatedAt: new Date()},
24-
{ code: "EDITOR", status: true, createdAt: new Date(), updatedAt: new Date()},
25-
{ code: "ADMIN", status: true, createdAt: new Date(), updatedAt: new Date()},
26-
])
29+
seed('afteracademy-blog-db', 'afteracademy-blog-db-user', 'changeit')
30+
seed('afteracademy-blog-test-db', 'afteracademy-blog-test-db-user', 'changeit')

tests/.env.test.example

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ NODE_ENV=test
88
CORS_URL=*
99

1010
# Databse
11-
DB_NAME=YOUR_TEST_MONGO_DB_NAME
11+
#YOUR_TEST_MONGO_DB_NAME
12+
DB_NAME=afteracademy-blog-test-db
13+
1214
#localhost or IP of the server
13-
DB_HOST=YOUR_TEST_MONGO_DB_HOST_NAME
15+
#YOUR_TEST_MONGO_DB_HOST_NAME
16+
DB_HOST=localhost
17+
1418
DB_PORT=27017
15-
DB_USER=YOUR_TEST_MONGO_DB_USER_NAME
16-
DB_PWD=YOUR_TEST_MONGO_DB_USER_PWD
19+
20+
#YOUR_TEST_MONGO_DB_USER_NAME
21+
DB_USER=afteracademy-blog-test-db-user
22+
23+
#YOUR_TEST_MONGO_DB_USER_PWD
24+
DB_PWD=changeit
1725

1826
#Log
1927
#Example '/Users/janisharali/logs'
2028
#DEFAUlT is this project's directory
21-
LOG_DIR=YOUR_TEST_DIRECTORY_PATH_FOR_LOG_FILES
29+
#LOG_DIR=YOUR_TEST_DIRECTORY_PATH_FOR_LOG_FILES
2230

23-
# Token Info
31+
#Token Info
2432
ACCESS_TOKEN_VALIDITY_DAYS=30
2533
REFRESH_TOKEN_VALIDITY_DAYS=120
2634
TOKEN_ISSUER=test.afteracademy.com

0 commit comments

Comments
 (0)